1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file contains the low level primitives for operating on tree nodes,
21 including allocation, list operations, interning of identifiers,
22 construction of data type nodes and statement nodes,
23 and construction of type conversion nodes. It also contains
24 tables index by tree code that describe how to take apart
27 It is intended to be language-independent but can occasionally
28 calls language-dependent routines. */
32 #include "coretypes.h"
40 #include "fold-const.h"
41 #include "stor-layout.h"
46 #include "toplev.h" /* get_random_seed */
47 #include "filenames.h"
50 #include "common/common-target.h"
51 #include "langhooks.h"
52 #include "tree-inline.h"
53 #include "tree-iterator.h"
54 #include "internal-fn.h"
55 #include "gimple-iterator.h"
58 #include "insn-config.h"
67 #include "tree-pass.h"
68 #include "langhooks-def.h"
69 #include "diagnostic.h"
70 #include "tree-diagnostic.h"
71 #include "tree-pretty-print.h"
76 #include "print-tree.h"
77 #include "ipa-utils.h"
79 /* Tree code classes. */
81 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
82 #define END_OF_BASE_TREE_CODES tcc_exceptional,
84 const enum tree_code_class tree_code_type
[] = {
85 #include "all-tree.def"
89 #undef END_OF_BASE_TREE_CODES
91 /* Table indexed by tree code giving number of expression
92 operands beyond the fixed part of the node structure.
93 Not used for types or decls. */
95 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
96 #define END_OF_BASE_TREE_CODES 0,
98 const unsigned char tree_code_length
[] = {
99 #include "all-tree.def"
103 #undef END_OF_BASE_TREE_CODES
105 /* Names of tree components.
106 Used for printing out the tree and error messages. */
107 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
108 #define END_OF_BASE_TREE_CODES "@dummy",
110 static const char *const tree_code_name
[] = {
111 #include "all-tree.def"
115 #undef END_OF_BASE_TREE_CODES
117 /* Each tree code class has an associated string representation.
118 These must correspond to the tree_code_class entries. */
120 const char *const tree_code_class_strings
[] =
135 /* obstack.[ch] explicitly declined to prototype this. */
136 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
138 /* Statistics-gathering stuff. */
140 static int tree_code_counts
[MAX_TREE_CODES
];
141 int tree_node_counts
[(int) all_kinds
];
142 int tree_node_sizes
[(int) all_kinds
];
144 /* Keep in sync with tree.h:enum tree_node_kind. */
145 static const char * const tree_node_kind_names
[] = {
164 /* Unique id for next decl created. */
165 static GTY(()) int next_decl_uid
;
166 /* Unique id for next type created. */
167 static GTY(()) int next_type_uid
= 1;
168 /* Unique id for next debug decl created. Use negative numbers,
169 to catch erroneous uses. */
170 static GTY(()) int next_debug_decl_uid
;
172 /* Since we cannot rehash a type after it is in the table, we have to
173 keep the hash code. */
175 struct GTY((for_user
)) type_hash
{
180 /* Initial size of the hash table (rounded to next prime). */
181 #define TYPE_HASH_INITIAL_SIZE 1000
183 struct type_cache_hasher
: ggc_cache_ptr_hash
<type_hash
>
185 static hashval_t
hash (type_hash
*t
) { return t
->hash
; }
186 static bool equal (type_hash
*a
, type_hash
*b
);
189 keep_cache_entry (type_hash
*&t
)
191 return ggc_marked_p (t
->type
);
195 /* Now here is the hash table. When recording a type, it is added to
196 the slot whose index is the hash code. Note that the hash table is
197 used for several kinds of types (function types, array types and
198 array index range types, for now). While all these live in the
199 same table, they are completely independent, and the hash code is
200 computed differently for each of these. */
202 static GTY ((cache
)) hash_table
<type_cache_hasher
> *type_hash_table
;
204 /* Hash table and temporary node for larger integer const values. */
205 static GTY (()) tree int_cst_node
;
207 struct int_cst_hasher
: ggc_cache_ptr_hash
<tree_node
>
209 static hashval_t
hash (tree t
);
210 static bool equal (tree x
, tree y
);
213 static GTY ((cache
)) hash_table
<int_cst_hasher
> *int_cst_hash_table
;
215 /* Hash table for optimization flags and target option flags. Use the same
216 hash table for both sets of options. Nodes for building the current
217 optimization and target option nodes. The assumption is most of the time
218 the options created will already be in the hash table, so we avoid
219 allocating and freeing up a node repeatably. */
220 static GTY (()) tree cl_optimization_node
;
221 static GTY (()) tree cl_target_option_node
;
223 struct cl_option_hasher
: ggc_cache_ptr_hash
<tree_node
>
225 static hashval_t
hash (tree t
);
226 static bool equal (tree x
, tree y
);
229 static GTY ((cache
)) hash_table
<cl_option_hasher
> *cl_option_hash_table
;
231 /* General tree->tree mapping structure for use in hash tables. */
235 hash_table
<tree_decl_map_cache_hasher
> *debug_expr_for_decl
;
238 hash_table
<tree_decl_map_cache_hasher
> *value_expr_for_decl
;
240 struct tree_vec_map_cache_hasher
: ggc_cache_ptr_hash
<tree_vec_map
>
242 static hashval_t
hash (tree_vec_map
*m
) { return DECL_UID (m
->base
.from
); }
245 equal (tree_vec_map
*a
, tree_vec_map
*b
)
247 return a
->base
.from
== b
->base
.from
;
251 keep_cache_entry (tree_vec_map
*&m
)
253 return ggc_marked_p (m
->base
.from
);
258 hash_table
<tree_vec_map_cache_hasher
> *debug_args_for_decl
;
260 static void set_type_quals (tree
, int);
261 static void print_type_hash_statistics (void);
262 static void print_debug_expr_statistics (void);
263 static void print_value_expr_statistics (void);
264 static void type_hash_list (const_tree
, inchash::hash
&);
265 static void attribute_hash_list (const_tree
, inchash::hash
&);
267 tree global_trees
[TI_MAX
];
268 tree integer_types
[itk_none
];
270 bool int_n_enabled_p
[NUM_INT_N_ENTS
];
271 struct int_n_trees_t int_n_trees
[NUM_INT_N_ENTS
];
273 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
275 /* Number of operands for each OpenMP clause. */
276 unsigned const char omp_clause_num_ops
[] =
278 0, /* OMP_CLAUSE_ERROR */
279 1, /* OMP_CLAUSE_PRIVATE */
280 1, /* OMP_CLAUSE_SHARED */
281 1, /* OMP_CLAUSE_FIRSTPRIVATE */
282 2, /* OMP_CLAUSE_LASTPRIVATE */
283 4, /* OMP_CLAUSE_REDUCTION */
284 1, /* OMP_CLAUSE_COPYIN */
285 1, /* OMP_CLAUSE_COPYPRIVATE */
286 3, /* OMP_CLAUSE_LINEAR */
287 2, /* OMP_CLAUSE_ALIGNED */
288 1, /* OMP_CLAUSE_DEPEND */
289 1, /* OMP_CLAUSE_UNIFORM */
290 2, /* OMP_CLAUSE_FROM */
291 2, /* OMP_CLAUSE_TO */
292 2, /* OMP_CLAUSE_MAP */
293 2, /* OMP_CLAUSE__CACHE_ */
294 1, /* OMP_CLAUSE_DEVICE_RESIDENT */
295 1, /* OMP_CLAUSE_USE_DEVICE */
296 2, /* OMP_CLAUSE_GANG */
297 1, /* OMP_CLAUSE_ASYNC */
298 1, /* OMP_CLAUSE_WAIT */
299 0, /* OMP_CLAUSE_AUTO */
300 0, /* OMP_CLAUSE_SEQ */
301 1, /* OMP_CLAUSE__LOOPTEMP_ */
302 1, /* OMP_CLAUSE_IF */
303 1, /* OMP_CLAUSE_NUM_THREADS */
304 1, /* OMP_CLAUSE_SCHEDULE */
305 0, /* OMP_CLAUSE_NOWAIT */
306 0, /* OMP_CLAUSE_ORDERED */
307 0, /* OMP_CLAUSE_DEFAULT */
308 3, /* OMP_CLAUSE_COLLAPSE */
309 0, /* OMP_CLAUSE_UNTIED */
310 1, /* OMP_CLAUSE_FINAL */
311 0, /* OMP_CLAUSE_MERGEABLE */
312 1, /* OMP_CLAUSE_DEVICE */
313 1, /* OMP_CLAUSE_DIST_SCHEDULE */
314 0, /* OMP_CLAUSE_INBRANCH */
315 0, /* OMP_CLAUSE_NOTINBRANCH */
316 1, /* OMP_CLAUSE_NUM_TEAMS */
317 1, /* OMP_CLAUSE_THREAD_LIMIT */
318 0, /* OMP_CLAUSE_PROC_BIND */
319 1, /* OMP_CLAUSE_SAFELEN */
320 1, /* OMP_CLAUSE_SIMDLEN */
321 0, /* OMP_CLAUSE_FOR */
322 0, /* OMP_CLAUSE_PARALLEL */
323 0, /* OMP_CLAUSE_SECTIONS */
324 0, /* OMP_CLAUSE_TASKGROUP */
325 1, /* OMP_CLAUSE__SIMDUID_ */
326 1, /* OMP_CLAUSE__CILK_FOR_COUNT_ */
327 0, /* OMP_CLAUSE_INDEPENDENT */
328 1, /* OMP_CLAUSE_WORKER */
329 1, /* OMP_CLAUSE_VECTOR */
330 1, /* OMP_CLAUSE_NUM_GANGS */
331 1, /* OMP_CLAUSE_NUM_WORKERS */
332 1, /* OMP_CLAUSE_VECTOR_LENGTH */
335 const char * const omp_clause_code_name
[] =
395 /* Return the tree node structure used by tree code CODE. */
397 static inline enum tree_node_structure_enum
398 tree_node_structure_for_code (enum tree_code code
)
400 switch (TREE_CODE_CLASS (code
))
402 case tcc_declaration
:
407 return TS_FIELD_DECL
;
413 return TS_LABEL_DECL
;
415 return TS_RESULT_DECL
;
416 case DEBUG_EXPR_DECL
:
419 return TS_CONST_DECL
;
423 return TS_FUNCTION_DECL
;
424 case TRANSLATION_UNIT_DECL
:
425 return TS_TRANSLATION_UNIT_DECL
;
427 return TS_DECL_NON_COMMON
;
431 return TS_TYPE_NON_COMMON
;
440 default: /* tcc_constant and tcc_exceptional */
445 /* tcc_constant cases. */
446 case VOID_CST
: return TS_TYPED
;
447 case INTEGER_CST
: return TS_INT_CST
;
448 case REAL_CST
: return TS_REAL_CST
;
449 case FIXED_CST
: return TS_FIXED_CST
;
450 case COMPLEX_CST
: return TS_COMPLEX
;
451 case VECTOR_CST
: return TS_VECTOR
;
452 case STRING_CST
: return TS_STRING
;
453 /* tcc_exceptional cases. */
454 case ERROR_MARK
: return TS_COMMON
;
455 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
456 case TREE_LIST
: return TS_LIST
;
457 case TREE_VEC
: return TS_VEC
;
458 case SSA_NAME
: return TS_SSA_NAME
;
459 case PLACEHOLDER_EXPR
: return TS_COMMON
;
460 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
461 case BLOCK
: return TS_BLOCK
;
462 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
463 case TREE_BINFO
: return TS_BINFO
;
464 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
465 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
466 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
474 /* Initialize tree_contains_struct to describe the hierarchy of tree
478 initialize_tree_contains_struct (void)
482 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
485 enum tree_node_structure_enum ts_code
;
487 code
= (enum tree_code
) i
;
488 ts_code
= tree_node_structure_for_code (code
);
490 /* Mark the TS structure itself. */
491 tree_contains_struct
[code
][ts_code
] = 1;
493 /* Mark all the structures that TS is derived from. */
511 case TS_STATEMENT_LIST
:
512 MARK_TS_TYPED (code
);
516 case TS_DECL_MINIMAL
:
522 case TS_OPTIMIZATION
:
523 case TS_TARGET_OPTION
:
524 MARK_TS_COMMON (code
);
527 case TS_TYPE_WITH_LANG_SPECIFIC
:
528 MARK_TS_TYPE_COMMON (code
);
531 case TS_TYPE_NON_COMMON
:
532 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
536 MARK_TS_DECL_MINIMAL (code
);
541 MARK_TS_DECL_COMMON (code
);
544 case TS_DECL_NON_COMMON
:
545 MARK_TS_DECL_WITH_VIS (code
);
548 case TS_DECL_WITH_VIS
:
552 MARK_TS_DECL_WRTL (code
);
556 MARK_TS_DECL_COMMON (code
);
560 MARK_TS_DECL_WITH_VIS (code
);
564 case TS_FUNCTION_DECL
:
565 MARK_TS_DECL_NON_COMMON (code
);
568 case TS_TRANSLATION_UNIT_DECL
:
569 MARK_TS_DECL_COMMON (code
);
577 /* Basic consistency checks for attributes used in fold. */
578 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
579 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
580 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
581 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
582 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
583 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
584 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
585 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
586 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
587 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
588 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
589 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
590 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
591 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
592 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
593 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
594 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
595 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
596 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
597 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
598 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
599 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
600 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
601 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
602 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
603 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
604 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
605 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
606 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
607 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
608 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
609 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
610 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
611 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
612 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
613 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
614 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
615 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
616 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_MINIMAL
]);
617 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_COMMON
]);
626 /* Initialize the hash table of types. */
628 = hash_table
<type_cache_hasher
>::create_ggc (TYPE_HASH_INITIAL_SIZE
);
631 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
634 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
636 int_cst_hash_table
= hash_table
<int_cst_hasher
>::create_ggc (1024);
638 int_cst_node
= make_int_cst (1, 1);
640 cl_option_hash_table
= hash_table
<cl_option_hasher
>::create_ggc (64);
642 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
643 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
645 /* Initialize the tree_contains_struct array. */
646 initialize_tree_contains_struct ();
647 lang_hooks
.init_ts ();
651 /* The name of the object as the assembler will see it (but before any
652 translations made by ASM_OUTPUT_LABELREF). Often this is the same
653 as DECL_NAME. It is an IDENTIFIER_NODE. */
655 decl_assembler_name (tree decl
)
657 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
658 lang_hooks
.set_decl_assembler_name (decl
);
659 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
662 /* When the target supports COMDAT groups, this indicates which group the
663 DECL is associated with. This can be either an IDENTIFIER_NODE or a
664 decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
666 decl_comdat_group (const_tree node
)
668 struct symtab_node
*snode
= symtab_node::get (node
);
671 return snode
->get_comdat_group ();
674 /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
676 decl_comdat_group_id (const_tree node
)
678 struct symtab_node
*snode
= symtab_node::get (node
);
681 return snode
->get_comdat_group_id ();
684 /* When the target supports named section, return its name as IDENTIFIER_NODE
685 or NULL if it is in no section. */
687 decl_section_name (const_tree node
)
689 struct symtab_node
*snode
= symtab_node::get (node
);
692 return snode
->get_section ();
695 /* Set section name of NODE to VALUE (that is expected to be
698 set_decl_section_name (tree node
, const char *value
)
700 struct symtab_node
*snode
;
704 snode
= symtab_node::get (node
);
708 else if (TREE_CODE (node
) == VAR_DECL
)
709 snode
= varpool_node::get_create (node
);
711 snode
= cgraph_node::get_create (node
);
712 snode
->set_section (value
);
715 /* Return TLS model of a variable NODE. */
717 decl_tls_model (const_tree node
)
719 struct varpool_node
*snode
= varpool_node::get (node
);
721 return TLS_MODEL_NONE
;
722 return snode
->tls_model
;
725 /* Set TLS model of variable NODE to MODEL. */
727 set_decl_tls_model (tree node
, enum tls_model model
)
729 struct varpool_node
*vnode
;
731 if (model
== TLS_MODEL_NONE
)
733 vnode
= varpool_node::get (node
);
738 vnode
= varpool_node::get_create (node
);
739 vnode
->tls_model
= model
;
742 /* Compute the number of bytes occupied by a tree with code CODE.
743 This function cannot be used for nodes that have variable sizes,
744 including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
746 tree_code_size (enum tree_code code
)
748 switch (TREE_CODE_CLASS (code
))
750 case tcc_declaration
: /* A decl node */
755 return sizeof (struct tree_field_decl
);
757 return sizeof (struct tree_parm_decl
);
759 return sizeof (struct tree_var_decl
);
761 return sizeof (struct tree_label_decl
);
763 return sizeof (struct tree_result_decl
);
765 return sizeof (struct tree_const_decl
);
767 return sizeof (struct tree_type_decl
);
769 return sizeof (struct tree_function_decl
);
770 case DEBUG_EXPR_DECL
:
771 return sizeof (struct tree_decl_with_rtl
);
772 case TRANSLATION_UNIT_DECL
:
773 return sizeof (struct tree_translation_unit_decl
);
777 return sizeof (struct tree_decl_non_common
);
779 return lang_hooks
.tree_size (code
);
783 case tcc_type
: /* a type node */
784 return sizeof (struct tree_type_non_common
);
786 case tcc_reference
: /* a reference */
787 case tcc_expression
: /* an expression */
788 case tcc_statement
: /* an expression with side effects */
789 case tcc_comparison
: /* a comparison expression */
790 case tcc_unary
: /* a unary arithmetic expression */
791 case tcc_binary
: /* a binary arithmetic expression */
792 return (sizeof (struct tree_exp
)
793 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
795 case tcc_constant
: /* a constant */
798 case VOID_CST
: return sizeof (struct tree_typed
);
799 case INTEGER_CST
: gcc_unreachable ();
800 case REAL_CST
: return sizeof (struct tree_real_cst
);
801 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
802 case COMPLEX_CST
: return sizeof (struct tree_complex
);
803 case VECTOR_CST
: return sizeof (struct tree_vector
);
804 case STRING_CST
: gcc_unreachable ();
806 return lang_hooks
.tree_size (code
);
809 case tcc_exceptional
: /* something random, like an identifier. */
812 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
813 case TREE_LIST
: return sizeof (struct tree_list
);
816 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
819 case OMP_CLAUSE
: gcc_unreachable ();
821 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
823 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
824 case BLOCK
: return sizeof (struct tree_block
);
825 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
826 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
827 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
830 return lang_hooks
.tree_size (code
);
838 /* Compute the number of bytes occupied by NODE. This routine only
839 looks at TREE_CODE, except for those nodes that have variable sizes. */
841 tree_size (const_tree node
)
843 const enum tree_code code
= TREE_CODE (node
);
847 return (sizeof (struct tree_int_cst
)
848 + (TREE_INT_CST_EXT_NUNITS (node
) - 1) * sizeof (HOST_WIDE_INT
));
851 return (offsetof (struct tree_binfo
, base_binfos
)
853 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
856 return (sizeof (struct tree_vec
)
857 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
860 return (sizeof (struct tree_vector
)
861 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node
)) - 1) * sizeof (tree
));
864 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
867 return (sizeof (struct tree_omp_clause
)
868 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
872 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
873 return (sizeof (struct tree_exp
)
874 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
876 return tree_code_size (code
);
880 /* Record interesting allocation statistics for a tree node with CODE
884 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
885 size_t length ATTRIBUTE_UNUSED
)
887 enum tree_code_class type
= TREE_CODE_CLASS (code
);
890 if (!GATHER_STATISTICS
)
895 case tcc_declaration
: /* A decl node */
899 case tcc_type
: /* a type node */
903 case tcc_statement
: /* an expression with side effects */
907 case tcc_reference
: /* a reference */
911 case tcc_expression
: /* an expression */
912 case tcc_comparison
: /* a comparison expression */
913 case tcc_unary
: /* a unary arithmetic expression */
914 case tcc_binary
: /* a binary arithmetic expression */
918 case tcc_constant
: /* a constant */
922 case tcc_exceptional
: /* something random, like an identifier. */
925 case IDENTIFIER_NODE
:
938 kind
= ssa_name_kind
;
950 kind
= omp_clause_kind
;
967 tree_code_counts
[(int) code
]++;
968 tree_node_counts
[(int) kind
]++;
969 tree_node_sizes
[(int) kind
] += length
;
972 /* Allocate and return a new UID from the DECL_UID namespace. */
975 allocate_decl_uid (void)
977 return next_decl_uid
++;
980 /* Return a newly allocated node of code CODE. For decl and type
981 nodes, some other fields are initialized. The rest of the node is
982 initialized to zero. This function cannot be used for TREE_VEC,
983 INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
986 Achoo! I got a code in the node. */
989 make_node_stat (enum tree_code code MEM_STAT_DECL
)
992 enum tree_code_class type
= TREE_CODE_CLASS (code
);
993 size_t length
= tree_code_size (code
);
995 record_node_allocation_statistics (code
, length
);
997 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
998 TREE_SET_CODE (t
, code
);
1003 TREE_SIDE_EFFECTS (t
) = 1;
1006 case tcc_declaration
:
1007 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1009 if (code
== FUNCTION_DECL
)
1011 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
1012 DECL_MODE (t
) = FUNCTION_MODE
;
1017 DECL_SOURCE_LOCATION (t
) = input_location
;
1018 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
1019 DECL_UID (t
) = --next_debug_decl_uid
;
1022 DECL_UID (t
) = allocate_decl_uid ();
1023 SET_DECL_PT_UID (t
, -1);
1025 if (TREE_CODE (t
) == LABEL_DECL
)
1026 LABEL_DECL_UID (t
) = -1;
1031 TYPE_UID (t
) = next_type_uid
++;
1032 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
1033 TYPE_USER_ALIGN (t
) = 0;
1034 TYPE_MAIN_VARIANT (t
) = t
;
1035 TYPE_CANONICAL (t
) = t
;
1037 /* Default to no attributes for type, but let target change that. */
1038 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1039 targetm
.set_default_type_attributes (t
);
1041 /* We have not yet computed the alias set for this type. */
1042 TYPE_ALIAS_SET (t
) = -1;
1046 TREE_CONSTANT (t
) = 1;
1049 case tcc_expression
:
1055 case PREDECREMENT_EXPR
:
1056 case PREINCREMENT_EXPR
:
1057 case POSTDECREMENT_EXPR
:
1058 case POSTINCREMENT_EXPR
:
1059 /* All of these have side-effects, no matter what their
1061 TREE_SIDE_EFFECTS (t
) = 1;
1069 case tcc_exceptional
:
1072 case TARGET_OPTION_NODE
:
1073 TREE_TARGET_OPTION(t
)
1074 = ggc_cleared_alloc
<struct cl_target_option
> ();
1077 case OPTIMIZATION_NODE
:
1078 TREE_OPTIMIZATION (t
)
1079 = ggc_cleared_alloc
<struct cl_optimization
> ();
1088 /* Other classes need no special treatment. */
1095 /* Return a new node with the same contents as NODE except that its
1096 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1099 copy_node_stat (tree node MEM_STAT_DECL
)
1102 enum tree_code code
= TREE_CODE (node
);
1105 gcc_assert (code
!= STATEMENT_LIST
);
1107 length
= tree_size (node
);
1108 record_node_allocation_statistics (code
, length
);
1109 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1110 memcpy (t
, node
, length
);
1112 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1114 TREE_ASM_WRITTEN (t
) = 0;
1115 TREE_VISITED (t
) = 0;
1117 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
1119 if (code
== DEBUG_EXPR_DECL
)
1120 DECL_UID (t
) = --next_debug_decl_uid
;
1123 DECL_UID (t
) = allocate_decl_uid ();
1124 if (DECL_PT_UID_SET_P (node
))
1125 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
1127 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
1128 && DECL_HAS_VALUE_EXPR_P (node
))
1130 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
1131 DECL_HAS_VALUE_EXPR_P (t
) = 1;
1133 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
1134 if (TREE_CODE (node
) == VAR_DECL
)
1136 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
1137 t
->decl_with_vis
.symtab_node
= NULL
;
1139 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
1141 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
1142 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
1144 if (TREE_CODE (node
) == FUNCTION_DECL
)
1146 DECL_STRUCT_FUNCTION (t
) = NULL
;
1147 t
->decl_with_vis
.symtab_node
= NULL
;
1150 else if (TREE_CODE_CLASS (code
) == tcc_type
)
1152 TYPE_UID (t
) = next_type_uid
++;
1153 /* The following is so that the debug code for
1154 the copy is different from the original type.
1155 The two statements usually duplicate each other
1156 (because they clear fields of the same union),
1157 but the optimizer should catch that. */
1158 TYPE_SYMTAB_POINTER (t
) = 0;
1159 TYPE_SYMTAB_ADDRESS (t
) = 0;
1161 /* Do not copy the values cache. */
1162 if (TYPE_CACHED_VALUES_P (t
))
1164 TYPE_CACHED_VALUES_P (t
) = 0;
1165 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1168 else if (code
== TARGET_OPTION_NODE
)
1170 TREE_TARGET_OPTION (t
) = ggc_alloc
<struct cl_target_option
>();
1171 memcpy (TREE_TARGET_OPTION (t
), TREE_TARGET_OPTION (node
),
1172 sizeof (struct cl_target_option
));
1174 else if (code
== OPTIMIZATION_NODE
)
1176 TREE_OPTIMIZATION (t
) = ggc_alloc
<struct cl_optimization
>();
1177 memcpy (TREE_OPTIMIZATION (t
), TREE_OPTIMIZATION (node
),
1178 sizeof (struct cl_optimization
));
1184 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1185 For example, this can copy a list made of TREE_LIST nodes. */
1188 copy_list (tree list
)
1196 head
= prev
= copy_node (list
);
1197 next
= TREE_CHAIN (list
);
1200 TREE_CHAIN (prev
) = copy_node (next
);
1201 prev
= TREE_CHAIN (prev
);
1202 next
= TREE_CHAIN (next
);
1208 /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1209 INTEGER_CST with value CST and type TYPE. */
1212 get_int_cst_ext_nunits (tree type
, const wide_int
&cst
)
1214 gcc_checking_assert (cst
.get_precision () == TYPE_PRECISION (type
));
1215 /* We need an extra zero HWI if CST is an unsigned integer with its
1216 upper bit set, and if CST occupies a whole number of HWIs. */
1217 if (TYPE_UNSIGNED (type
)
1219 && (cst
.get_precision () % HOST_BITS_PER_WIDE_INT
) == 0)
1220 return cst
.get_precision () / HOST_BITS_PER_WIDE_INT
+ 1;
1221 return cst
.get_len ();
1224 /* Return a new INTEGER_CST with value CST and type TYPE. */
1227 build_new_int_cst (tree type
, const wide_int
&cst
)
1229 unsigned int len
= cst
.get_len ();
1230 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1231 tree nt
= make_int_cst (len
, ext_len
);
1236 TREE_INT_CST_ELT (nt
, ext_len
) = 0;
1237 for (unsigned int i
= len
; i
< ext_len
; ++i
)
1238 TREE_INT_CST_ELT (nt
, i
) = -1;
1240 else if (TYPE_UNSIGNED (type
)
1241 && cst
.get_precision () < len
* HOST_BITS_PER_WIDE_INT
)
1244 TREE_INT_CST_ELT (nt
, len
)
1245 = zext_hwi (cst
.elt (len
),
1246 cst
.get_precision () % HOST_BITS_PER_WIDE_INT
);
1249 for (unsigned int i
= 0; i
< len
; i
++)
1250 TREE_INT_CST_ELT (nt
, i
) = cst
.elt (i
);
1251 TREE_TYPE (nt
) = type
;
1255 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1258 build_int_cst (tree type
, HOST_WIDE_INT low
)
1260 /* Support legacy code. */
1262 type
= integer_type_node
;
1264 return wide_int_to_tree (type
, wi::shwi (low
, TYPE_PRECISION (type
)));
1268 build_int_cstu (tree type
, unsigned HOST_WIDE_INT cst
)
1270 return wide_int_to_tree (type
, wi::uhwi (cst
, TYPE_PRECISION (type
)));
1273 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1276 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1279 return wide_int_to_tree (type
, wi::shwi (low
, TYPE_PRECISION (type
)));
1282 /* Constructs tree in type TYPE from with value given by CST. Signedness
1283 of CST is assumed to be the same as the signedness of TYPE. */
1286 double_int_to_tree (tree type
, double_int cst
)
1288 return wide_int_to_tree (type
, widest_int::from (cst
, TYPE_SIGN (type
)));
1291 /* We force the wide_int CST to the range of the type TYPE by sign or
1292 zero extending it. OVERFLOWABLE indicates if we are interested in
1293 overflow of the value, when >0 we are only interested in signed
1294 overflow, for <0 we are interested in any overflow. OVERFLOWED
1295 indicates whether overflow has already occurred. CONST_OVERFLOWED
1296 indicates whether constant overflow has already occurred. We force
1297 T's value to be within range of T's type (by setting to 0 or 1 all
1298 the bits outside the type's range). We set TREE_OVERFLOWED if,
1299 OVERFLOWED is nonzero,
1300 or OVERFLOWABLE is >0 and signed overflow occurs
1301 or OVERFLOWABLE is <0 and any overflow occurs
1302 We return a new tree node for the extended wide_int. The node
1303 is shared if no overflow flags are set. */
1307 force_fit_type (tree type
, const wide_int_ref
&cst
,
1308 int overflowable
, bool overflowed
)
1310 signop sign
= TYPE_SIGN (type
);
1312 /* If we need to set overflow flags, return a new unshared node. */
1313 if (overflowed
|| !wi::fits_to_tree_p (cst
, type
))
1317 || (overflowable
> 0 && sign
== SIGNED
))
1319 wide_int tmp
= wide_int::from (cst
, TYPE_PRECISION (type
), sign
);
1320 tree t
= build_new_int_cst (type
, tmp
);
1321 TREE_OVERFLOW (t
) = 1;
1326 /* Else build a shared node. */
1327 return wide_int_to_tree (type
, cst
);
1330 /* These are the hash table functions for the hash table of INTEGER_CST
1331 nodes of a sizetype. */
1333 /* Return the hash code X, an INTEGER_CST. */
1336 int_cst_hasher::hash (tree x
)
1338 const_tree
const t
= x
;
1339 hashval_t code
= TYPE_UID (TREE_TYPE (t
));
1342 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
1343 code
^= TREE_INT_CST_ELT (t
, i
);
1348 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1349 is the same as that given by *Y, which is the same. */
1352 int_cst_hasher::equal (tree x
, tree y
)
1354 const_tree
const xt
= x
;
1355 const_tree
const yt
= y
;
1357 if (TREE_TYPE (xt
) != TREE_TYPE (yt
)
1358 || TREE_INT_CST_NUNITS (xt
) != TREE_INT_CST_NUNITS (yt
)
1359 || TREE_INT_CST_EXT_NUNITS (xt
) != TREE_INT_CST_EXT_NUNITS (yt
))
1362 for (int i
= 0; i
< TREE_INT_CST_NUNITS (xt
); i
++)
1363 if (TREE_INT_CST_ELT (xt
, i
) != TREE_INT_CST_ELT (yt
, i
))
1369 /* Create an INT_CST node of TYPE and value CST.
1370 The returned node is always shared. For small integers we use a
1371 per-type vector cache, for larger ones we use a single hash table.
1372 The value is extended from its precision according to the sign of
1373 the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1374 the upper bits and ensures that hashing and value equality based
1375 upon the underlying HOST_WIDE_INTs works without masking. */
1378 wide_int_to_tree (tree type
, const wide_int_ref
&pcst
)
1385 unsigned int prec
= TYPE_PRECISION (type
);
1386 signop sgn
= TYPE_SIGN (type
);
1388 /* Verify that everything is canonical. */
1389 int l
= pcst
.get_len ();
1392 if (pcst
.elt (l
- 1) == 0)
1393 gcc_checking_assert (pcst
.elt (l
- 2) < 0);
1394 if (pcst
.elt (l
- 1) == (HOST_WIDE_INT
) -1)
1395 gcc_checking_assert (pcst
.elt (l
- 2) >= 0);
1398 wide_int cst
= wide_int::from (pcst
, prec
, sgn
);
1399 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1403 /* We just need to store a single HOST_WIDE_INT. */
1405 if (TYPE_UNSIGNED (type
))
1406 hwi
= cst
.to_uhwi ();
1408 hwi
= cst
.to_shwi ();
1410 switch (TREE_CODE (type
))
1413 gcc_assert (hwi
== 0);
1417 case REFERENCE_TYPE
:
1418 case POINTER_BOUNDS_TYPE
:
1419 /* Cache NULL pointer and zero bounds. */
1428 /* Cache false or true. */
1436 if (TYPE_SIGN (type
) == UNSIGNED
)
1439 limit
= INTEGER_SHARE_LIMIT
;
1440 if (IN_RANGE (hwi
, 0, INTEGER_SHARE_LIMIT
- 1))
1445 /* Cache [-1, N). */
1446 limit
= INTEGER_SHARE_LIMIT
+ 1;
1447 if (IN_RANGE (hwi
, -1, INTEGER_SHARE_LIMIT
- 1))
1461 /* Look for it in the type's vector of small shared ints. */
1462 if (!TYPE_CACHED_VALUES_P (type
))
1464 TYPE_CACHED_VALUES_P (type
) = 1;
1465 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1468 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1470 /* Make sure no one is clobbering the shared constant. */
1471 gcc_checking_assert (TREE_TYPE (t
) == type
1472 && TREE_INT_CST_NUNITS (t
) == 1
1473 && TREE_INT_CST_OFFSET_NUNITS (t
) == 1
1474 && TREE_INT_CST_EXT_NUNITS (t
) == 1
1475 && TREE_INT_CST_ELT (t
, 0) == hwi
);
1478 /* Create a new shared int. */
1479 t
= build_new_int_cst (type
, cst
);
1480 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1485 /* Use the cache of larger shared ints, using int_cst_node as
1488 TREE_INT_CST_ELT (int_cst_node
, 0) = hwi
;
1489 TREE_TYPE (int_cst_node
) = type
;
1491 tree
*slot
= int_cst_hash_table
->find_slot (int_cst_node
, INSERT
);
1495 /* Insert this one into the hash table. */
1498 /* Make a new node for next time round. */
1499 int_cst_node
= make_int_cst (1, 1);
1505 /* The value either hashes properly or we drop it on the floor
1506 for the gc to take care of. There will not be enough of them
1509 tree nt
= build_new_int_cst (type
, cst
);
1510 tree
*slot
= int_cst_hash_table
->find_slot (nt
, INSERT
);
1514 /* Insert this one into the hash table. */
1524 cache_integer_cst (tree t
)
1526 tree type
= TREE_TYPE (t
);
1529 int prec
= TYPE_PRECISION (type
);
1531 gcc_assert (!TREE_OVERFLOW (t
));
1533 switch (TREE_CODE (type
))
1536 gcc_assert (integer_zerop (t
));
1540 case REFERENCE_TYPE
:
1541 /* Cache NULL pointer. */
1542 if (integer_zerop (t
))
1550 /* Cache false or true. */
1552 if (wi::ltu_p (t
, 2))
1553 ix
= TREE_INT_CST_ELT (t
, 0);
1558 if (TYPE_UNSIGNED (type
))
1561 limit
= INTEGER_SHARE_LIMIT
;
1563 /* This is a little hokie, but if the prec is smaller than
1564 what is necessary to hold INTEGER_SHARE_LIMIT, then the
1565 obvious test will not get the correct answer. */
1566 if (prec
< HOST_BITS_PER_WIDE_INT
)
1568 if (tree_to_uhwi (t
) < (unsigned HOST_WIDE_INT
) INTEGER_SHARE_LIMIT
)
1569 ix
= tree_to_uhwi (t
);
1571 else if (wi::ltu_p (t
, INTEGER_SHARE_LIMIT
))
1572 ix
= tree_to_uhwi (t
);
1577 limit
= INTEGER_SHARE_LIMIT
+ 1;
1579 if (integer_minus_onep (t
))
1581 else if (!wi::neg_p (t
))
1583 if (prec
< HOST_BITS_PER_WIDE_INT
)
1585 if (tree_to_shwi (t
) < INTEGER_SHARE_LIMIT
)
1586 ix
= tree_to_shwi (t
) + 1;
1588 else if (wi::ltu_p (t
, INTEGER_SHARE_LIMIT
))
1589 ix
= tree_to_shwi (t
) + 1;
1603 /* Look for it in the type's vector of small shared ints. */
1604 if (!TYPE_CACHED_VALUES_P (type
))
1606 TYPE_CACHED_VALUES_P (type
) = 1;
1607 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1610 gcc_assert (TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) == NULL_TREE
);
1611 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1615 /* Use the cache of larger shared ints. */
1616 tree
*slot
= int_cst_hash_table
->find_slot (t
, INSERT
);
1617 /* If there is already an entry for the number verify it's the
1620 gcc_assert (wi::eq_p (tree (*slot
), t
));
1622 /* Otherwise insert this one into the hash table. */
1628 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1629 and the rest are zeros. */
1632 build_low_bits_mask (tree type
, unsigned bits
)
1634 gcc_assert (bits
<= TYPE_PRECISION (type
));
1636 return wide_int_to_tree (type
, wi::mask (bits
, false,
1637 TYPE_PRECISION (type
)));
1640 /* Checks that X is integer constant that can be expressed in (unsigned)
1641 HOST_WIDE_INT without loss of precision. */
1644 cst_and_fits_in_hwi (const_tree x
)
1646 if (TREE_CODE (x
) != INTEGER_CST
)
1649 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1652 return TREE_INT_CST_NUNITS (x
) == 1;
1655 /* Build a newly constructed VECTOR_CST node of length LEN. */
1658 make_vector_stat (unsigned len MEM_STAT_DECL
)
1661 unsigned length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vector
);
1663 record_node_allocation_statistics (VECTOR_CST
, length
);
1665 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1667 TREE_SET_CODE (t
, VECTOR_CST
);
1668 TREE_CONSTANT (t
) = 1;
1673 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1674 are in a list pointed to by VALS. */
1677 build_vector_stat (tree type
, tree
*vals MEM_STAT_DECL
)
1681 tree v
= make_vector (TYPE_VECTOR_SUBPARTS (type
));
1682 TREE_TYPE (v
) = type
;
1684 /* Iterate through elements and check for overflow. */
1685 for (cnt
= 0; cnt
< TYPE_VECTOR_SUBPARTS (type
); ++cnt
)
1687 tree value
= vals
[cnt
];
1689 VECTOR_CST_ELT (v
, cnt
) = value
;
1691 /* Don't crash if we get an address constant. */
1692 if (!CONSTANT_CLASS_P (value
))
1695 over
|= TREE_OVERFLOW (value
);
1698 TREE_OVERFLOW (v
) = over
;
1702 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1703 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1706 build_vector_from_ctor (tree type
, vec
<constructor_elt
, va_gc
> *v
)
1708 tree
*vec
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (type
));
1709 unsigned HOST_WIDE_INT idx
;
1712 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1714 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1715 vec
[idx
] = build_zero_cst (TREE_TYPE (type
));
1717 return build_vector (type
, vec
);
1720 /* Build a vector of type VECTYPE where all the elements are SCs. */
1722 build_vector_from_val (tree vectype
, tree sc
)
1724 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1726 if (sc
== error_mark_node
)
1729 /* Verify that the vector type is suitable for SC. Note that there
1730 is some inconsistency in the type-system with respect to restrict
1731 qualifications of pointers. Vector types always have a main-variant
1732 element type and the qualification is applied to the vector-type.
1733 So TREE_TYPE (vector-type) does not return a properly qualified
1734 vector element-type. */
1735 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1736 TREE_TYPE (vectype
)));
1738 if (CONSTANT_CLASS_P (sc
))
1740 tree
*v
= XALLOCAVEC (tree
, nunits
);
1741 for (i
= 0; i
< nunits
; ++i
)
1743 return build_vector (vectype
, v
);
1747 vec
<constructor_elt
, va_gc
> *v
;
1748 vec_alloc (v
, nunits
);
1749 for (i
= 0; i
< nunits
; ++i
)
1750 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1751 return build_constructor (vectype
, v
);
1755 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1756 are in the vec pointed to by VALS. */
1758 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals
)
1760 tree c
= make_node (CONSTRUCTOR
);
1762 constructor_elt
*elt
;
1763 bool constant_p
= true;
1764 bool side_effects_p
= false;
1766 TREE_TYPE (c
) = type
;
1767 CONSTRUCTOR_ELTS (c
) = vals
;
1769 FOR_EACH_VEC_SAFE_ELT (vals
, i
, elt
)
1771 /* Mostly ctors will have elts that don't have side-effects, so
1772 the usual case is to scan all the elements. Hence a single
1773 loop for both const and side effects, rather than one loop
1774 each (with early outs). */
1775 if (!TREE_CONSTANT (elt
->value
))
1777 if (TREE_SIDE_EFFECTS (elt
->value
))
1778 side_effects_p
= true;
1781 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
1782 TREE_CONSTANT (c
) = constant_p
;
1787 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1790 build_constructor_single (tree type
, tree index
, tree value
)
1792 vec
<constructor_elt
, va_gc
> *v
;
1793 constructor_elt elt
= {index
, value
};
1796 v
->quick_push (elt
);
1798 return build_constructor (type
, v
);
1802 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1803 are in a list pointed to by VALS. */
1805 build_constructor_from_list (tree type
, tree vals
)
1808 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1812 vec_alloc (v
, list_length (vals
));
1813 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1814 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1817 return build_constructor (type
, v
);
1820 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1821 of elements, provided as index/value pairs. */
1824 build_constructor_va (tree type
, int nelts
, ...)
1826 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1829 va_start (p
, nelts
);
1830 vec_alloc (v
, nelts
);
1833 tree index
= va_arg (p
, tree
);
1834 tree value
= va_arg (p
, tree
);
1835 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
1838 return build_constructor (type
, v
);
1841 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1844 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1847 FIXED_VALUE_TYPE
*fp
;
1849 v
= make_node (FIXED_CST
);
1850 fp
= ggc_alloc
<fixed_value
> ();
1851 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1853 TREE_TYPE (v
) = type
;
1854 TREE_FIXED_CST_PTR (v
) = fp
;
1858 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1861 build_real (tree type
, REAL_VALUE_TYPE d
)
1864 REAL_VALUE_TYPE
*dp
;
1867 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1868 Consider doing it via real_convert now. */
1870 v
= make_node (REAL_CST
);
1871 dp
= ggc_alloc
<real_value
> ();
1872 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1874 TREE_TYPE (v
) = type
;
1875 TREE_REAL_CST_PTR (v
) = dp
;
1876 TREE_OVERFLOW (v
) = overflow
;
1880 /* Return a new REAL_CST node whose type is TYPE
1881 and whose value is the integer value of the INTEGER_CST node I. */
1884 real_value_from_int_cst (const_tree type
, const_tree i
)
1888 /* Clear all bits of the real value type so that we can later do
1889 bitwise comparisons to see if two values are the same. */
1890 memset (&d
, 0, sizeof d
);
1892 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
, i
,
1893 TYPE_SIGN (TREE_TYPE (i
)));
1897 /* Given a tree representing an integer constant I, return a tree
1898 representing the same value as a floating-point constant of type TYPE. */
1901 build_real_from_int_cst (tree type
, const_tree i
)
1904 int overflow
= TREE_OVERFLOW (i
);
1906 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1908 TREE_OVERFLOW (v
) |= overflow
;
1912 /* Return a newly constructed STRING_CST node whose value is
1913 the LEN characters at STR.
1914 Note that for a C string literal, LEN should include the trailing NUL.
1915 The TREE_TYPE is not initialized. */
1918 build_string (int len
, const char *str
)
1923 /* Do not waste bytes provided by padding of struct tree_string. */
1924 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1926 record_node_allocation_statistics (STRING_CST
, length
);
1928 s
= (tree
) ggc_internal_alloc (length
);
1930 memset (s
, 0, sizeof (struct tree_typed
));
1931 TREE_SET_CODE (s
, STRING_CST
);
1932 TREE_CONSTANT (s
) = 1;
1933 TREE_STRING_LENGTH (s
) = len
;
1934 memcpy (s
->string
.str
, str
, len
);
1935 s
->string
.str
[len
] = '\0';
1940 /* Return a newly constructed COMPLEX_CST node whose value is
1941 specified by the real and imaginary parts REAL and IMAG.
1942 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1943 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1946 build_complex (tree type
, tree real
, tree imag
)
1948 tree t
= make_node (COMPLEX_CST
);
1950 TREE_REALPART (t
) = real
;
1951 TREE_IMAGPART (t
) = imag
;
1952 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1953 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1957 /* Return the constant 1 in type TYPE. If TYPE has several elements, each
1958 element is set to 1. In particular, this is 1 + i for complex types. */
1961 build_each_one_cst (tree type
)
1963 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1965 tree scalar
= build_one_cst (TREE_TYPE (type
));
1966 return build_complex (type
, scalar
, scalar
);
1969 return build_one_cst (type
);
1972 /* Return a constant of arithmetic type TYPE which is the
1973 multiplicative identity of the set TYPE. */
1976 build_one_cst (tree type
)
1978 switch (TREE_CODE (type
))
1980 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1981 case POINTER_TYPE
: case REFERENCE_TYPE
:
1983 return build_int_cst (type
, 1);
1986 return build_real (type
, dconst1
);
1988 case FIXED_POINT_TYPE
:
1989 /* We can only generate 1 for accum types. */
1990 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1991 return build_fixed (type
, FCONST1 (TYPE_MODE (type
)));
1995 tree scalar
= build_one_cst (TREE_TYPE (type
));
1997 return build_vector_from_val (type
, scalar
);
2001 return build_complex (type
,
2002 build_one_cst (TREE_TYPE (type
)),
2003 build_zero_cst (TREE_TYPE (type
)));
2010 /* Return an integer of type TYPE containing all 1's in as much precision as
2011 it contains, or a complex or vector whose subparts are such integers. */
2014 build_all_ones_cst (tree type
)
2016 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2018 tree scalar
= build_all_ones_cst (TREE_TYPE (type
));
2019 return build_complex (type
, scalar
, scalar
);
2022 return build_minus_one_cst (type
);
2025 /* Return a constant of arithmetic type TYPE which is the
2026 opposite of the multiplicative identity of the set TYPE. */
2029 build_minus_one_cst (tree type
)
2031 switch (TREE_CODE (type
))
2033 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2034 case POINTER_TYPE
: case REFERENCE_TYPE
:
2036 return build_int_cst (type
, -1);
2039 return build_real (type
, dconstm1
);
2041 case FIXED_POINT_TYPE
:
2042 /* We can only generate 1 for accum types. */
2043 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
2044 return build_fixed (type
, fixed_from_double_int (double_int_minus_one
,
2049 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
2051 return build_vector_from_val (type
, scalar
);
2055 return build_complex (type
,
2056 build_minus_one_cst (TREE_TYPE (type
)),
2057 build_zero_cst (TREE_TYPE (type
)));
2064 /* Build 0 constant of type TYPE. This is used by constructor folding
2065 and thus the constant should be represented in memory by
2069 build_zero_cst (tree type
)
2071 switch (TREE_CODE (type
))
2073 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2074 case POINTER_TYPE
: case REFERENCE_TYPE
:
2075 case OFFSET_TYPE
: case NULLPTR_TYPE
:
2076 return build_int_cst (type
, 0);
2079 return build_real (type
, dconst0
);
2081 case FIXED_POINT_TYPE
:
2082 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
2086 tree scalar
= build_zero_cst (TREE_TYPE (type
));
2088 return build_vector_from_val (type
, scalar
);
2093 tree zero
= build_zero_cst (TREE_TYPE (type
));
2095 return build_complex (type
, zero
, zero
);
2099 if (!AGGREGATE_TYPE_P (type
))
2100 return fold_convert (type
, integer_zero_node
);
2101 return build_constructor (type
, NULL
);
2106 /* Build a BINFO with LEN language slots. */
2109 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
2112 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
2113 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
2115 record_node_allocation_statistics (TREE_BINFO
, length
);
2117 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
2119 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
2121 TREE_SET_CODE (t
, TREE_BINFO
);
2123 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
2128 /* Create a CASE_LABEL_EXPR tree node and return it. */
2131 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
2133 tree t
= make_node (CASE_LABEL_EXPR
);
2135 TREE_TYPE (t
) = void_type_node
;
2136 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
2138 CASE_LOW (t
) = low_value
;
2139 CASE_HIGH (t
) = high_value
;
2140 CASE_LABEL (t
) = label_decl
;
2141 CASE_CHAIN (t
) = NULL_TREE
;
2146 /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2147 values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2148 The latter determines the length of the HOST_WIDE_INT vector. */
2151 make_int_cst_stat (int len
, int ext_len MEM_STAT_DECL
)
2154 int length
= ((ext_len
- 1) * sizeof (HOST_WIDE_INT
)
2155 + sizeof (struct tree_int_cst
));
2158 record_node_allocation_statistics (INTEGER_CST
, length
);
2160 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2162 TREE_SET_CODE (t
, INTEGER_CST
);
2163 TREE_INT_CST_NUNITS (t
) = len
;
2164 TREE_INT_CST_EXT_NUNITS (t
) = ext_len
;
2165 /* to_offset can only be applied to trees that are offset_int-sized
2166 or smaller. EXT_LEN is correct if it fits, otherwise the constant
2167 must be exactly the precision of offset_int and so LEN is correct. */
2168 if (ext_len
<= OFFSET_INT_ELTS
)
2169 TREE_INT_CST_OFFSET_NUNITS (t
) = ext_len
;
2171 TREE_INT_CST_OFFSET_NUNITS (t
) = len
;
2173 TREE_CONSTANT (t
) = 1;
2178 /* Build a newly constructed TREE_VEC node of length LEN. */
2181 make_tree_vec_stat (int len MEM_STAT_DECL
)
2184 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2186 record_node_allocation_statistics (TREE_VEC
, length
);
2188 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2190 TREE_SET_CODE (t
, TREE_VEC
);
2191 TREE_VEC_LENGTH (t
) = len
;
2196 /* Grow a TREE_VEC node to new length LEN. */
2199 grow_tree_vec_stat (tree v
, int len MEM_STAT_DECL
)
2201 gcc_assert (TREE_CODE (v
) == TREE_VEC
);
2203 int oldlen
= TREE_VEC_LENGTH (v
);
2204 gcc_assert (len
> oldlen
);
2206 int oldlength
= (oldlen
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2207 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2209 record_node_allocation_statistics (TREE_VEC
, length
- oldlength
);
2211 v
= (tree
) ggc_realloc (v
, length PASS_MEM_STAT
);
2213 TREE_VEC_LENGTH (v
) = len
;
2218 /* Return 1 if EXPR is the integer constant zero or a complex constant
2222 integer_zerop (const_tree expr
)
2226 switch (TREE_CODE (expr
))
2229 return wi::eq_p (expr
, 0);
2231 return (integer_zerop (TREE_REALPART (expr
))
2232 && integer_zerop (TREE_IMAGPART (expr
)));
2236 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2237 if (!integer_zerop (VECTOR_CST_ELT (expr
, i
)))
2246 /* Return 1 if EXPR is the integer constant one or the corresponding
2247 complex constant. */
2250 integer_onep (const_tree expr
)
2254 switch (TREE_CODE (expr
))
2257 return wi::eq_p (wi::to_widest (expr
), 1);
2259 return (integer_onep (TREE_REALPART (expr
))
2260 && integer_zerop (TREE_IMAGPART (expr
)));
2264 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2265 if (!integer_onep (VECTOR_CST_ELT (expr
, i
)))
2274 /* Return 1 if EXPR is the integer constant one. For complex and vector,
2275 return 1 if every piece is the integer constant one. */
2278 integer_each_onep (const_tree expr
)
2282 if (TREE_CODE (expr
) == COMPLEX_CST
)
2283 return (integer_onep (TREE_REALPART (expr
))
2284 && integer_onep (TREE_IMAGPART (expr
)));
2286 return integer_onep (expr
);
2289 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
2290 it contains, or a complex or vector whose subparts are such integers. */
2293 integer_all_onesp (const_tree expr
)
2297 if (TREE_CODE (expr
) == COMPLEX_CST
2298 && integer_all_onesp (TREE_REALPART (expr
))
2299 && integer_all_onesp (TREE_IMAGPART (expr
)))
2302 else if (TREE_CODE (expr
) == VECTOR_CST
)
2305 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2306 if (!integer_all_onesp (VECTOR_CST_ELT (expr
, i
)))
2311 else if (TREE_CODE (expr
) != INTEGER_CST
)
2314 return wi::max_value (TYPE_PRECISION (TREE_TYPE (expr
)), UNSIGNED
) == expr
;
2317 /* Return 1 if EXPR is the integer constant minus one. */
2320 integer_minus_onep (const_tree expr
)
2324 if (TREE_CODE (expr
) == COMPLEX_CST
)
2325 return (integer_all_onesp (TREE_REALPART (expr
))
2326 && integer_zerop (TREE_IMAGPART (expr
)));
2328 return integer_all_onesp (expr
);
2331 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2335 integer_pow2p (const_tree expr
)
2339 if (TREE_CODE (expr
) == COMPLEX_CST
2340 && integer_pow2p (TREE_REALPART (expr
))
2341 && integer_zerop (TREE_IMAGPART (expr
)))
2344 if (TREE_CODE (expr
) != INTEGER_CST
)
2347 return wi::popcount (expr
) == 1;
2350 /* Return 1 if EXPR is an integer constant other than zero or a
2351 complex constant other than zero. */
2354 integer_nonzerop (const_tree expr
)
2358 return ((TREE_CODE (expr
) == INTEGER_CST
2359 && !wi::eq_p (expr
, 0))
2360 || (TREE_CODE (expr
) == COMPLEX_CST
2361 && (integer_nonzerop (TREE_REALPART (expr
))
2362 || integer_nonzerop (TREE_IMAGPART (expr
)))));
2365 /* Return 1 if EXPR is the integer constant one. For vector,
2366 return 1 if every piece is the integer constant minus one
2367 (representing the value TRUE). */
2370 integer_truep (const_tree expr
)
2374 if (TREE_CODE (expr
) == VECTOR_CST
)
2375 return integer_all_onesp (expr
);
2376 return integer_onep (expr
);
2379 /* Return 1 if EXPR is the fixed-point constant zero. */
2382 fixed_zerop (const_tree expr
)
2384 return (TREE_CODE (expr
) == FIXED_CST
2385 && TREE_FIXED_CST (expr
).data
.is_zero ());
2388 /* Return the power of two represented by a tree node known to be a
2392 tree_log2 (const_tree expr
)
2396 if (TREE_CODE (expr
) == COMPLEX_CST
)
2397 return tree_log2 (TREE_REALPART (expr
));
2399 return wi::exact_log2 (expr
);
2402 /* Similar, but return the largest integer Y such that 2 ** Y is less
2403 than or equal to EXPR. */
2406 tree_floor_log2 (const_tree expr
)
2410 if (TREE_CODE (expr
) == COMPLEX_CST
)
2411 return tree_log2 (TREE_REALPART (expr
));
2413 return wi::floor_log2 (expr
);
2416 /* Return number of known trailing zero bits in EXPR, or, if the value of
2417 EXPR is known to be zero, the precision of it's type. */
2420 tree_ctz (const_tree expr
)
2422 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
2423 && !POINTER_TYPE_P (TREE_TYPE (expr
)))
2426 unsigned int ret1
, ret2
, prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2427 switch (TREE_CODE (expr
))
2430 ret1
= wi::ctz (expr
);
2431 return MIN (ret1
, prec
);
2433 ret1
= wi::ctz (get_nonzero_bits (expr
));
2434 return MIN (ret1
, prec
);
2441 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2444 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2445 return MIN (ret1
, ret2
);
2446 case POINTER_PLUS_EXPR
:
2447 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2448 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2449 /* Second operand is sizetype, which could be in theory
2450 wider than pointer's precision. Make sure we never
2451 return more than prec. */
2452 ret2
= MIN (ret2
, prec
);
2453 return MIN (ret1
, ret2
);
2455 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2456 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2457 return MAX (ret1
, ret2
);
2459 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2460 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2461 return MIN (ret1
+ ret2
, prec
);
2463 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2464 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
2465 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
2467 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
2468 return MIN (ret1
+ ret2
, prec
);
2472 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
2473 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
2475 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2476 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
2481 case TRUNC_DIV_EXPR
:
2483 case FLOOR_DIV_EXPR
:
2484 case ROUND_DIV_EXPR
:
2485 case EXACT_DIV_EXPR
:
2486 if (TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
2487 && tree_int_cst_sgn (TREE_OPERAND (expr
, 1)) == 1)
2489 int l
= tree_log2 (TREE_OPERAND (expr
, 1));
2492 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2500 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2501 if (ret1
&& ret1
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2503 return MIN (ret1
, prec
);
2505 return tree_ctz (TREE_OPERAND (expr
, 0));
2507 ret1
= tree_ctz (TREE_OPERAND (expr
, 1));
2510 ret2
= tree_ctz (TREE_OPERAND (expr
, 2));
2511 return MIN (ret1
, ret2
);
2513 return tree_ctz (TREE_OPERAND (expr
, 1));
2515 ret1
= get_pointer_alignment (CONST_CAST_TREE (expr
));
2516 if (ret1
> BITS_PER_UNIT
)
2518 ret1
= ctz_hwi (ret1
/ BITS_PER_UNIT
);
2519 return MIN (ret1
, prec
);
2527 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2528 decimal float constants, so don't return 1 for them. */
2531 real_zerop (const_tree expr
)
2535 switch (TREE_CODE (expr
))
2538 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
2539 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2541 return real_zerop (TREE_REALPART (expr
))
2542 && real_zerop (TREE_IMAGPART (expr
));
2546 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2547 if (!real_zerop (VECTOR_CST_ELT (expr
, i
)))
2556 /* Return 1 if EXPR is the real constant one in real or complex form.
2557 Trailing zeroes matter for decimal float constants, so don't return
2561 real_onep (const_tree expr
)
2565 switch (TREE_CODE (expr
))
2568 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
2569 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2571 return real_onep (TREE_REALPART (expr
))
2572 && real_zerop (TREE_IMAGPART (expr
));
2576 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2577 if (!real_onep (VECTOR_CST_ELT (expr
, i
)))
2586 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2587 matter for decimal float constants, so don't return 1 for them. */
2590 real_minus_onep (const_tree expr
)
2594 switch (TREE_CODE (expr
))
2597 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
2598 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2600 return real_minus_onep (TREE_REALPART (expr
))
2601 && real_zerop (TREE_IMAGPART (expr
));
2605 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2606 if (!real_minus_onep (VECTOR_CST_ELT (expr
, i
)))
2615 /* Nonzero if EXP is a constant or a cast of a constant. */
2618 really_constant_p (const_tree exp
)
2620 /* This is not quite the same as STRIP_NOPS. It does more. */
2621 while (CONVERT_EXPR_P (exp
)
2622 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2623 exp
= TREE_OPERAND (exp
, 0);
2624 return TREE_CONSTANT (exp
);
2627 /* Return first list element whose TREE_VALUE is ELEM.
2628 Return 0 if ELEM is not in LIST. */
2631 value_member (tree elem
, tree list
)
2635 if (elem
== TREE_VALUE (list
))
2637 list
= TREE_CHAIN (list
);
2642 /* Return first list element whose TREE_PURPOSE is ELEM.
2643 Return 0 if ELEM is not in LIST. */
2646 purpose_member (const_tree elem
, tree list
)
2650 if (elem
== TREE_PURPOSE (list
))
2652 list
= TREE_CHAIN (list
);
2657 /* Return true if ELEM is in V. */
2660 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
2664 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
2670 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2674 chain_index (int idx
, tree chain
)
2676 for (; chain
&& idx
> 0; --idx
)
2677 chain
= TREE_CHAIN (chain
);
2681 /* Return nonzero if ELEM is part of the chain CHAIN. */
2684 chain_member (const_tree elem
, const_tree chain
)
2690 chain
= DECL_CHAIN (chain
);
2696 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2697 We expect a null pointer to mark the end of the chain.
2698 This is the Lisp primitive `length'. */
2701 list_length (const_tree t
)
2704 #ifdef ENABLE_TREE_CHECKING
2712 #ifdef ENABLE_TREE_CHECKING
2715 gcc_assert (p
!= q
);
2723 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2724 UNION_TYPE TYPE, or NULL_TREE if none. */
2727 first_field (const_tree type
)
2729 tree t
= TYPE_FIELDS (type
);
2730 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2735 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2736 by modifying the last node in chain 1 to point to chain 2.
2737 This is the Lisp primitive `nconc'. */
2740 chainon (tree op1
, tree op2
)
2749 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2751 TREE_CHAIN (t1
) = op2
;
2753 #ifdef ENABLE_TREE_CHECKING
2756 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2757 gcc_assert (t2
!= t1
);
2764 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2767 tree_last (tree chain
)
2771 while ((next
= TREE_CHAIN (chain
)))
2776 /* Reverse the order of elements in the chain T,
2777 and return the new head of the chain (old last element). */
2782 tree prev
= 0, decl
, next
;
2783 for (decl
= t
; decl
; decl
= next
)
2785 /* We shouldn't be using this function to reverse BLOCK chains; we
2786 have blocks_nreverse for that. */
2787 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2788 next
= TREE_CHAIN (decl
);
2789 TREE_CHAIN (decl
) = prev
;
2795 /* Return a newly created TREE_LIST node whose
2796 purpose and value fields are PARM and VALUE. */
2799 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2801 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2802 TREE_PURPOSE (t
) = parm
;
2803 TREE_VALUE (t
) = value
;
2807 /* Build a chain of TREE_LIST nodes from a vector. */
2810 build_tree_list_vec_stat (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
2812 tree ret
= NULL_TREE
;
2816 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
2818 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2819 pp
= &TREE_CHAIN (*pp
);
2824 /* Return a newly created TREE_LIST node whose
2825 purpose and value fields are PURPOSE and VALUE
2826 and whose TREE_CHAIN is CHAIN. */
2829 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2833 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
2834 memset (node
, 0, sizeof (struct tree_common
));
2836 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2838 TREE_SET_CODE (node
, TREE_LIST
);
2839 TREE_CHAIN (node
) = chain
;
2840 TREE_PURPOSE (node
) = purpose
;
2841 TREE_VALUE (node
) = value
;
2845 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2849 ctor_to_vec (tree ctor
)
2851 vec
<tree
, va_gc
> *vec
;
2852 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
2856 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2857 vec
->quick_push (val
);
2862 /* Return the size nominally occupied by an object of type TYPE
2863 when it resides in memory. The value is measured in units of bytes,
2864 and its data type is that normally used for type sizes
2865 (which is the first type created by make_signed_type or
2866 make_unsigned_type). */
2869 size_in_bytes (const_tree type
)
2873 if (type
== error_mark_node
)
2874 return integer_zero_node
;
2876 type
= TYPE_MAIN_VARIANT (type
);
2877 t
= TYPE_SIZE_UNIT (type
);
2881 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2882 return size_zero_node
;
2888 /* Return the size of TYPE (in bytes) as a wide integer
2889 or return -1 if the size can vary or is larger than an integer. */
2892 int_size_in_bytes (const_tree type
)
2896 if (type
== error_mark_node
)
2899 type
= TYPE_MAIN_VARIANT (type
);
2900 t
= TYPE_SIZE_UNIT (type
);
2902 if (t
&& tree_fits_uhwi_p (t
))
2903 return TREE_INT_CST_LOW (t
);
2908 /* Return the maximum size of TYPE (in bytes) as a wide integer
2909 or return -1 if the size can vary or is larger than an integer. */
2912 max_int_size_in_bytes (const_tree type
)
2914 HOST_WIDE_INT size
= -1;
2917 /* If this is an array type, check for a possible MAX_SIZE attached. */
2919 if (TREE_CODE (type
) == ARRAY_TYPE
)
2921 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2923 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
2924 size
= tree_to_uhwi (size_tree
);
2927 /* If we still haven't been able to get a size, see if the language
2928 can compute a maximum size. */
2932 size_tree
= lang_hooks
.types
.max_size (type
);
2934 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
2935 size
= tree_to_uhwi (size_tree
);
2941 /* Return the bit position of FIELD, in bits from the start of the record.
2942 This is a tree of type bitsizetype. */
2945 bit_position (const_tree field
)
2947 return bit_from_pos (DECL_FIELD_OFFSET (field
),
2948 DECL_FIELD_BIT_OFFSET (field
));
2951 /* Return the byte position of FIELD, in bytes from the start of the record.
2952 This is a tree of type sizetype. */
2955 byte_position (const_tree field
)
2957 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2958 DECL_FIELD_BIT_OFFSET (field
));
2961 /* Likewise, but return as an integer. It must be representable in
2962 that way (since it could be a signed value, we don't have the
2963 option of returning -1 like int_size_in_byte can. */
2966 int_byte_position (const_tree field
)
2968 return tree_to_shwi (byte_position (field
));
2971 /* Return the strictest alignment, in bits, that T is known to have. */
2974 expr_align (const_tree t
)
2976 unsigned int align0
, align1
;
2978 switch (TREE_CODE (t
))
2980 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2981 /* If we have conversions, we know that the alignment of the
2982 object must meet each of the alignments of the types. */
2983 align0
= expr_align (TREE_OPERAND (t
, 0));
2984 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2985 return MAX (align0
, align1
);
2987 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2988 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2989 case CLEANUP_POINT_EXPR
:
2990 /* These don't change the alignment of an object. */
2991 return expr_align (TREE_OPERAND (t
, 0));
2994 /* The best we can do is say that the alignment is the least aligned
2996 align0
= expr_align (TREE_OPERAND (t
, 1));
2997 align1
= expr_align (TREE_OPERAND (t
, 2));
2998 return MIN (align0
, align1
);
3000 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
3001 meaningfully, it's always 1. */
3002 case LABEL_DECL
: case CONST_DECL
:
3003 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
3005 gcc_assert (DECL_ALIGN (t
) != 0);
3006 return DECL_ALIGN (t
);
3012 /* Otherwise take the alignment from that of the type. */
3013 return TYPE_ALIGN (TREE_TYPE (t
));
3016 /* Return, as a tree node, the number of elements for TYPE (which is an
3017 ARRAY_TYPE) minus one. This counts only elements of the top array. */
3020 array_type_nelts (const_tree type
)
3022 tree index_type
, min
, max
;
3024 /* If they did it with unspecified bounds, then we should have already
3025 given an error about it before we got here. */
3026 if (! TYPE_DOMAIN (type
))
3027 return error_mark_node
;
3029 index_type
= TYPE_DOMAIN (type
);
3030 min
= TYPE_MIN_VALUE (index_type
);
3031 max
= TYPE_MAX_VALUE (index_type
);
3033 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3035 return error_mark_node
;
3037 return (integer_zerop (min
)
3039 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
3042 /* If arg is static -- a reference to an object in static storage -- then
3043 return the object. This is not the same as the C meaning of `static'.
3044 If arg isn't static, return NULL. */
3049 switch (TREE_CODE (arg
))
3052 /* Nested functions are static, even though taking their address will
3053 involve a trampoline as we unnest the nested function and create
3054 the trampoline on the tree level. */
3058 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3059 && ! DECL_THREAD_LOCAL_P (arg
)
3060 && ! DECL_DLLIMPORT_P (arg
)
3064 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3068 return TREE_STATIC (arg
) ? arg
: NULL
;
3075 /* If the thing being referenced is not a field, then it is
3076 something language specific. */
3077 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
3079 /* If we are referencing a bitfield, we can't evaluate an
3080 ADDR_EXPR at compile time and so it isn't a constant. */
3081 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
3084 return staticp (TREE_OPERAND (arg
, 0));
3090 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
3093 case ARRAY_RANGE_REF
:
3094 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
3095 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
3096 return staticp (TREE_OPERAND (arg
, 0));
3100 case COMPOUND_LITERAL_EXPR
:
3101 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
3111 /* Return whether OP is a DECL whose address is function-invariant. */
3114 decl_address_invariant_p (const_tree op
)
3116 /* The conditions below are slightly less strict than the one in
3119 switch (TREE_CODE (op
))
3128 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3129 || DECL_THREAD_LOCAL_P (op
)
3130 || DECL_CONTEXT (op
) == current_function_decl
3131 || decl_function_context (op
) == current_function_decl
)
3136 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3137 || decl_function_context (op
) == current_function_decl
)
3148 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3151 decl_address_ip_invariant_p (const_tree op
)
3153 /* The conditions below are slightly less strict than the one in
3156 switch (TREE_CODE (op
))
3164 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3165 && !DECL_DLLIMPORT_P (op
))
3166 || DECL_THREAD_LOCAL_P (op
))
3171 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
3183 /* Return true if T is function-invariant (internal function, does
3184 not handle arithmetic; that's handled in skip_simple_arithmetic and
3185 tree_invariant_p). */
3187 static bool tree_invariant_p (tree t
);
3190 tree_invariant_p_1 (tree t
)
3194 if (TREE_CONSTANT (t
)
3195 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
3198 switch (TREE_CODE (t
))
3204 op
= TREE_OPERAND (t
, 0);
3205 while (handled_component_p (op
))
3207 switch (TREE_CODE (op
))
3210 case ARRAY_RANGE_REF
:
3211 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
3212 || TREE_OPERAND (op
, 2) != NULL_TREE
3213 || TREE_OPERAND (op
, 3) != NULL_TREE
)
3218 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
3224 op
= TREE_OPERAND (op
, 0);
3227 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
3236 /* Return true if T is function-invariant. */
3239 tree_invariant_p (tree t
)
3241 tree inner
= skip_simple_arithmetic (t
);
3242 return tree_invariant_p_1 (inner
);
3245 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
3246 Do this to any expression which may be used in more than one place,
3247 but must be evaluated only once.
3249 Normally, expand_expr would reevaluate the expression each time.
3250 Calling save_expr produces something that is evaluated and recorded
3251 the first time expand_expr is called on it. Subsequent calls to
3252 expand_expr just reuse the recorded value.
3254 The call to expand_expr that generates code that actually computes
3255 the value is the first call *at compile time*. Subsequent calls
3256 *at compile time* generate code to use the saved value.
3257 This produces correct result provided that *at run time* control
3258 always flows through the insns made by the first expand_expr
3259 before reaching the other places where the save_expr was evaluated.
3260 You, the caller of save_expr, must make sure this is so.
3262 Constants, and certain read-only nodes, are returned with no
3263 SAVE_EXPR because that is safe. Expressions containing placeholders
3264 are not touched; see tree.def for an explanation of what these
3268 save_expr (tree expr
)
3270 tree t
= fold (expr
);
3273 /* If the tree evaluates to a constant, then we don't want to hide that
3274 fact (i.e. this allows further folding, and direct checks for constants).
3275 However, a read-only object that has side effects cannot be bypassed.
3276 Since it is no problem to reevaluate literals, we just return the
3278 inner
= skip_simple_arithmetic (t
);
3279 if (TREE_CODE (inner
) == ERROR_MARK
)
3282 if (tree_invariant_p_1 (inner
))
3285 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
3286 it means that the size or offset of some field of an object depends on
3287 the value within another field.
3289 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
3290 and some variable since it would then need to be both evaluated once and
3291 evaluated more than once. Front-ends must assure this case cannot
3292 happen by surrounding any such subexpressions in their own SAVE_EXPR
3293 and forcing evaluation at the proper time. */
3294 if (contains_placeholder_p (inner
))
3297 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
3298 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
3300 /* This expression might be placed ahead of a jump to ensure that the
3301 value was computed on both sides of the jump. So make sure it isn't
3302 eliminated as dead. */
3303 TREE_SIDE_EFFECTS (t
) = 1;
3307 /* Look inside EXPR into any simple arithmetic operations. Return the
3308 outermost non-arithmetic or non-invariant node. */
3311 skip_simple_arithmetic (tree expr
)
3313 /* We don't care about whether this can be used as an lvalue in this
3315 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3316 expr
= TREE_OPERAND (expr
, 0);
3318 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3319 a constant, it will be more efficient to not make another SAVE_EXPR since
3320 it will allow better simplification and GCSE will be able to merge the
3321 computations if they actually occur. */
3324 if (UNARY_CLASS_P (expr
))
3325 expr
= TREE_OPERAND (expr
, 0);
3326 else if (BINARY_CLASS_P (expr
))
3328 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
3329 expr
= TREE_OPERAND (expr
, 0);
3330 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
3331 expr
= TREE_OPERAND (expr
, 1);
3342 /* Look inside EXPR into simple arithmetic operations involving constants.
3343 Return the outermost non-arithmetic or non-constant node. */
3346 skip_simple_constant_arithmetic (tree expr
)
3348 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3349 expr
= TREE_OPERAND (expr
, 0);
3353 if (UNARY_CLASS_P (expr
))
3354 expr
= TREE_OPERAND (expr
, 0);
3355 else if (BINARY_CLASS_P (expr
))
3357 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
3358 expr
= TREE_OPERAND (expr
, 0);
3359 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3360 expr
= TREE_OPERAND (expr
, 1);
3371 /* Return which tree structure is used by T. */
3373 enum tree_node_structure_enum
3374 tree_node_structure (const_tree t
)
3376 const enum tree_code code
= TREE_CODE (t
);
3377 return tree_node_structure_for_code (code
);
3380 /* Set various status flags when building a CALL_EXPR object T. */
3383 process_call_operands (tree t
)
3385 bool side_effects
= TREE_SIDE_EFFECTS (t
);
3386 bool read_only
= false;
3387 int i
= call_expr_flags (t
);
3389 /* Calls have side-effects, except those to const or pure functions. */
3390 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
3391 side_effects
= true;
3392 /* Propagate TREE_READONLY of arguments for const functions. */
3396 if (!side_effects
|| read_only
)
3397 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3399 tree op
= TREE_OPERAND (t
, i
);
3400 if (op
&& TREE_SIDE_EFFECTS (op
))
3401 side_effects
= true;
3402 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3406 TREE_SIDE_EFFECTS (t
) = side_effects
;
3407 TREE_READONLY (t
) = read_only
;
3410 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3411 size or offset that depends on a field within a record. */
3414 contains_placeholder_p (const_tree exp
)
3416 enum tree_code code
;
3421 code
= TREE_CODE (exp
);
3422 if (code
== PLACEHOLDER_EXPR
)
3425 switch (TREE_CODE_CLASS (code
))
3428 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3429 position computations since they will be converted into a
3430 WITH_RECORD_EXPR involving the reference, which will assume
3431 here will be valid. */
3432 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3434 case tcc_exceptional
:
3435 if (code
== TREE_LIST
)
3436 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3437 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3442 case tcc_comparison
:
3443 case tcc_expression
:
3447 /* Ignoring the first operand isn't quite right, but works best. */
3448 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
3451 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3452 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
3453 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
3456 /* The save_expr function never wraps anything containing
3457 a PLACEHOLDER_EXPR. */
3464 switch (TREE_CODE_LENGTH (code
))
3467 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3469 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3470 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
3481 const_call_expr_arg_iterator iter
;
3482 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
3483 if (CONTAINS_PLACEHOLDER_P (arg
))
3497 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3498 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3502 type_contains_placeholder_1 (const_tree type
)
3504 /* If the size contains a placeholder or the parent type (component type in
3505 the case of arrays) type involves a placeholder, this type does. */
3506 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
3507 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
3508 || (!POINTER_TYPE_P (type
)
3510 && type_contains_placeholder_p (TREE_TYPE (type
))))
3513 /* Now do type-specific checks. Note that the last part of the check above
3514 greatly limits what we have to do below. */
3515 switch (TREE_CODE (type
))
3518 case POINTER_BOUNDS_TYPE
:
3524 case REFERENCE_TYPE
:
3533 case FIXED_POINT_TYPE
:
3534 /* Here we just check the bounds. */
3535 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
3536 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
3539 /* We have already checked the component type above, so just check the
3541 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
3545 case QUAL_UNION_TYPE
:
3549 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
3550 if (TREE_CODE (field
) == FIELD_DECL
3551 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
3552 || (TREE_CODE (type
) == QUAL_UNION_TYPE
3553 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
3554 || type_contains_placeholder_p (TREE_TYPE (field
))))
3565 /* Wrapper around above function used to cache its result. */
3568 type_contains_placeholder_p (tree type
)
3572 /* If the contains_placeholder_bits field has been initialized,
3573 then we know the answer. */
3574 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
3575 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
3577 /* Indicate that we've seen this type node, and the answer is false.
3578 This is what we want to return if we run into recursion via fields. */
3579 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
3581 /* Compute the real value. */
3582 result
= type_contains_placeholder_1 (type
);
3584 /* Store the real value. */
3585 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
3590 /* Push tree EXP onto vector QUEUE if it is not already present. */
3593 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
3598 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
3599 if (simple_cst_equal (iter
, exp
) == 1)
3603 queue
->safe_push (exp
);
3606 /* Given a tree EXP, find all occurrences of references to fields
3607 in a PLACEHOLDER_EXPR and place them in vector REFS without
3608 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3609 we assume here that EXP contains only arithmetic expressions
3610 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3614 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
3616 enum tree_code code
= TREE_CODE (exp
);
3620 /* We handle TREE_LIST and COMPONENT_REF separately. */
3621 if (code
== TREE_LIST
)
3623 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3624 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3626 else if (code
== COMPONENT_REF
)
3628 for (inner
= TREE_OPERAND (exp
, 0);
3629 REFERENCE_CLASS_P (inner
);
3630 inner
= TREE_OPERAND (inner
, 0))
3633 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3634 push_without_duplicates (exp
, refs
);
3636 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3639 switch (TREE_CODE_CLASS (code
))
3644 case tcc_declaration
:
3645 /* Variables allocated to static storage can stay. */
3646 if (!TREE_STATIC (exp
))
3647 push_without_duplicates (exp
, refs
);
3650 case tcc_expression
:
3651 /* This is the pattern built in ada/make_aligning_type. */
3652 if (code
== ADDR_EXPR
3653 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3655 push_without_duplicates (exp
, refs
);
3659 /* Fall through... */
3661 case tcc_exceptional
:
3664 case tcc_comparison
:
3666 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3667 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3671 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3672 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3680 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3681 return a tree with all occurrences of references to F in a
3682 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3683 CONST_DECLs. Note that we assume here that EXP contains only
3684 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3685 occurring only in their argument list. */
3688 substitute_in_expr (tree exp
, tree f
, tree r
)
3690 enum tree_code code
= TREE_CODE (exp
);
3691 tree op0
, op1
, op2
, op3
;
3694 /* We handle TREE_LIST and COMPONENT_REF separately. */
3695 if (code
== TREE_LIST
)
3697 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3698 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3699 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3702 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3704 else if (code
== COMPONENT_REF
)
3708 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3709 and it is the right field, replace it with R. */
3710 for (inner
= TREE_OPERAND (exp
, 0);
3711 REFERENCE_CLASS_P (inner
);
3712 inner
= TREE_OPERAND (inner
, 0))
3716 op1
= TREE_OPERAND (exp
, 1);
3718 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3721 /* If this expression hasn't been completed let, leave it alone. */
3722 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3725 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3726 if (op0
== TREE_OPERAND (exp
, 0))
3730 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3733 switch (TREE_CODE_CLASS (code
))
3738 case tcc_declaration
:
3744 case tcc_expression
:
3748 /* Fall through... */
3750 case tcc_exceptional
:
3753 case tcc_comparison
:
3755 switch (TREE_CODE_LENGTH (code
))
3761 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3762 if (op0
== TREE_OPERAND (exp
, 0))
3765 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3769 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3770 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3772 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3775 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3779 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3780 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3781 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3783 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3784 && op2
== TREE_OPERAND (exp
, 2))
3787 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3791 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3792 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3793 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3794 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3796 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3797 && op2
== TREE_OPERAND (exp
, 2)
3798 && op3
== TREE_OPERAND (exp
, 3))
3802 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3814 new_tree
= NULL_TREE
;
3816 /* If we are trying to replace F with a constant, inline back
3817 functions which do nothing else than computing a value from
3818 the arguments they are passed. This makes it possible to
3819 fold partially or entirely the replacement expression. */
3820 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3822 tree t
= maybe_inline_call_in_expr (exp
);
3824 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3827 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3829 tree op
= TREE_OPERAND (exp
, i
);
3830 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3834 new_tree
= copy_node (exp
);
3835 TREE_OPERAND (new_tree
, i
) = new_op
;
3841 new_tree
= fold (new_tree
);
3842 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3843 process_call_operands (new_tree
);
3854 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3856 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3857 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3862 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3863 for it within OBJ, a tree that is an object or a chain of references. */
3866 substitute_placeholder_in_expr (tree exp
, tree obj
)
3868 enum tree_code code
= TREE_CODE (exp
);
3869 tree op0
, op1
, op2
, op3
;
3872 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3873 in the chain of OBJ. */
3874 if (code
== PLACEHOLDER_EXPR
)
3876 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3879 for (elt
= obj
; elt
!= 0;
3880 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3881 || TREE_CODE (elt
) == COND_EXPR
)
3882 ? TREE_OPERAND (elt
, 1)
3883 : (REFERENCE_CLASS_P (elt
)
3884 || UNARY_CLASS_P (elt
)
3885 || BINARY_CLASS_P (elt
)
3886 || VL_EXP_CLASS_P (elt
)
3887 || EXPRESSION_CLASS_P (elt
))
3888 ? TREE_OPERAND (elt
, 0) : 0))
3889 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3892 for (elt
= obj
; elt
!= 0;
3893 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3894 || TREE_CODE (elt
) == COND_EXPR
)
3895 ? TREE_OPERAND (elt
, 1)
3896 : (REFERENCE_CLASS_P (elt
)
3897 || UNARY_CLASS_P (elt
)
3898 || BINARY_CLASS_P (elt
)
3899 || VL_EXP_CLASS_P (elt
)
3900 || EXPRESSION_CLASS_P (elt
))
3901 ? TREE_OPERAND (elt
, 0) : 0))
3902 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3903 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3905 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3907 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3908 survives until RTL generation, there will be an error. */
3912 /* TREE_LIST is special because we need to look at TREE_VALUE
3913 and TREE_CHAIN, not TREE_OPERANDS. */
3914 else if (code
== TREE_LIST
)
3916 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3917 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3918 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3921 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3924 switch (TREE_CODE_CLASS (code
))
3927 case tcc_declaration
:
3930 case tcc_exceptional
:
3933 case tcc_comparison
:
3934 case tcc_expression
:
3937 switch (TREE_CODE_LENGTH (code
))
3943 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3944 if (op0
== TREE_OPERAND (exp
, 0))
3947 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3951 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3952 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3954 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3957 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3961 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3962 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3963 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3965 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3966 && op2
== TREE_OPERAND (exp
, 2))
3969 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3973 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3974 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3975 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3976 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3978 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3979 && op2
== TREE_OPERAND (exp
, 2)
3980 && op3
== TREE_OPERAND (exp
, 3))
3984 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3996 new_tree
= NULL_TREE
;
3998 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4000 tree op
= TREE_OPERAND (exp
, i
);
4001 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
4005 new_tree
= copy_node (exp
);
4006 TREE_OPERAND (new_tree
, i
) = new_op
;
4012 new_tree
= fold (new_tree
);
4013 if (TREE_CODE (new_tree
) == CALL_EXPR
)
4014 process_call_operands (new_tree
);
4025 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
4027 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
4028 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
4034 /* Subroutine of stabilize_reference; this is called for subtrees of
4035 references. Any expression with side-effects must be put in a SAVE_EXPR
4036 to ensure that it is only evaluated once.
4038 We don't put SAVE_EXPR nodes around everything, because assigning very
4039 simple expressions to temporaries causes us to miss good opportunities
4040 for optimizations. Among other things, the opportunity to fold in the
4041 addition of a constant into an addressing mode often gets lost, e.g.
4042 "y[i+1] += x;". In general, we take the approach that we should not make
4043 an assignment unless we are forced into it - i.e., that any non-side effect
4044 operator should be allowed, and that cse should take care of coalescing
4045 multiple utterances of the same expression should that prove fruitful. */
4048 stabilize_reference_1 (tree e
)
4051 enum tree_code code
= TREE_CODE (e
);
4053 /* We cannot ignore const expressions because it might be a reference
4054 to a const array but whose index contains side-effects. But we can
4055 ignore things that are actual constant or that already have been
4056 handled by this function. */
4058 if (tree_invariant_p (e
))
4061 switch (TREE_CODE_CLASS (code
))
4063 case tcc_exceptional
:
4065 case tcc_declaration
:
4066 case tcc_comparison
:
4068 case tcc_expression
:
4071 /* If the expression has side-effects, then encase it in a SAVE_EXPR
4072 so that it will only be evaluated once. */
4073 /* The reference (r) and comparison (<) classes could be handled as
4074 below, but it is generally faster to only evaluate them once. */
4075 if (TREE_SIDE_EFFECTS (e
))
4076 return save_expr (e
);
4080 /* Constants need no processing. In fact, we should never reach
4085 /* Division is slow and tends to be compiled with jumps,
4086 especially the division by powers of 2 that is often
4087 found inside of an array reference. So do it just once. */
4088 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
4089 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
4090 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
4091 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
4092 return save_expr (e
);
4093 /* Recursively stabilize each operand. */
4094 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
4095 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
4099 /* Recursively stabilize each operand. */
4100 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
4107 TREE_TYPE (result
) = TREE_TYPE (e
);
4108 TREE_READONLY (result
) = TREE_READONLY (e
);
4109 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
4110 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
4115 /* Stabilize a reference so that we can use it any number of times
4116 without causing its operands to be evaluated more than once.
4117 Returns the stabilized reference. This works by means of save_expr,
4118 so see the caveats in the comments about save_expr.
4120 Also allows conversion expressions whose operands are references.
4121 Any other kind of expression is returned unchanged. */
4124 stabilize_reference (tree ref
)
4127 enum tree_code code
= TREE_CODE (ref
);
4134 /* No action is needed in this case. */
4139 case FIX_TRUNC_EXPR
:
4140 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
4144 result
= build_nt (INDIRECT_REF
,
4145 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
4149 result
= build_nt (COMPONENT_REF
,
4150 stabilize_reference (TREE_OPERAND (ref
, 0)),
4151 TREE_OPERAND (ref
, 1), NULL_TREE
);
4155 result
= build_nt (BIT_FIELD_REF
,
4156 stabilize_reference (TREE_OPERAND (ref
, 0)),
4157 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
4161 result
= build_nt (ARRAY_REF
,
4162 stabilize_reference (TREE_OPERAND (ref
, 0)),
4163 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4164 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4167 case ARRAY_RANGE_REF
:
4168 result
= build_nt (ARRAY_RANGE_REF
,
4169 stabilize_reference (TREE_OPERAND (ref
, 0)),
4170 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4171 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4175 /* We cannot wrap the first expression in a SAVE_EXPR, as then
4176 it wouldn't be ignored. This matters when dealing with
4178 return stabilize_reference_1 (ref
);
4180 /* If arg isn't a kind of lvalue we recognize, make no change.
4181 Caller should recognize the error for an invalid lvalue. */
4186 return error_mark_node
;
4189 TREE_TYPE (result
) = TREE_TYPE (ref
);
4190 TREE_READONLY (result
) = TREE_READONLY (ref
);
4191 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
4192 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
4197 /* Low-level constructors for expressions. */
4199 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
4200 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
4203 recompute_tree_invariant_for_addr_expr (tree t
)
4206 bool tc
= true, se
= false;
4208 /* We started out assuming this address is both invariant and constant, but
4209 does not have side effects. Now go down any handled components and see if
4210 any of them involve offsets that are either non-constant or non-invariant.
4211 Also check for side-effects.
4213 ??? Note that this code makes no attempt to deal with the case where
4214 taking the address of something causes a copy due to misalignment. */
4216 #define UPDATE_FLAGS(NODE) \
4217 do { tree _node = (NODE); \
4218 if (_node && !TREE_CONSTANT (_node)) tc = false; \
4219 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
4221 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
4222 node
= TREE_OPERAND (node
, 0))
4224 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
4225 array reference (probably made temporarily by the G++ front end),
4226 so ignore all the operands. */
4227 if ((TREE_CODE (node
) == ARRAY_REF
4228 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
4229 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
4231 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
4232 if (TREE_OPERAND (node
, 2))
4233 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4234 if (TREE_OPERAND (node
, 3))
4235 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
4237 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
4238 FIELD_DECL, apparently. The G++ front end can put something else
4239 there, at least temporarily. */
4240 else if (TREE_CODE (node
) == COMPONENT_REF
4241 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
4243 if (TREE_OPERAND (node
, 2))
4244 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4248 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
4250 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
4251 the address, since &(*a)->b is a form of addition. If it's a constant, the
4252 address is constant too. If it's a decl, its address is constant if the
4253 decl is static. Everything else is not constant and, furthermore,
4254 taking the address of a volatile variable is not volatile. */
4255 if (TREE_CODE (node
) == INDIRECT_REF
4256 || TREE_CODE (node
) == MEM_REF
)
4257 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
4258 else if (CONSTANT_CLASS_P (node
))
4260 else if (DECL_P (node
))
4261 tc
&= (staticp (node
) != NULL_TREE
);
4265 se
|= TREE_SIDE_EFFECTS (node
);
4269 TREE_CONSTANT (t
) = tc
;
4270 TREE_SIDE_EFFECTS (t
) = se
;
4274 /* Build an expression of code CODE, data type TYPE, and operands as
4275 specified. Expressions and reference nodes can be created this way.
4276 Constants, decls, types and misc nodes cannot be.
4278 We define 5 non-variadic functions, from 0 to 4 arguments. This is
4279 enough for all extant tree codes. */
4282 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
4286 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
4288 t
= make_node_stat (code PASS_MEM_STAT
);
4295 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
4297 int length
= sizeof (struct tree_exp
);
4300 record_node_allocation_statistics (code
, length
);
4302 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
4304 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
4306 memset (t
, 0, sizeof (struct tree_common
));
4308 TREE_SET_CODE (t
, code
);
4310 TREE_TYPE (t
) = type
;
4311 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
4312 TREE_OPERAND (t
, 0) = node
;
4313 if (node
&& !TYPE_P (node
))
4315 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
4316 TREE_READONLY (t
) = TREE_READONLY (node
);
4319 if (TREE_CODE_CLASS (code
) == tcc_statement
)
4320 TREE_SIDE_EFFECTS (t
) = 1;
4324 /* All of these have side-effects, no matter what their
4326 TREE_SIDE_EFFECTS (t
) = 1;
4327 TREE_READONLY (t
) = 0;
4331 /* Whether a dereference is readonly has nothing to do with whether
4332 its operand is readonly. */
4333 TREE_READONLY (t
) = 0;
4338 recompute_tree_invariant_for_addr_expr (t
);
4342 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
4343 && node
&& !TYPE_P (node
)
4344 && TREE_CONSTANT (node
))
4345 TREE_CONSTANT (t
) = 1;
4346 if (TREE_CODE_CLASS (code
) == tcc_reference
4347 && node
&& TREE_THIS_VOLATILE (node
))
4348 TREE_THIS_VOLATILE (t
) = 1;
4355 #define PROCESS_ARG(N) \
4357 TREE_OPERAND (t, N) = arg##N; \
4358 if (arg##N &&!TYPE_P (arg##N)) \
4360 if (TREE_SIDE_EFFECTS (arg##N)) \
4362 if (!TREE_READONLY (arg##N) \
4363 && !CONSTANT_CLASS_P (arg##N)) \
4364 (void) (read_only = 0); \
4365 if (!TREE_CONSTANT (arg##N)) \
4366 (void) (constant = 0); \
4371 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
4373 bool constant
, read_only
, side_effects
;
4376 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
4378 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
4379 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
4380 /* When sizetype precision doesn't match that of pointers
4381 we need to be able to build explicit extensions or truncations
4382 of the offset argument. */
4383 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
4384 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
4385 && TREE_CODE (arg1
) == INTEGER_CST
);
4387 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4388 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4389 && ptrofftype_p (TREE_TYPE (arg1
)));
4391 t
= make_node_stat (code PASS_MEM_STAT
);
4394 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4395 result based on those same flags for the arguments. But if the
4396 arguments aren't really even `tree' expressions, we shouldn't be trying
4399 /* Expressions without side effects may be constant if their
4400 arguments are as well. */
4401 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4402 || TREE_CODE_CLASS (code
) == tcc_binary
);
4404 side_effects
= TREE_SIDE_EFFECTS (t
);
4409 TREE_SIDE_EFFECTS (t
) = side_effects
;
4410 if (code
== MEM_REF
)
4412 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
4414 tree o
= TREE_OPERAND (arg0
, 0);
4415 TREE_READONLY (t
) = TREE_READONLY (o
);
4416 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
4421 TREE_READONLY (t
) = read_only
;
4422 TREE_CONSTANT (t
) = constant
;
4423 TREE_THIS_VOLATILE (t
)
4424 = (TREE_CODE_CLASS (code
) == tcc_reference
4425 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4433 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4434 tree arg2 MEM_STAT_DECL
)
4436 bool constant
, read_only
, side_effects
;
4439 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
4440 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4442 t
= make_node_stat (code PASS_MEM_STAT
);
4447 /* As a special exception, if COND_EXPR has NULL branches, we
4448 assume that it is a gimple statement and always consider
4449 it to have side effects. */
4450 if (code
== COND_EXPR
4451 && tt
== void_type_node
4452 && arg1
== NULL_TREE
4453 && arg2
== NULL_TREE
)
4454 side_effects
= true;
4456 side_effects
= TREE_SIDE_EFFECTS (t
);
4462 if (code
== COND_EXPR
)
4463 TREE_READONLY (t
) = read_only
;
4465 TREE_SIDE_EFFECTS (t
) = side_effects
;
4466 TREE_THIS_VOLATILE (t
)
4467 = (TREE_CODE_CLASS (code
) == tcc_reference
4468 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4474 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4475 tree arg2
, tree arg3 MEM_STAT_DECL
)
4477 bool constant
, read_only
, side_effects
;
4480 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
4482 t
= make_node_stat (code PASS_MEM_STAT
);
4485 side_effects
= TREE_SIDE_EFFECTS (t
);
4492 TREE_SIDE_EFFECTS (t
) = side_effects
;
4493 TREE_THIS_VOLATILE (t
)
4494 = (TREE_CODE_CLASS (code
) == tcc_reference
4495 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4501 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4502 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
4504 bool constant
, read_only
, side_effects
;
4507 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
4509 t
= make_node_stat (code PASS_MEM_STAT
);
4512 side_effects
= TREE_SIDE_EFFECTS (t
);
4520 TREE_SIDE_EFFECTS (t
) = side_effects
;
4521 if (code
== TARGET_MEM_REF
)
4523 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
4525 tree o
= TREE_OPERAND (arg0
, 0);
4526 TREE_READONLY (t
) = TREE_READONLY (o
);
4527 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
4531 TREE_THIS_VOLATILE (t
)
4532 = (TREE_CODE_CLASS (code
) == tcc_reference
4533 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4538 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4539 on the pointer PTR. */
4542 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
4544 HOST_WIDE_INT offset
= 0;
4545 tree ptype
= TREE_TYPE (ptr
);
4547 /* For convenience allow addresses that collapse to a simple base
4549 if (TREE_CODE (ptr
) == ADDR_EXPR
4550 && (handled_component_p (TREE_OPERAND (ptr
, 0))
4551 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
4553 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
4555 ptr
= build_fold_addr_expr (ptr
);
4556 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
4558 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
4559 ptr
, build_int_cst (ptype
, offset
));
4560 SET_EXPR_LOCATION (tem
, loc
);
4564 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4567 mem_ref_offset (const_tree t
)
4569 return offset_int::from (TREE_OPERAND (t
, 1), SIGNED
);
4572 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4573 offsetted by OFFSET units. */
4576 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4578 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4579 build_fold_addr_expr (base
),
4580 build_int_cst (ptr_type_node
, offset
));
4581 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4582 recompute_tree_invariant_for_addr_expr (addr
);
4586 /* Similar except don't specify the TREE_TYPE
4587 and leave the TREE_SIDE_EFFECTS as 0.
4588 It is permissible for arguments to be null,
4589 or even garbage if their values do not matter. */
4592 build_nt (enum tree_code code
, ...)
4599 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4603 t
= make_node (code
);
4604 length
= TREE_CODE_LENGTH (code
);
4606 for (i
= 0; i
< length
; i
++)
4607 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4613 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4617 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
4622 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
4623 CALL_EXPR_FN (ret
) = fn
;
4624 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4625 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
4626 CALL_EXPR_ARG (ret
, ix
) = t
;
4630 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4631 We do NOT enter this node in any sort of symbol table.
4633 LOC is the location of the decl.
4635 layout_decl is used to set up the decl's storage layout.
4636 Other slots are initialized to 0 or null pointers. */
4639 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4640 tree type MEM_STAT_DECL
)
4644 t
= make_node_stat (code PASS_MEM_STAT
);
4645 DECL_SOURCE_LOCATION (t
) = loc
;
4647 /* if (type == error_mark_node)
4648 type = integer_type_node; */
4649 /* That is not done, deliberately, so that having error_mark_node
4650 as the type can suppress useless errors in the use of this variable. */
4652 DECL_NAME (t
) = name
;
4653 TREE_TYPE (t
) = type
;
4655 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4661 /* Builds and returns function declaration with NAME and TYPE. */
4664 build_fn_decl (const char *name
, tree type
)
4666 tree id
= get_identifier (name
);
4667 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4669 DECL_EXTERNAL (decl
) = 1;
4670 TREE_PUBLIC (decl
) = 1;
4671 DECL_ARTIFICIAL (decl
) = 1;
4672 TREE_NOTHROW (decl
) = 1;
4677 vec
<tree
, va_gc
> *all_translation_units
;
4679 /* Builds a new translation-unit decl with name NAME, queues it in the
4680 global list of translation-unit decls and returns it. */
4683 build_translation_unit_decl (tree name
)
4685 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4687 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4688 vec_safe_push (all_translation_units
, tu
);
4693 /* BLOCK nodes are used to represent the structure of binding contours
4694 and declarations, once those contours have been exited and their contents
4695 compiled. This information is used for outputting debugging info. */
4698 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4700 tree block
= make_node (BLOCK
);
4702 BLOCK_VARS (block
) = vars
;
4703 BLOCK_SUBBLOCKS (block
) = subblocks
;
4704 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4705 BLOCK_CHAIN (block
) = chain
;
4710 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4712 LOC is the location to use in tree T. */
4715 protected_set_expr_location (tree t
, location_t loc
)
4717 if (CAN_HAVE_LOCATION_P (t
))
4718 SET_EXPR_LOCATION (t
, loc
);
4721 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4725 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4727 DECL_ATTRIBUTES (ddecl
) = attribute
;
4731 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4732 is ATTRIBUTE and its qualifiers are QUALS.
4734 Record such modified types already made so we don't make duplicates. */
4737 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4739 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4741 inchash::hash hstate
;
4745 enum tree_code code
= TREE_CODE (ttype
);
4747 /* Building a distinct copy of a tagged type is inappropriate; it
4748 causes breakage in code that expects there to be a one-to-one
4749 relationship between a struct and its fields.
4750 build_duplicate_type is another solution (as used in
4751 handle_transparent_union_attribute), but that doesn't play well
4752 with the stronger C++ type identity model. */
4753 if (TREE_CODE (ttype
) == RECORD_TYPE
4754 || TREE_CODE (ttype
) == UNION_TYPE
4755 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4756 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4758 warning (OPT_Wattributes
,
4759 "ignoring attributes applied to %qT after definition",
4760 TYPE_MAIN_VARIANT (ttype
));
4761 return build_qualified_type (ttype
, quals
);
4764 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4765 ntype
= build_distinct_type_copy (ttype
);
4767 TYPE_ATTRIBUTES (ntype
) = attribute
;
4769 hstate
.add_int (code
);
4770 if (TREE_TYPE (ntype
))
4771 hstate
.add_object (TYPE_HASH (TREE_TYPE (ntype
)));
4772 attribute_hash_list (attribute
, hstate
);
4774 switch (TREE_CODE (ntype
))
4777 type_hash_list (TYPE_ARG_TYPES (ntype
), hstate
);
4780 if (TYPE_DOMAIN (ntype
))
4781 hstate
.add_object (TYPE_HASH (TYPE_DOMAIN (ntype
)));
4784 t
= TYPE_MAX_VALUE (ntype
);
4785 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
4786 hstate
.add_object (TREE_INT_CST_ELT (t
, i
));
4789 case FIXED_POINT_TYPE
:
4791 unsigned int precision
= TYPE_PRECISION (ntype
);
4792 hstate
.add_object (precision
);
4799 ntype
= type_hash_canon (hstate
.end(), ntype
);
4801 /* If the target-dependent attributes make NTYPE different from
4802 its canonical type, we will need to use structural equality
4803 checks for this type. */
4804 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4805 || !comp_type_attributes (ntype
, ttype
))
4806 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4807 else if (TYPE_CANONICAL (ntype
) == ntype
)
4808 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4810 ttype
= build_qualified_type (ntype
, quals
);
4812 else if (TYPE_QUALS (ttype
) != quals
)
4813 ttype
= build_qualified_type (ttype
, quals
);
4818 /* Check if "omp declare simd" attribute arguments, CLAUSES1 and CLAUSES2, are
4822 omp_declare_simd_clauses_equal (tree clauses1
, tree clauses2
)
4825 for (cl1
= clauses1
, cl2
= clauses2
;
4827 cl1
= OMP_CLAUSE_CHAIN (cl1
), cl2
= OMP_CLAUSE_CHAIN (cl2
))
4829 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_CODE (cl2
))
4831 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_SIMDLEN
)
4833 if (simple_cst_equal (OMP_CLAUSE_DECL (cl1
),
4834 OMP_CLAUSE_DECL (cl2
)) != 1)
4837 switch (OMP_CLAUSE_CODE (cl1
))
4839 case OMP_CLAUSE_ALIGNED
:
4840 if (simple_cst_equal (OMP_CLAUSE_ALIGNED_ALIGNMENT (cl1
),
4841 OMP_CLAUSE_ALIGNED_ALIGNMENT (cl2
)) != 1)
4844 case OMP_CLAUSE_LINEAR
:
4845 if (simple_cst_equal (OMP_CLAUSE_LINEAR_STEP (cl1
),
4846 OMP_CLAUSE_LINEAR_STEP (cl2
)) != 1)
4849 case OMP_CLAUSE_SIMDLEN
:
4850 if (simple_cst_equal (OMP_CLAUSE_SIMDLEN_EXPR (cl1
),
4851 OMP_CLAUSE_SIMDLEN_EXPR (cl2
)) != 1)
4860 /* Compare two constructor-element-type constants. Return 1 if the lists
4861 are known to be equal; otherwise return 0. */
4864 simple_cst_list_equal (const_tree l1
, const_tree l2
)
4866 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
4868 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
4871 l1
= TREE_CHAIN (l1
);
4872 l2
= TREE_CHAIN (l2
);
4878 /* Compare two identifier nodes representing attributes. Either one may
4879 be in wrapped __ATTR__ form. Return true if they are the same, false
4883 cmp_attrib_identifiers (const_tree attr1
, const_tree attr2
)
4885 /* Make sure we're dealing with IDENTIFIER_NODEs. */
4886 gcc_checking_assert (TREE_CODE (attr1
) == IDENTIFIER_NODE
4887 && TREE_CODE (attr2
) == IDENTIFIER_NODE
);
4889 /* Identifiers can be compared directly for equality. */
4893 /* If they are not equal, they may still be one in the form
4894 'text' while the other one is in the form '__text__'. TODO:
4895 If we were storing attributes in normalized 'text' form, then
4896 this could all go away and we could take full advantage of
4897 the fact that we're comparing identifiers. :-) */
4898 const size_t attr1_len
= IDENTIFIER_LENGTH (attr1
);
4899 const size_t attr2_len
= IDENTIFIER_LENGTH (attr2
);
4901 if (attr2_len
== attr1_len
+ 4)
4903 const char *p
= IDENTIFIER_POINTER (attr2
);
4904 const char *q
= IDENTIFIER_POINTER (attr1
);
4905 if (p
[0] == '_' && p
[1] == '_'
4906 && p
[attr2_len
- 2] == '_' && p
[attr2_len
- 1] == '_'
4907 && strncmp (q
, p
+ 2, attr1_len
) == 0)
4910 else if (attr2_len
+ 4 == attr1_len
)
4912 const char *p
= IDENTIFIER_POINTER (attr2
);
4913 const char *q
= IDENTIFIER_POINTER (attr1
);
4914 if (q
[0] == '_' && q
[1] == '_'
4915 && q
[attr1_len
- 2] == '_' && q
[attr1_len
- 1] == '_'
4916 && strncmp (q
+ 2, p
, attr2_len
) == 0)
4923 /* Compare two attributes for their value identity. Return true if the
4924 attribute values are known to be equal; otherwise return false. */
4927 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4929 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4932 if (TREE_VALUE (attr1
) != NULL_TREE
4933 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4934 && TREE_VALUE (attr2
) != NULL_TREE
4935 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4937 /* Handle attribute format. */
4938 if (is_attribute_p ("format", TREE_PURPOSE (attr1
)))
4940 attr1
= TREE_VALUE (attr1
);
4941 attr2
= TREE_VALUE (attr2
);
4942 /* Compare the archetypes (printf/scanf/strftime/...). */
4943 if (!cmp_attrib_identifiers (TREE_VALUE (attr1
),
4944 TREE_VALUE (attr2
)))
4946 /* Archetypes are the same. Compare the rest. */
4947 return (simple_cst_list_equal (TREE_CHAIN (attr1
),
4948 TREE_CHAIN (attr2
)) == 1);
4950 return (simple_cst_list_equal (TREE_VALUE (attr1
),
4951 TREE_VALUE (attr2
)) == 1);
4954 if ((flag_openmp
|| flag_openmp_simd
)
4955 && TREE_VALUE (attr1
) && TREE_VALUE (attr2
)
4956 && TREE_CODE (TREE_VALUE (attr1
)) == OMP_CLAUSE
4957 && TREE_CODE (TREE_VALUE (attr2
)) == OMP_CLAUSE
)
4958 return omp_declare_simd_clauses_equal (TREE_VALUE (attr1
),
4959 TREE_VALUE (attr2
));
4961 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
4964 /* Return 0 if the attributes for two types are incompatible, 1 if they
4965 are compatible, and 2 if they are nearly compatible (which causes a
4966 warning to be generated). */
4968 comp_type_attributes (const_tree type1
, const_tree type2
)
4970 const_tree a1
= TYPE_ATTRIBUTES (type1
);
4971 const_tree a2
= TYPE_ATTRIBUTES (type2
);
4976 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4978 const struct attribute_spec
*as
;
4981 as
= lookup_attribute_spec (get_attribute_name (a
));
4982 if (!as
|| as
->affects_type_identity
== false)
4985 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
4986 if (!attr
|| !attribute_value_equal (a
, attr
))
4991 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4993 const struct attribute_spec
*as
;
4995 as
= lookup_attribute_spec (get_attribute_name (a
));
4996 if (!as
|| as
->affects_type_identity
== false)
4999 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
5001 /* We don't need to compare trees again, as we did this
5002 already in first loop. */
5004 /* All types - affecting identity - are equal, so
5005 there is no need to call target hook for comparison. */
5009 /* As some type combinations - like default calling-convention - might
5010 be compatible, we have to call the target hook to get the final result. */
5011 return targetm
.comp_type_attributes (type1
, type2
);
5014 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
5017 Record such modified types already made so we don't make duplicates. */
5020 build_type_attribute_variant (tree ttype
, tree attribute
)
5022 return build_type_attribute_qual_variant (ttype
, attribute
,
5023 TYPE_QUALS (ttype
));
5027 /* Reset the expression *EXPR_P, a size or position.
5029 ??? We could reset all non-constant sizes or positions. But it's cheap
5030 enough to not do so and refrain from adding workarounds to dwarf2out.c.
5032 We need to reset self-referential sizes or positions because they cannot
5033 be gimplified and thus can contain a CALL_EXPR after the gimplification
5034 is finished, which will run afoul of LTO streaming. And they need to be
5035 reset to something essentially dummy but not constant, so as to preserve
5036 the properties of the object they are attached to. */
5039 free_lang_data_in_one_sizepos (tree
*expr_p
)
5041 tree expr
= *expr_p
;
5042 if (CONTAINS_PLACEHOLDER_P (expr
))
5043 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
5047 /* Reset all the fields in a binfo node BINFO. We only keep
5048 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
5051 free_lang_data_in_binfo (tree binfo
)
5056 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
5058 BINFO_VIRTUALS (binfo
) = NULL_TREE
;
5059 BINFO_BASE_ACCESSES (binfo
) = NULL
;
5060 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
5061 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
5063 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo
), i
, t
)
5064 free_lang_data_in_binfo (t
);
5068 /* Reset all language specific information still present in TYPE. */
5071 free_lang_data_in_type (tree type
)
5073 gcc_assert (TYPE_P (type
));
5075 /* Give the FE a chance to remove its own data first. */
5076 lang_hooks
.free_lang_data (type
);
5078 TREE_LANG_FLAG_0 (type
) = 0;
5079 TREE_LANG_FLAG_1 (type
) = 0;
5080 TREE_LANG_FLAG_2 (type
) = 0;
5081 TREE_LANG_FLAG_3 (type
) = 0;
5082 TREE_LANG_FLAG_4 (type
) = 0;
5083 TREE_LANG_FLAG_5 (type
) = 0;
5084 TREE_LANG_FLAG_6 (type
) = 0;
5086 if (TREE_CODE (type
) == FUNCTION_TYPE
)
5088 /* Remove the const and volatile qualifiers from arguments. The
5089 C++ front end removes them, but the C front end does not,
5090 leading to false ODR violation errors when merging two
5091 instances of the same function signature compiled by
5092 different front ends. */
5095 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
5097 tree arg_type
= TREE_VALUE (p
);
5099 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
5101 int quals
= TYPE_QUALS (arg_type
)
5103 & ~TYPE_QUAL_VOLATILE
;
5104 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
5105 free_lang_data_in_type (TREE_VALUE (p
));
5107 /* C++ FE uses TREE_PURPOSE to store initial values. */
5108 TREE_PURPOSE (p
) = NULL
;
5110 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
5111 TYPE_MINVAL (type
) = NULL
;
5113 if (TREE_CODE (type
) == METHOD_TYPE
)
5117 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
5119 /* C++ FE uses TREE_PURPOSE to store initial values. */
5120 TREE_PURPOSE (p
) = NULL
;
5122 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
5123 TYPE_MINVAL (type
) = NULL
;
5126 /* Remove members that are not actually FIELD_DECLs from the field
5127 list of an aggregate. These occur in C++. */
5128 if (RECORD_OR_UNION_TYPE_P (type
))
5132 /* Note that TYPE_FIELDS can be shared across distinct
5133 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
5134 to be removed, we cannot set its TREE_CHAIN to NULL.
5135 Otherwise, we would not be able to find all the other fields
5136 in the other instances of this TREE_TYPE.
5138 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
5140 member
= TYPE_FIELDS (type
);
5143 if (TREE_CODE (member
) == FIELD_DECL
5144 || TREE_CODE (member
) == TYPE_DECL
)
5147 TREE_CHAIN (prev
) = member
;
5149 TYPE_FIELDS (type
) = member
;
5153 member
= TREE_CHAIN (member
);
5157 TREE_CHAIN (prev
) = NULL_TREE
;
5159 TYPE_FIELDS (type
) = NULL_TREE
;
5161 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
5162 and danagle the pointer from time to time. */
5163 if (TYPE_VFIELD (type
) && TREE_CODE (TYPE_VFIELD (type
)) != FIELD_DECL
)
5164 TYPE_VFIELD (type
) = NULL_TREE
;
5166 /* Remove TYPE_METHODS list. While it would be nice to keep it
5167 to enable ODR warnings about different method lists, doing so
5168 seems to impractically increase size of LTO data streamed.
5169 Keep the infrmation if TYPE_METHODS was non-NULL. This is used
5170 by function.c and pretty printers. */
5171 if (TYPE_METHODS (type
))
5172 TYPE_METHODS (type
) = error_mark_node
;
5173 if (TYPE_BINFO (type
))
5175 free_lang_data_in_binfo (TYPE_BINFO (type
));
5176 /* We need to preserve link to bases and virtual table for all
5177 polymorphic types to make devirtualization machinery working.
5178 Debug output cares only about bases, but output also
5179 virtual table pointers so merging of -fdevirtualize and
5180 -fno-devirtualize units is easier. */
5181 if ((!BINFO_VTABLE (TYPE_BINFO (type
))
5182 || !flag_devirtualize
)
5183 && ((!BINFO_N_BASE_BINFOS (TYPE_BINFO (type
))
5184 && !BINFO_VTABLE (TYPE_BINFO (type
)))
5185 || debug_info_level
!= DINFO_LEVEL_NONE
))
5186 TYPE_BINFO (type
) = NULL
;
5191 /* For non-aggregate types, clear out the language slot (which
5192 overloads TYPE_BINFO). */
5193 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
5195 if (INTEGRAL_TYPE_P (type
)
5196 || SCALAR_FLOAT_TYPE_P (type
)
5197 || FIXED_POINT_TYPE_P (type
))
5199 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
5200 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
5204 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
5205 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
5207 if (TYPE_CONTEXT (type
)
5208 && TREE_CODE (TYPE_CONTEXT (type
)) == BLOCK
)
5210 tree ctx
= TYPE_CONTEXT (type
);
5213 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5215 while (ctx
&& TREE_CODE (ctx
) == BLOCK
);
5216 TYPE_CONTEXT (type
) = ctx
;
5221 /* Return true if DECL may need an assembler name to be set. */
5224 need_assembler_name_p (tree decl
)
5226 /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
5227 Rule merging. This makes type_odr_p to return true on those types during
5228 LTO and by comparing the mangled name, we can say what types are intended
5229 to be equivalent across compilation unit.
5231 We do not store names of type_in_anonymous_namespace_p.
5233 Record, union and enumeration type have linkage that allows use
5234 to check type_in_anonymous_namespace_p. We do not mangle compound types
5235 that always can be compared structurally.
5237 Similarly for builtin types, we compare properties of their main variant.
5238 A special case are integer types where mangling do make differences
5239 between char/signed char/unsigned char etc. Storing name for these makes
5240 e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
5241 See cp/mangle.c:write_builtin_type for details. */
5243 if (flag_lto_odr_type_mering
5244 && TREE_CODE (decl
) == TYPE_DECL
5246 && decl
== TYPE_NAME (TREE_TYPE (decl
))
5247 && !TYPE_ARTIFICIAL (TREE_TYPE (decl
))
5248 && (type_with_linkage_p (TREE_TYPE (decl
))
5249 || TREE_CODE (TREE_TYPE (decl
)) == INTEGER_TYPE
)
5250 && !variably_modified_type_p (TREE_TYPE (decl
), NULL_TREE
))
5251 return !DECL_ASSEMBLER_NAME_SET_P (decl
);
5252 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
5253 if (TREE_CODE (decl
) != FUNCTION_DECL
5254 && TREE_CODE (decl
) != VAR_DECL
)
5257 /* If DECL already has its assembler name set, it does not need a
5259 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
5260 || DECL_ASSEMBLER_NAME_SET_P (decl
))
5263 /* Abstract decls do not need an assembler name. */
5264 if (DECL_ABSTRACT_P (decl
))
5267 /* For VAR_DECLs, only static, public and external symbols need an
5269 if (TREE_CODE (decl
) == VAR_DECL
5270 && !TREE_STATIC (decl
)
5271 && !TREE_PUBLIC (decl
)
5272 && !DECL_EXTERNAL (decl
))
5275 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5277 /* Do not set assembler name on builtins. Allow RTL expansion to
5278 decide whether to expand inline or via a regular call. */
5279 if (DECL_BUILT_IN (decl
)
5280 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
5283 /* Functions represented in the callgraph need an assembler name. */
5284 if (cgraph_node::get (decl
) != NULL
)
5287 /* Unused and not public functions don't need an assembler name. */
5288 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
5296 /* Reset all language specific information still present in symbol
5300 free_lang_data_in_decl (tree decl
)
5302 gcc_assert (DECL_P (decl
));
5304 /* Give the FE a chance to remove its own data first. */
5305 lang_hooks
.free_lang_data (decl
);
5307 TREE_LANG_FLAG_0 (decl
) = 0;
5308 TREE_LANG_FLAG_1 (decl
) = 0;
5309 TREE_LANG_FLAG_2 (decl
) = 0;
5310 TREE_LANG_FLAG_3 (decl
) = 0;
5311 TREE_LANG_FLAG_4 (decl
) = 0;
5312 TREE_LANG_FLAG_5 (decl
) = 0;
5313 TREE_LANG_FLAG_6 (decl
) = 0;
5315 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
5316 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
5317 if (TREE_CODE (decl
) == FIELD_DECL
)
5319 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
5320 if (TREE_CODE (DECL_CONTEXT (decl
)) == QUAL_UNION_TYPE
)
5321 DECL_QUALIFIER (decl
) = NULL_TREE
;
5324 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5326 struct cgraph_node
*node
;
5327 if (!(node
= cgraph_node::get (decl
))
5328 || (!node
->definition
&& !node
->clones
))
5331 node
->release_body ();
5334 release_function_body (decl
);
5335 DECL_ARGUMENTS (decl
) = NULL
;
5336 DECL_RESULT (decl
) = NULL
;
5337 DECL_INITIAL (decl
) = error_mark_node
;
5340 if (gimple_has_body_p (decl
))
5344 /* If DECL has a gimple body, then the context for its
5345 arguments must be DECL. Otherwise, it doesn't really
5346 matter, as we will not be emitting any code for DECL. In
5347 general, there may be other instances of DECL created by
5348 the front end and since PARM_DECLs are generally shared,
5349 their DECL_CONTEXT changes as the replicas of DECL are
5350 created. The only time where DECL_CONTEXT is important
5351 is for the FUNCTION_DECLs that have a gimple body (since
5352 the PARM_DECL will be used in the function's body). */
5353 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
5354 DECL_CONTEXT (t
) = decl
;
5355 if (!DECL_FUNCTION_SPECIFIC_TARGET (decl
))
5356 DECL_FUNCTION_SPECIFIC_TARGET (decl
)
5357 = target_option_default_node
;
5358 if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl
))
5359 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl
)
5360 = optimization_default_node
;
5363 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
5364 At this point, it is not needed anymore. */
5365 DECL_SAVED_TREE (decl
) = NULL_TREE
;
5367 /* Clear the abstract origin if it refers to a method. Otherwise
5368 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
5369 origin will not be output correctly. */
5370 if (DECL_ABSTRACT_ORIGIN (decl
)
5371 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
5372 && RECORD_OR_UNION_TYPE_P
5373 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
5374 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
5376 /* Sometimes the C++ frontend doesn't manage to transform a temporary
5377 DECL_VINDEX referring to itself into a vtable slot number as it
5378 should. Happens with functions that are copied and then forgotten
5379 about. Just clear it, it won't matter anymore. */
5380 if (DECL_VINDEX (decl
) && !tree_fits_shwi_p (DECL_VINDEX (decl
)))
5381 DECL_VINDEX (decl
) = NULL_TREE
;
5383 else if (TREE_CODE (decl
) == VAR_DECL
)
5385 if ((DECL_EXTERNAL (decl
)
5386 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
5387 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
5388 DECL_INITIAL (decl
) = NULL_TREE
;
5390 else if (TREE_CODE (decl
) == TYPE_DECL
5391 || TREE_CODE (decl
) == FIELD_DECL
)
5392 DECL_INITIAL (decl
) = NULL_TREE
;
5393 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
5394 && DECL_INITIAL (decl
)
5395 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
5397 /* Strip builtins from the translation-unit BLOCK. We still have targets
5398 without builtin_decl_explicit support and also builtins are shared
5399 nodes and thus we can't use TREE_CHAIN in multiple lists. */
5400 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
5404 if (TREE_CODE (var
) == FUNCTION_DECL
5405 && DECL_BUILT_IN (var
))
5406 *nextp
= TREE_CHAIN (var
);
5408 nextp
= &TREE_CHAIN (var
);
5414 /* Data used when collecting DECLs and TYPEs for language data removal. */
5416 struct free_lang_data_d
5418 /* Worklist to avoid excessive recursion. */
5421 /* Set of traversed objects. Used to avoid duplicate visits. */
5422 hash_set
<tree
> *pset
;
5424 /* Array of symbols to process with free_lang_data_in_decl. */
5427 /* Array of types to process with free_lang_data_in_type. */
5432 /* Save all language fields needed to generate proper debug information
5433 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
5436 save_debug_info_for_decl (tree t
)
5438 /*struct saved_debug_info_d *sdi;*/
5440 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
5442 /* FIXME. Partial implementation for saving debug info removed. */
5446 /* Save all language fields needed to generate proper debug information
5447 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5450 save_debug_info_for_type (tree t
)
5452 /*struct saved_debug_info_d *sdi;*/
5454 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
5456 /* FIXME. Partial implementation for saving debug info removed. */
5460 /* Add type or decl T to one of the list of tree nodes that need their
5461 language data removed. The lists are held inside FLD. */
5464 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
5468 fld
->decls
.safe_push (t
);
5469 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5470 save_debug_info_for_decl (t
);
5472 else if (TYPE_P (t
))
5474 fld
->types
.safe_push (t
);
5475 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5476 save_debug_info_for_type (t
);
5482 /* Push tree node T into FLD->WORKLIST. */
5485 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
5487 if (t
&& !is_lang_specific (t
) && !fld
->pset
->contains (t
))
5488 fld
->worklist
.safe_push ((t
));
5492 /* Operand callback helper for free_lang_data_in_node. *TP is the
5493 subtree operand being considered. */
5496 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
5499 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
5501 if (TREE_CODE (t
) == TREE_LIST
)
5504 /* Language specific nodes will be removed, so there is no need
5505 to gather anything under them. */
5506 if (is_lang_specific (t
))
5514 /* Note that walk_tree does not traverse every possible field in
5515 decls, so we have to do our own traversals here. */
5516 add_tree_to_fld_list (t
, fld
);
5518 fld_worklist_push (DECL_NAME (t
), fld
);
5519 fld_worklist_push (DECL_CONTEXT (t
), fld
);
5520 fld_worklist_push (DECL_SIZE (t
), fld
);
5521 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
5523 /* We are going to remove everything under DECL_INITIAL for
5524 TYPE_DECLs. No point walking them. */
5525 if (TREE_CODE (t
) != TYPE_DECL
)
5526 fld_worklist_push (DECL_INITIAL (t
), fld
);
5528 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
5529 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
5531 if (TREE_CODE (t
) == FUNCTION_DECL
)
5533 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
5534 fld_worklist_push (DECL_RESULT (t
), fld
);
5536 else if (TREE_CODE (t
) == TYPE_DECL
)
5538 fld_worklist_push (DECL_ORIGINAL_TYPE (t
), fld
);
5540 else if (TREE_CODE (t
) == FIELD_DECL
)
5542 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
5543 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
5544 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
5545 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
5548 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
5549 && DECL_HAS_VALUE_EXPR_P (t
))
5550 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
5552 if (TREE_CODE (t
) != FIELD_DECL
5553 && TREE_CODE (t
) != TYPE_DECL
)
5554 fld_worklist_push (TREE_CHAIN (t
), fld
);
5557 else if (TYPE_P (t
))
5559 /* Note that walk_tree does not traverse every possible field in
5560 types, so we have to do our own traversals here. */
5561 add_tree_to_fld_list (t
, fld
);
5563 if (!RECORD_OR_UNION_TYPE_P (t
))
5564 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
5565 fld_worklist_push (TYPE_SIZE (t
), fld
);
5566 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
5567 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
5568 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
5569 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
5570 fld_worklist_push (TYPE_NAME (t
), fld
);
5571 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5572 them and thus do not and want not to reach unused pointer types
5574 if (!POINTER_TYPE_P (t
))
5575 fld_worklist_push (TYPE_MINVAL (t
), fld
);
5576 if (!RECORD_OR_UNION_TYPE_P (t
))
5577 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
5578 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
5579 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5580 do not and want not to reach unused variants this way. */
5581 if (TYPE_CONTEXT (t
))
5583 tree ctx
= TYPE_CONTEXT (t
);
5584 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5585 So push that instead. */
5586 while (ctx
&& TREE_CODE (ctx
) == BLOCK
)
5587 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5588 fld_worklist_push (ctx
, fld
);
5590 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5591 and want not to reach unused types this way. */
5593 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
5597 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t
)), i
, tem
)
5598 fld_worklist_push (TREE_TYPE (tem
), fld
);
5599 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
5601 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5602 && TREE_CODE (tem
) == TREE_LIST
)
5605 fld_worklist_push (TREE_VALUE (tem
), fld
);
5606 tem
= TREE_CHAIN (tem
);
5610 if (RECORD_OR_UNION_TYPE_P (t
))
5613 /* Push all TYPE_FIELDS - there can be interleaving interesting
5614 and non-interesting things. */
5615 tem
= TYPE_FIELDS (t
);
5618 if (TREE_CODE (tem
) == FIELD_DECL
5619 || TREE_CODE (tem
) == TYPE_DECL
)
5620 fld_worklist_push (tem
, fld
);
5621 tem
= TREE_CHAIN (tem
);
5625 fld_worklist_push (TYPE_STUB_DECL (t
), fld
);
5628 else if (TREE_CODE (t
) == BLOCK
)
5631 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
5632 fld_worklist_push (tem
, fld
);
5633 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
5634 fld_worklist_push (tem
, fld
);
5635 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
5638 if (TREE_CODE (t
) != IDENTIFIER_NODE
5639 && CODE_CONTAINS_STRUCT (TREE_CODE (t
), TS_TYPED
))
5640 fld_worklist_push (TREE_TYPE (t
), fld
);
5646 /* Find decls and types in T. */
5649 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
5653 if (!fld
->pset
->contains (t
))
5654 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
5655 if (fld
->worklist
.is_empty ())
5657 t
= fld
->worklist
.pop ();
5661 /* Translate all the types in LIST with the corresponding runtime
5665 get_eh_types_for_runtime (tree list
)
5669 if (list
== NULL_TREE
)
5672 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5674 list
= TREE_CHAIN (list
);
5677 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5678 TREE_CHAIN (prev
) = n
;
5679 prev
= TREE_CHAIN (prev
);
5680 list
= TREE_CHAIN (list
);
5687 /* Find decls and types referenced in EH region R and store them in
5688 FLD->DECLS and FLD->TYPES. */
5691 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
5702 /* The types referenced in each catch must first be changed to the
5703 EH types used at runtime. This removes references to FE types
5705 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
5707 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
5708 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
5713 case ERT_ALLOWED_EXCEPTIONS
:
5714 r
->u
.allowed
.type_list
5715 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
5716 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
5719 case ERT_MUST_NOT_THROW
:
5720 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
5721 find_decls_types_r
, fld
, fld
->pset
);
5727 /* Find decls and types referenced in cgraph node N and store them in
5728 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5729 look for *every* kind of DECL and TYPE node reachable from N,
5730 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5731 NAMESPACE_DECLs, etc). */
5734 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5737 struct function
*fn
;
5741 find_decls_types (n
->decl
, fld
);
5743 if (!gimple_has_body_p (n
->decl
))
5746 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5748 fn
= DECL_STRUCT_FUNCTION (n
->decl
);
5750 /* Traverse locals. */
5751 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5752 find_decls_types (t
, fld
);
5754 /* Traverse EH regions in FN. */
5757 FOR_ALL_EH_REGION_FN (r
, fn
)
5758 find_decls_types_in_eh_region (r
, fld
);
5761 /* Traverse every statement in FN. */
5762 FOR_EACH_BB_FN (bb
, fn
)
5765 gimple_stmt_iterator si
;
5768 for (psi
= gsi_start_phis (bb
); !gsi_end_p (psi
); gsi_next (&psi
))
5770 gphi
*phi
= psi
.phi ();
5772 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5774 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5775 find_decls_types (*arg_p
, fld
);
5779 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5781 gimple stmt
= gsi_stmt (si
);
5783 if (is_gimple_call (stmt
))
5784 find_decls_types (gimple_call_fntype (stmt
), fld
);
5786 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5788 tree arg
= gimple_op (stmt
, i
);
5789 find_decls_types (arg
, fld
);
5796 /* Find decls and types referenced in varpool node N and store them in
5797 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5798 look for *every* kind of DECL and TYPE node reachable from N,
5799 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5800 NAMESPACE_DECLs, etc). */
5803 find_decls_types_in_var (varpool_node
*v
, struct free_lang_data_d
*fld
)
5805 find_decls_types (v
->decl
, fld
);
5808 /* If T needs an assembler name, have one created for it. */
5811 assign_assembler_name_if_neeeded (tree t
)
5813 if (need_assembler_name_p (t
))
5815 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5816 diagnostics that use input_location to show locus
5817 information. The problem here is that, at this point,
5818 input_location is generally anchored to the end of the file
5819 (since the parser is long gone), so we don't have a good
5820 position to pin it to.
5822 To alleviate this problem, this uses the location of T's
5823 declaration. Examples of this are
5824 testsuite/g++.dg/template/cond2.C and
5825 testsuite/g++.dg/template/pr35240.C. */
5826 location_t saved_location
= input_location
;
5827 input_location
= DECL_SOURCE_LOCATION (t
);
5829 decl_assembler_name (t
);
5831 input_location
= saved_location
;
5836 /* Free language specific information for every operand and expression
5837 in every node of the call graph. This process operates in three stages:
5839 1- Every callgraph node and varpool node is traversed looking for
5840 decls and types embedded in them. This is a more exhaustive
5841 search than that done by find_referenced_vars, because it will
5842 also collect individual fields, decls embedded in types, etc.
5844 2- All the decls found are sent to free_lang_data_in_decl.
5846 3- All the types found are sent to free_lang_data_in_type.
5848 The ordering between decls and types is important because
5849 free_lang_data_in_decl sets assembler names, which includes
5850 mangling. So types cannot be freed up until assembler names have
5854 free_lang_data_in_cgraph (void)
5856 struct cgraph_node
*n
;
5858 struct free_lang_data_d fld
;
5863 /* Initialize sets and arrays to store referenced decls and types. */
5864 fld
.pset
= new hash_set
<tree
>;
5865 fld
.worklist
.create (0);
5866 fld
.decls
.create (100);
5867 fld
.types
.create (100);
5869 /* Find decls and types in the body of every function in the callgraph. */
5870 FOR_EACH_FUNCTION (n
)
5871 find_decls_types_in_node (n
, &fld
);
5873 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
5874 find_decls_types (p
->decl
, &fld
);
5876 /* Find decls and types in every varpool symbol. */
5877 FOR_EACH_VARIABLE (v
)
5878 find_decls_types_in_var (v
, &fld
);
5880 /* Set the assembler name on every decl found. We need to do this
5881 now because free_lang_data_in_decl will invalidate data needed
5882 for mangling. This breaks mangling on interdependent decls. */
5883 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5884 assign_assembler_name_if_neeeded (t
);
5886 /* Traverse every decl found freeing its language data. */
5887 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5888 free_lang_data_in_decl (t
);
5890 /* Traverse every type found freeing its language data. */
5891 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5892 free_lang_data_in_type (t
);
5893 #ifdef ENABLE_CHECKING
5894 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5899 fld
.worklist
.release ();
5900 fld
.decls
.release ();
5901 fld
.types
.release ();
5905 /* Free resources that are used by FE but are not needed once they are done. */
5908 free_lang_data (void)
5912 /* If we are the LTO frontend we have freed lang-specific data already. */
5914 || (!flag_generate_lto
&& !flag_generate_offload
))
5917 /* Allocate and assign alias sets to the standard integer types
5918 while the slots are still in the way the frontends generated them. */
5919 for (i
= 0; i
< itk_none
; ++i
)
5920 if (integer_types
[i
])
5921 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5923 /* Traverse the IL resetting language specific information for
5924 operands, expressions, etc. */
5925 free_lang_data_in_cgraph ();
5927 /* Create gimple variants for common types. */
5928 ptrdiff_type_node
= integer_type_node
;
5929 fileptr_type_node
= ptr_type_node
;
5931 /* Reset some langhooks. Do not reset types_compatible_p, it may
5932 still be used indirectly via the get_alias_set langhook. */
5933 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5934 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5935 lang_hooks
.gimplify_expr
= lhd_gimplify_expr
;
5937 /* We do not want the default decl_assembler_name implementation,
5938 rather if we have fixed everything we want a wrapper around it
5939 asserting that all non-local symbols already got their assembler
5940 name and only produce assembler names for local symbols. Or rather
5941 make sure we never call decl_assembler_name on local symbols and
5942 devise a separate, middle-end private scheme for it. */
5944 /* Reset diagnostic machinery. */
5945 tree_diagnostics_defaults (global_dc
);
5951 static const pass_data pass_data_ipa_free_lang_data
=
5953 SIMPLE_IPA_PASS
, /* type */
5954 "*free_lang_data", /* name */
5955 OPTGROUP_NONE
, /* optinfo_flags */
5956 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5957 0, /* properties_required */
5958 0, /* properties_provided */
5959 0, /* properties_destroyed */
5960 0, /* todo_flags_start */
5961 0, /* todo_flags_finish */
5964 class pass_ipa_free_lang_data GCC_FINAL
: public simple_ipa_opt_pass
5967 pass_ipa_free_lang_data (gcc::context
*ctxt
)
5968 : simple_ipa_opt_pass (pass_data_ipa_free_lang_data
, ctxt
)
5971 /* opt_pass methods: */
5972 virtual unsigned int execute (function
*) { return free_lang_data (); }
5974 }; // class pass_ipa_free_lang_data
5976 simple_ipa_opt_pass
*
5977 make_pass_ipa_free_lang_data (gcc::context
*ctxt
)
5979 return new pass_ipa_free_lang_data (ctxt
);
5982 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
5983 ATTR_NAME. Also used internally by remove_attribute(). */
5985 private_is_attribute_p (const char *attr_name
, size_t attr_len
, const_tree ident
)
5987 size_t ident_len
= IDENTIFIER_LENGTH (ident
);
5989 if (ident_len
== attr_len
)
5991 if (strcmp (attr_name
, IDENTIFIER_POINTER (ident
)) == 0)
5994 else if (ident_len
== attr_len
+ 4)
5996 /* There is the possibility that ATTR is 'text' and IDENT is
5998 const char *p
= IDENTIFIER_POINTER (ident
);
5999 if (p
[0] == '_' && p
[1] == '_'
6000 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
6001 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6008 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
6009 of ATTR_NAME, and LIST is not NULL_TREE. */
6011 private_lookup_attribute (const char *attr_name
, size_t attr_len
, tree list
)
6015 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
6017 if (ident_len
== attr_len
)
6019 if (!strcmp (attr_name
,
6020 IDENTIFIER_POINTER (get_attribute_name (list
))))
6023 /* TODO: If we made sure that attributes were stored in the
6024 canonical form without '__...__' (ie, as in 'text' as opposed
6025 to '__text__') then we could avoid the following case. */
6026 else if (ident_len
== attr_len
+ 4)
6028 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
6029 if (p
[0] == '_' && p
[1] == '_'
6030 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
6031 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6034 list
= TREE_CHAIN (list
);
6040 /* Given an attribute name ATTR_NAME and a list of attributes LIST,
6041 return a pointer to the attribute's list first element if the attribute
6042 starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
6046 private_lookup_attribute_by_prefix (const char *attr_name
, size_t attr_len
,
6051 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
6053 if (attr_len
> ident_len
)
6055 list
= TREE_CHAIN (list
);
6059 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
6061 if (strncmp (attr_name
, p
, attr_len
) == 0)
6064 /* TODO: If we made sure that attributes were stored in the
6065 canonical form without '__...__' (ie, as in 'text' as opposed
6066 to '__text__') then we could avoid the following case. */
6067 if (p
[0] == '_' && p
[1] == '_' &&
6068 strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6071 list
= TREE_CHAIN (list
);
6078 /* A variant of lookup_attribute() that can be used with an identifier
6079 as the first argument, and where the identifier can be either
6080 'text' or '__text__'.
6082 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
6083 return a pointer to the attribute's list element if the attribute
6084 is part of the list, or NULL_TREE if not found. If the attribute
6085 appears more than once, this only returns the first occurrence; the
6086 TREE_CHAIN of the return value should be passed back in if further
6087 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
6088 can be in the form 'text' or '__text__'. */
6090 lookup_ident_attribute (tree attr_identifier
, tree list
)
6092 gcc_checking_assert (TREE_CODE (attr_identifier
) == IDENTIFIER_NODE
);
6096 gcc_checking_assert (TREE_CODE (get_attribute_name (list
))
6097 == IDENTIFIER_NODE
);
6099 if (cmp_attrib_identifiers (attr_identifier
,
6100 get_attribute_name (list
)))
6103 list
= TREE_CHAIN (list
);
6109 /* Remove any instances of attribute ATTR_NAME in LIST and return the
6113 remove_attribute (const char *attr_name
, tree list
)
6116 size_t attr_len
= strlen (attr_name
);
6118 gcc_checking_assert (attr_name
[0] != '_');
6120 for (p
= &list
; *p
; )
6123 /* TODO: If we were storing attributes in normalized form, here
6124 we could use a simple strcmp(). */
6125 if (private_is_attribute_p (attr_name
, attr_len
, get_attribute_name (l
)))
6126 *p
= TREE_CHAIN (l
);
6128 p
= &TREE_CHAIN (l
);
6134 /* Return an attribute list that is the union of a1 and a2. */
6137 merge_attributes (tree a1
, tree a2
)
6141 /* Either one unset? Take the set one. */
6143 if ((attributes
= a1
) == 0)
6146 /* One that completely contains the other? Take it. */
6148 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
6150 if (attribute_list_contained (a2
, a1
))
6154 /* Pick the longest list, and hang on the other list. */
6156 if (list_length (a1
) < list_length (a2
))
6157 attributes
= a2
, a2
= a1
;
6159 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
6162 for (a
= lookup_ident_attribute (get_attribute_name (a2
),
6164 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
6165 a
= lookup_ident_attribute (get_attribute_name (a2
),
6170 a1
= copy_node (a2
);
6171 TREE_CHAIN (a1
) = attributes
;
6180 /* Given types T1 and T2, merge their attributes and return
6184 merge_type_attributes (tree t1
, tree t2
)
6186 return merge_attributes (TYPE_ATTRIBUTES (t1
),
6187 TYPE_ATTRIBUTES (t2
));
6190 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
6194 merge_decl_attributes (tree olddecl
, tree newdecl
)
6196 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
6197 DECL_ATTRIBUTES (newdecl
));
6200 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
6202 /* Specialization of merge_decl_attributes for various Windows targets.
6204 This handles the following situation:
6206 __declspec (dllimport) int foo;
6209 The second instance of `foo' nullifies the dllimport. */
6212 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
6215 int delete_dllimport_p
= 1;
6217 /* What we need to do here is remove from `old' dllimport if it doesn't
6218 appear in `new'. dllimport behaves like extern: if a declaration is
6219 marked dllimport and a definition appears later, then the object
6220 is not dllimport'd. We also remove a `new' dllimport if the old list
6221 contains dllexport: dllexport always overrides dllimport, regardless
6222 of the order of declaration. */
6223 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
6224 delete_dllimport_p
= 0;
6225 else if (DECL_DLLIMPORT_P (new_tree
)
6226 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
6228 DECL_DLLIMPORT_P (new_tree
) = 0;
6229 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
6230 "dllimport ignored", new_tree
);
6232 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
6234 /* Warn about overriding a symbol that has already been used, e.g.:
6235 extern int __attribute__ ((dllimport)) foo;
6236 int* bar () {return &foo;}
6239 if (TREE_USED (old
))
6241 warning (0, "%q+D redeclared without dllimport attribute "
6242 "after being referenced with dll linkage", new_tree
);
6243 /* If we have used a variable's address with dllimport linkage,
6244 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
6245 decl may already have had TREE_CONSTANT computed.
6246 We still remove the attribute so that assembler code refers
6247 to '&foo rather than '_imp__foo'. */
6248 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
6249 DECL_DLLIMPORT_P (new_tree
) = 1;
6252 /* Let an inline definition silently override the external reference,
6253 but otherwise warn about attribute inconsistency. */
6254 else if (TREE_CODE (new_tree
) == VAR_DECL
6255 || !DECL_DECLARED_INLINE_P (new_tree
))
6256 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
6257 "previous dllimport ignored", new_tree
);
6260 delete_dllimport_p
= 0;
6262 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
6264 if (delete_dllimport_p
)
6265 a
= remove_attribute ("dllimport", a
);
6270 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
6271 struct attribute_spec.handler. */
6274 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
6280 /* These attributes may apply to structure and union types being created,
6281 but otherwise should pass to the declaration involved. */
6284 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
6285 | (int) ATTR_FLAG_ARRAY_NEXT
))
6287 *no_add_attrs
= true;
6288 return tree_cons (name
, args
, NULL_TREE
);
6290 if (TREE_CODE (node
) == RECORD_TYPE
6291 || TREE_CODE (node
) == UNION_TYPE
)
6293 node
= TYPE_NAME (node
);
6299 warning (OPT_Wattributes
, "%qE attribute ignored",
6301 *no_add_attrs
= true;
6306 if (TREE_CODE (node
) != FUNCTION_DECL
6307 && TREE_CODE (node
) != VAR_DECL
6308 && TREE_CODE (node
) != TYPE_DECL
)
6310 *no_add_attrs
= true;
6311 warning (OPT_Wattributes
, "%qE attribute ignored",
6316 if (TREE_CODE (node
) == TYPE_DECL
6317 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
6318 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
6320 *no_add_attrs
= true;
6321 warning (OPT_Wattributes
, "%qE attribute ignored",
6326 is_dllimport
= is_attribute_p ("dllimport", name
);
6328 /* Report error on dllimport ambiguities seen now before they cause
6332 /* Honor any target-specific overrides. */
6333 if (!targetm
.valid_dllimport_attribute_p (node
))
6334 *no_add_attrs
= true;
6336 else if (TREE_CODE (node
) == FUNCTION_DECL
6337 && DECL_DECLARED_INLINE_P (node
))
6339 warning (OPT_Wattributes
, "inline function %q+D declared as "
6340 " dllimport: attribute ignored", node
);
6341 *no_add_attrs
= true;
6343 /* Like MS, treat definition of dllimported variables and
6344 non-inlined functions on declaration as syntax errors. */
6345 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
6347 error ("function %q+D definition is marked dllimport", node
);
6348 *no_add_attrs
= true;
6351 else if (TREE_CODE (node
) == VAR_DECL
)
6353 if (DECL_INITIAL (node
))
6355 error ("variable %q+D definition is marked dllimport",
6357 *no_add_attrs
= true;
6360 /* `extern' needn't be specified with dllimport.
6361 Specify `extern' now and hope for the best. Sigh. */
6362 DECL_EXTERNAL (node
) = 1;
6363 /* Also, implicitly give dllimport'd variables declared within
6364 a function global scope, unless declared static. */
6365 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
6366 TREE_PUBLIC (node
) = 1;
6369 if (*no_add_attrs
== false)
6370 DECL_DLLIMPORT_P (node
) = 1;
6372 else if (TREE_CODE (node
) == FUNCTION_DECL
6373 && DECL_DECLARED_INLINE_P (node
)
6374 && flag_keep_inline_dllexport
)
6375 /* An exported function, even if inline, must be emitted. */
6376 DECL_EXTERNAL (node
) = 0;
6378 /* Report error if symbol is not accessible at global scope. */
6379 if (!TREE_PUBLIC (node
)
6380 && (TREE_CODE (node
) == VAR_DECL
6381 || TREE_CODE (node
) == FUNCTION_DECL
))
6383 error ("external linkage required for symbol %q+D because of "
6384 "%qE attribute", node
, name
);
6385 *no_add_attrs
= true;
6388 /* A dllexport'd entity must have default visibility so that other
6389 program units (shared libraries or the main executable) can see
6390 it. A dllimport'd entity must have default visibility so that
6391 the linker knows that undefined references within this program
6392 unit can be resolved by the dynamic linker. */
6395 if (DECL_VISIBILITY_SPECIFIED (node
)
6396 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
6397 error ("%qE implies default visibility, but %qD has already "
6398 "been declared with a different visibility",
6400 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
6401 DECL_VISIBILITY_SPECIFIED (node
) = 1;
6407 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
6409 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
6410 of the various TYPE_QUAL values. */
6413 set_type_quals (tree type
, int type_quals
)
6415 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
6416 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
6417 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
6418 TYPE_ATOMIC (type
) = (type_quals
& TYPE_QUAL_ATOMIC
) != 0;
6419 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
6422 /* Returns true iff unqualified CAND and BASE are equivalent. */
6425 check_base_type (const_tree cand
, const_tree base
)
6427 return (TYPE_NAME (cand
) == TYPE_NAME (base
)
6428 /* Apparently this is needed for Objective-C. */
6429 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6430 /* Check alignment. */
6431 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
6432 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6433 TYPE_ATTRIBUTES (base
)));
6436 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
6439 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
6441 return (TYPE_QUALS (cand
) == type_quals
6442 && check_base_type (cand
, base
));
6445 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
6448 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
6450 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
6451 && TYPE_NAME (cand
) == TYPE_NAME (base
)
6452 /* Apparently this is needed for Objective-C. */
6453 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6454 /* Check alignment. */
6455 && TYPE_ALIGN (cand
) == align
6456 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6457 TYPE_ATTRIBUTES (base
)));
6460 /* This function checks to see if TYPE matches the size one of the built-in
6461 atomic types, and returns that core atomic type. */
6464 find_atomic_core_type (tree type
)
6466 tree base_atomic_type
;
6468 /* Only handle complete types. */
6469 if (TYPE_SIZE (type
) == NULL_TREE
)
6472 HOST_WIDE_INT type_size
= tree_to_uhwi (TYPE_SIZE (type
));
6476 base_atomic_type
= atomicQI_type_node
;
6480 base_atomic_type
= atomicHI_type_node
;
6484 base_atomic_type
= atomicSI_type_node
;
6488 base_atomic_type
= atomicDI_type_node
;
6492 base_atomic_type
= atomicTI_type_node
;
6496 base_atomic_type
= NULL_TREE
;
6499 return base_atomic_type
;
6502 /* Return a version of the TYPE, qualified as indicated by the
6503 TYPE_QUALS, if one exists. If no qualified version exists yet,
6504 return NULL_TREE. */
6507 get_qualified_type (tree type
, int type_quals
)
6511 if (TYPE_QUALS (type
) == type_quals
)
6514 /* Search the chain of variants to see if there is already one there just
6515 like the one we need to have. If so, use that existing one. We must
6516 preserve the TYPE_NAME, since there is code that depends on this. */
6517 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6518 if (check_qualified_type (t
, type
, type_quals
))
6524 /* Like get_qualified_type, but creates the type if it does not
6525 exist. This function never returns NULL_TREE. */
6528 build_qualified_type (tree type
, int type_quals
)
6532 /* See if we already have the appropriate qualified variant. */
6533 t
= get_qualified_type (type
, type_quals
);
6535 /* If not, build it. */
6538 t
= build_variant_type_copy (type
);
6539 set_type_quals (t
, type_quals
);
6541 if (((type_quals
& TYPE_QUAL_ATOMIC
) == TYPE_QUAL_ATOMIC
))
6543 /* See if this object can map to a basic atomic type. */
6544 tree atomic_type
= find_atomic_core_type (type
);
6547 /* Ensure the alignment of this type is compatible with
6548 the required alignment of the atomic type. */
6549 if (TYPE_ALIGN (atomic_type
) > TYPE_ALIGN (t
))
6550 TYPE_ALIGN (t
) = TYPE_ALIGN (atomic_type
);
6554 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6555 /* Propagate structural equality. */
6556 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6557 else if (TYPE_CANONICAL (type
) != type
)
6558 /* Build the underlying canonical type, since it is different
6561 tree c
= build_qualified_type (TYPE_CANONICAL (type
), type_quals
);
6562 TYPE_CANONICAL (t
) = TYPE_CANONICAL (c
);
6565 /* T is its own canonical type. */
6566 TYPE_CANONICAL (t
) = t
;
6573 /* Create a variant of type T with alignment ALIGN. */
6576 build_aligned_type (tree type
, unsigned int align
)
6580 if (TYPE_PACKED (type
)
6581 || TYPE_ALIGN (type
) == align
)
6584 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6585 if (check_aligned_type (t
, type
, align
))
6588 t
= build_variant_type_copy (type
);
6589 TYPE_ALIGN (t
) = align
;
6594 /* Create a new distinct copy of TYPE. The new type is made its own
6595 MAIN_VARIANT. If TYPE requires structural equality checks, the
6596 resulting type requires structural equality checks; otherwise, its
6597 TYPE_CANONICAL points to itself. */
6600 build_distinct_type_copy (tree type
)
6602 tree t
= copy_node (type
);
6604 TYPE_POINTER_TO (t
) = 0;
6605 TYPE_REFERENCE_TO (t
) = 0;
6607 /* Set the canonical type either to a new equivalence class, or
6608 propagate the need for structural equality checks. */
6609 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6610 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6612 TYPE_CANONICAL (t
) = t
;
6614 /* Make it its own variant. */
6615 TYPE_MAIN_VARIANT (t
) = t
;
6616 TYPE_NEXT_VARIANT (t
) = 0;
6618 /* We do not record methods in type copies nor variants
6619 so we do not need to keep them up to date when new method
6621 if (RECORD_OR_UNION_TYPE_P (t
))
6622 TYPE_METHODS (t
) = NULL_TREE
;
6624 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6625 whose TREE_TYPE is not t. This can also happen in the Ada
6626 frontend when using subtypes. */
6631 /* Create a new variant of TYPE, equivalent but distinct. This is so
6632 the caller can modify it. TYPE_CANONICAL for the return type will
6633 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6634 are considered equal by the language itself (or that both types
6635 require structural equality checks). */
6638 build_variant_type_copy (tree type
)
6640 tree t
, m
= TYPE_MAIN_VARIANT (type
);
6642 t
= build_distinct_type_copy (type
);
6644 /* Since we're building a variant, assume that it is a non-semantic
6645 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6646 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
6648 /* Add the new type to the chain of variants of TYPE. */
6649 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
6650 TYPE_NEXT_VARIANT (m
) = t
;
6651 TYPE_MAIN_VARIANT (t
) = m
;
6656 /* Return true if the from tree in both tree maps are equal. */
6659 tree_map_base_eq (const void *va
, const void *vb
)
6661 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
6662 *const b
= (const struct tree_map_base
*) vb
;
6663 return (a
->from
== b
->from
);
6666 /* Hash a from tree in a tree_base_map. */
6669 tree_map_base_hash (const void *item
)
6671 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
6674 /* Return true if this tree map structure is marked for garbage collection
6675 purposes. We simply return true if the from tree is marked, so that this
6676 structure goes away when the from tree goes away. */
6679 tree_map_base_marked_p (const void *p
)
6681 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
6684 /* Hash a from tree in a tree_map. */
6687 tree_map_hash (const void *item
)
6689 return (((const struct tree_map
*) item
)->hash
);
6692 /* Hash a from tree in a tree_decl_map. */
6695 tree_decl_map_hash (const void *item
)
6697 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
6700 /* Return the initialization priority for DECL. */
6703 decl_init_priority_lookup (tree decl
)
6705 symtab_node
*snode
= symtab_node::get (decl
);
6708 return DEFAULT_INIT_PRIORITY
;
6710 snode
->get_init_priority ();
6713 /* Return the finalization priority for DECL. */
6716 decl_fini_priority_lookup (tree decl
)
6718 cgraph_node
*node
= cgraph_node::get (decl
);
6721 return DEFAULT_INIT_PRIORITY
;
6723 node
->get_fini_priority ();
6726 /* Set the initialization priority for DECL to PRIORITY. */
6729 decl_init_priority_insert (tree decl
, priority_type priority
)
6731 struct symtab_node
*snode
;
6733 if (priority
== DEFAULT_INIT_PRIORITY
)
6735 snode
= symtab_node::get (decl
);
6739 else if (TREE_CODE (decl
) == VAR_DECL
)
6740 snode
= varpool_node::get_create (decl
);
6742 snode
= cgraph_node::get_create (decl
);
6743 snode
->set_init_priority (priority
);
6746 /* Set the finalization priority for DECL to PRIORITY. */
6749 decl_fini_priority_insert (tree decl
, priority_type priority
)
6751 struct cgraph_node
*node
;
6753 if (priority
== DEFAULT_INIT_PRIORITY
)
6755 node
= cgraph_node::get (decl
);
6760 node
= cgraph_node::get_create (decl
);
6761 node
->set_fini_priority (priority
);
6764 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6767 print_debug_expr_statistics (void)
6769 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6770 (long) debug_expr_for_decl
->size (),
6771 (long) debug_expr_for_decl
->elements (),
6772 debug_expr_for_decl
->collisions ());
6775 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6778 print_value_expr_statistics (void)
6780 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6781 (long) value_expr_for_decl
->size (),
6782 (long) value_expr_for_decl
->elements (),
6783 value_expr_for_decl
->collisions ());
6786 /* Lookup a debug expression for FROM, and return it if we find one. */
6789 decl_debug_expr_lookup (tree from
)
6791 struct tree_decl_map
*h
, in
;
6792 in
.base
.from
= from
;
6794 h
= debug_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6800 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6803 decl_debug_expr_insert (tree from
, tree to
)
6805 struct tree_decl_map
*h
;
6807 h
= ggc_alloc
<tree_decl_map
> ();
6808 h
->base
.from
= from
;
6810 *debug_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
6813 /* Lookup a value expression for FROM, and return it if we find one. */
6816 decl_value_expr_lookup (tree from
)
6818 struct tree_decl_map
*h
, in
;
6819 in
.base
.from
= from
;
6821 h
= value_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6827 /* Insert a mapping FROM->TO in the value expression hashtable. */
6830 decl_value_expr_insert (tree from
, tree to
)
6832 struct tree_decl_map
*h
;
6834 h
= ggc_alloc
<tree_decl_map
> ();
6835 h
->base
.from
= from
;
6837 *value_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
6840 /* Lookup a vector of debug arguments for FROM, and return it if we
6844 decl_debug_args_lookup (tree from
)
6846 struct tree_vec_map
*h
, in
;
6848 if (!DECL_HAS_DEBUG_ARGS_P (from
))
6850 gcc_checking_assert (debug_args_for_decl
!= NULL
);
6851 in
.base
.from
= from
;
6852 h
= debug_args_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6858 /* Insert a mapping FROM->empty vector of debug arguments in the value
6859 expression hashtable. */
6862 decl_debug_args_insert (tree from
)
6864 struct tree_vec_map
*h
;
6867 if (DECL_HAS_DEBUG_ARGS_P (from
))
6868 return decl_debug_args_lookup (from
);
6869 if (debug_args_for_decl
== NULL
)
6870 debug_args_for_decl
= hash_table
<tree_vec_map_cache_hasher
>::create_ggc (64);
6871 h
= ggc_alloc
<tree_vec_map
> ();
6872 h
->base
.from
= from
;
6874 loc
= debug_args_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
);
6876 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
6880 /* Hashing of types so that we don't make duplicates.
6881 The entry point is `type_hash_canon'. */
6883 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6884 with types in the TREE_VALUE slots), by adding the hash codes
6885 of the individual types. */
6888 type_hash_list (const_tree list
, inchash::hash
&hstate
)
6892 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6893 if (TREE_VALUE (tail
) != error_mark_node
)
6894 hstate
.add_object (TYPE_HASH (TREE_VALUE (tail
)));
6897 /* These are the Hashtable callback functions. */
6899 /* Returns true iff the types are equivalent. */
6902 type_cache_hasher::equal (type_hash
*a
, type_hash
*b
)
6904 /* First test the things that are the same for all types. */
6905 if (a
->hash
!= b
->hash
6906 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6907 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6908 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6909 TYPE_ATTRIBUTES (b
->type
))
6910 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6911 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6914 /* Be careful about comparing arrays before and after the element type
6915 has been completed; don't compare TYPE_ALIGN unless both types are
6917 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6918 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6919 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6922 switch (TREE_CODE (a
->type
))
6927 case REFERENCE_TYPE
:
6932 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6935 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6936 && !(TYPE_VALUES (a
->type
)
6937 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6938 && TYPE_VALUES (b
->type
)
6939 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6940 && type_list_equal (TYPE_VALUES (a
->type
),
6941 TYPE_VALUES (b
->type
))))
6944 /* ... fall through ... */
6949 if (TYPE_PRECISION (a
->type
) != TYPE_PRECISION (b
->type
))
6951 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6952 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6953 TYPE_MAX_VALUE (b
->type
)))
6954 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6955 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6956 TYPE_MIN_VALUE (b
->type
))));
6958 case FIXED_POINT_TYPE
:
6959 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6962 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6965 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6966 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6967 || (TYPE_ARG_TYPES (a
->type
)
6968 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6969 && TYPE_ARG_TYPES (b
->type
)
6970 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6971 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6972 TYPE_ARG_TYPES (b
->type
)))))
6976 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6980 case QUAL_UNION_TYPE
:
6981 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6982 || (TYPE_FIELDS (a
->type
)
6983 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6984 && TYPE_FIELDS (b
->type
)
6985 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6986 && type_list_equal (TYPE_FIELDS (a
->type
),
6987 TYPE_FIELDS (b
->type
))));
6990 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6991 || (TYPE_ARG_TYPES (a
->type
)
6992 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6993 && TYPE_ARG_TYPES (b
->type
)
6994 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6995 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6996 TYPE_ARG_TYPES (b
->type
))))
7004 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
7005 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
7010 /* Given TYPE, and HASHCODE its hash code, return the canonical
7011 object for an identical type if one already exists.
7012 Otherwise, return TYPE, and record it as the canonical object.
7014 To use this function, first create a type of the sort you want.
7015 Then compute its hash code from the fields of the type that
7016 make it different from other similar types.
7017 Then call this function and use the value. */
7020 type_hash_canon (unsigned int hashcode
, tree type
)
7025 /* The hash table only contains main variants, so ensure that's what we're
7027 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
7029 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
7030 must call that routine before comparing TYPE_ALIGNs. */
7036 loc
= type_hash_table
->find_slot_with_hash (&in
, hashcode
, INSERT
);
7039 tree t1
= ((type_hash
*) *loc
)->type
;
7040 gcc_assert (TYPE_MAIN_VARIANT (t1
) == t1
);
7041 if (GATHER_STATISTICS
)
7043 tree_code_counts
[(int) TREE_CODE (type
)]--;
7044 tree_node_counts
[(int) t_kind
]--;
7045 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type_non_common
);
7051 struct type_hash
*h
;
7053 h
= ggc_alloc
<type_hash
> ();
7063 print_type_hash_statistics (void)
7065 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
7066 (long) type_hash_table
->size (),
7067 (long) type_hash_table
->elements (),
7068 type_hash_table
->collisions ());
7071 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
7072 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
7073 by adding the hash codes of the individual attributes. */
7076 attribute_hash_list (const_tree list
, inchash::hash
&hstate
)
7080 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
7081 /* ??? Do we want to add in TREE_VALUE too? */
7082 hstate
.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (tail
)));
7085 /* Given two lists of attributes, return true if list l2 is
7086 equivalent to l1. */
7089 attribute_list_equal (const_tree l1
, const_tree l2
)
7094 return attribute_list_contained (l1
, l2
)
7095 && attribute_list_contained (l2
, l1
);
7098 /* Given two lists of attributes, return true if list L2 is
7099 completely contained within L1. */
7100 /* ??? This would be faster if attribute names were stored in a canonicalized
7101 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
7102 must be used to show these elements are equivalent (which they are). */
7103 /* ??? It's not clear that attributes with arguments will always be handled
7107 attribute_list_contained (const_tree l1
, const_tree l2
)
7111 /* First check the obvious, maybe the lists are identical. */
7115 /* Maybe the lists are similar. */
7116 for (t1
= l1
, t2
= l2
;
7118 && get_attribute_name (t1
) == get_attribute_name (t2
)
7119 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
7120 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
7123 /* Maybe the lists are equal. */
7124 if (t1
== 0 && t2
== 0)
7127 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
7130 /* This CONST_CAST is okay because lookup_attribute does not
7131 modify its argument and the return value is assigned to a
7133 for (attr
= lookup_ident_attribute (get_attribute_name (t2
),
7134 CONST_CAST_TREE (l1
));
7135 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
7136 attr
= lookup_ident_attribute (get_attribute_name (t2
),
7140 if (attr
== NULL_TREE
)
7147 /* Given two lists of types
7148 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
7149 return 1 if the lists contain the same types in the same order.
7150 Also, the TREE_PURPOSEs must match. */
7153 type_list_equal (const_tree l1
, const_tree l2
)
7157 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
7158 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
7159 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
7160 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
7161 && (TREE_TYPE (TREE_PURPOSE (t1
))
7162 == TREE_TYPE (TREE_PURPOSE (t2
))))))
7168 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
7169 given by TYPE. If the argument list accepts variable arguments,
7170 then this function counts only the ordinary arguments. */
7173 type_num_arguments (const_tree type
)
7178 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
7179 /* If the function does not take a variable number of arguments,
7180 the last element in the list will have type `void'. */
7181 if (VOID_TYPE_P (TREE_VALUE (t
)))
7189 /* Nonzero if integer constants T1 and T2
7190 represent the same constant value. */
7193 tree_int_cst_equal (const_tree t1
, const_tree t2
)
7198 if (t1
== 0 || t2
== 0)
7201 if (TREE_CODE (t1
) == INTEGER_CST
7202 && TREE_CODE (t2
) == INTEGER_CST
7203 && wi::to_widest (t1
) == wi::to_widest (t2
))
7209 /* Return true if T is an INTEGER_CST whose numerical value (extended
7210 according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
7213 tree_fits_shwi_p (const_tree t
)
7215 return (t
!= NULL_TREE
7216 && TREE_CODE (t
) == INTEGER_CST
7217 && wi::fits_shwi_p (wi::to_widest (t
)));
7220 /* Return true if T is an INTEGER_CST whose numerical value (extended
7221 according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
7224 tree_fits_uhwi_p (const_tree t
)
7226 return (t
!= NULL_TREE
7227 && TREE_CODE (t
) == INTEGER_CST
7228 && wi::fits_uhwi_p (wi::to_widest (t
)));
7231 /* T is an INTEGER_CST whose numerical value (extended according to
7232 TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
7236 tree_to_shwi (const_tree t
)
7238 gcc_assert (tree_fits_shwi_p (t
));
7239 return TREE_INT_CST_LOW (t
);
7242 /* T is an INTEGER_CST whose numerical value (extended according to
7243 TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
7246 unsigned HOST_WIDE_INT
7247 tree_to_uhwi (const_tree t
)
7249 gcc_assert (tree_fits_uhwi_p (t
));
7250 return TREE_INT_CST_LOW (t
);
7253 /* Return the most significant (sign) bit of T. */
7256 tree_int_cst_sign_bit (const_tree t
)
7258 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
7260 return wi::extract_uhwi (t
, bitno
, 1);
7263 /* Return an indication of the sign of the integer constant T.
7264 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
7265 Note that -1 will never be returned if T's type is unsigned. */
7268 tree_int_cst_sgn (const_tree t
)
7270 if (wi::eq_p (t
, 0))
7272 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
7274 else if (wi::neg_p (t
))
7280 /* Return the minimum number of bits needed to represent VALUE in a
7281 signed or unsigned type, UNSIGNEDP says which. */
7284 tree_int_cst_min_precision (tree value
, signop sgn
)
7286 /* If the value is negative, compute its negative minus 1. The latter
7287 adjustment is because the absolute value of the largest negative value
7288 is one larger than the largest positive value. This is equivalent to
7289 a bit-wise negation, so use that operation instead. */
7291 if (tree_int_cst_sgn (value
) < 0)
7292 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
7294 /* Return the number of bits needed, taking into account the fact
7295 that we need one more bit for a signed than unsigned type.
7296 If value is 0 or -1, the minimum precision is 1 no matter
7297 whether unsignedp is true or false. */
7299 if (integer_zerop (value
))
7302 return tree_floor_log2 (value
) + 1 + (sgn
== SIGNED
? 1 : 0) ;
7305 /* Return truthvalue of whether T1 is the same tree structure as T2.
7306 Return 1 if they are the same.
7307 Return 0 if they are understandably different.
7308 Return -1 if either contains tree structure not understood by
7312 simple_cst_equal (const_tree t1
, const_tree t2
)
7314 enum tree_code code1
, code2
;
7320 if (t1
== 0 || t2
== 0)
7323 code1
= TREE_CODE (t1
);
7324 code2
= TREE_CODE (t2
);
7326 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
7328 if (CONVERT_EXPR_CODE_P (code2
)
7329 || code2
== NON_LVALUE_EXPR
)
7330 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7332 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
7335 else if (CONVERT_EXPR_CODE_P (code2
)
7336 || code2
== NON_LVALUE_EXPR
)
7337 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
7345 return wi::to_widest (t1
) == wi::to_widest (t2
);
7348 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
7351 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
7354 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
7355 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
7356 TREE_STRING_LENGTH (t1
)));
7360 unsigned HOST_WIDE_INT idx
;
7361 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
7362 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
7364 if (vec_safe_length (v1
) != vec_safe_length (v2
))
7367 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
7368 /* ??? Should we handle also fields here? */
7369 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
7375 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7378 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
7381 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
7384 const_tree arg1
, arg2
;
7385 const_call_expr_arg_iterator iter1
, iter2
;
7386 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
7387 arg2
= first_const_call_expr_arg (t2
, &iter2
);
7389 arg1
= next_const_call_expr_arg (&iter1
),
7390 arg2
= next_const_call_expr_arg (&iter2
))
7392 cmp
= simple_cst_equal (arg1
, arg2
);
7396 return arg1
== arg2
;
7400 /* Special case: if either target is an unallocated VAR_DECL,
7401 it means that it's going to be unified with whatever the
7402 TARGET_EXPR is really supposed to initialize, so treat it
7403 as being equivalent to anything. */
7404 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
7405 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
7406 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
7407 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
7408 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
7409 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
7412 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7417 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
7419 case WITH_CLEANUP_EXPR
:
7420 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7424 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
7427 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
7428 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7442 /* This general rule works for most tree codes. All exceptions should be
7443 handled above. If this is a language-specific tree code, we can't
7444 trust what might be in the operand, so say we don't know
7446 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
7449 switch (TREE_CODE_CLASS (code1
))
7453 case tcc_comparison
:
7454 case tcc_expression
:
7458 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
7460 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
7472 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7473 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7474 than U, respectively. */
7477 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
7479 if (tree_int_cst_sgn (t
) < 0)
7481 else if (!tree_fits_uhwi_p (t
))
7483 else if (TREE_INT_CST_LOW (t
) == u
)
7485 else if (TREE_INT_CST_LOW (t
) < u
)
7491 /* Return true if SIZE represents a constant size that is in bounds of
7492 what the middle-end and the backend accepts (covering not more than
7493 half of the address-space). */
7496 valid_constant_size_p (const_tree size
)
7498 if (! tree_fits_uhwi_p (size
)
7499 || TREE_OVERFLOW (size
)
7500 || tree_int_cst_sign_bit (size
) != 0)
7505 /* Return the precision of the type, or for a complex or vector type the
7506 precision of the type of its elements. */
7509 element_precision (const_tree type
)
7511 enum tree_code code
= TREE_CODE (type
);
7512 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7513 type
= TREE_TYPE (type
);
7515 return TYPE_PRECISION (type
);
7518 /* Return true if CODE represents an associative tree code. Otherwise
7521 associative_tree_code (enum tree_code code
)
7540 /* Return true if CODE represents a commutative tree code. Otherwise
7543 commutative_tree_code (enum tree_code code
)
7549 case MULT_HIGHPART_EXPR
:
7557 case UNORDERED_EXPR
:
7561 case TRUTH_AND_EXPR
:
7562 case TRUTH_XOR_EXPR
:
7564 case WIDEN_MULT_EXPR
:
7565 case VEC_WIDEN_MULT_HI_EXPR
:
7566 case VEC_WIDEN_MULT_LO_EXPR
:
7567 case VEC_WIDEN_MULT_EVEN_EXPR
:
7568 case VEC_WIDEN_MULT_ODD_EXPR
:
7577 /* Return true if CODE represents a ternary tree code for which the
7578 first two operands are commutative. Otherwise return false. */
7580 commutative_ternary_tree_code (enum tree_code code
)
7584 case WIDEN_MULT_PLUS_EXPR
:
7585 case WIDEN_MULT_MINUS_EXPR
:
7596 /* Returns true if CODE can overflow. */
7599 operation_can_overflow (enum tree_code code
)
7607 /* Can overflow in various ways. */
7609 case TRUNC_DIV_EXPR
:
7610 case EXACT_DIV_EXPR
:
7611 case FLOOR_DIV_EXPR
:
7613 /* For INT_MIN / -1. */
7620 /* These operators cannot overflow. */
7625 /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7626 ftrapv doesn't generate trapping insns for CODE. */
7629 operation_no_trapping_overflow (tree type
, enum tree_code code
)
7631 gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type
));
7633 /* We don't generate instructions that trap on overflow for complex or vector
7635 if (!INTEGRAL_TYPE_P (type
))
7638 if (!TYPE_OVERFLOW_TRAPS (type
))
7648 /* These operators can overflow, and -ftrapv generates trapping code for
7651 case TRUNC_DIV_EXPR
:
7652 case EXACT_DIV_EXPR
:
7653 case FLOOR_DIV_EXPR
:
7656 /* These operators can overflow, but -ftrapv does not generate trapping
7660 /* These operators cannot overflow. */
7668 /* Generate a hash value for an expression. This can be used iteratively
7669 by passing a previous result as the HSTATE argument.
7671 This function is intended to produce the same hash for expressions which
7672 would compare equal using operand_equal_p. */
7674 add_expr (const_tree t
, inchash::hash
&hstate
)
7677 enum tree_code code
;
7678 enum tree_code_class tclass
;
7682 hstate
.merge_hash (0);
7686 code
= TREE_CODE (t
);
7690 /* Alas, constants aren't shared, so we can't rely on pointer
7693 hstate
.merge_hash (0);
7696 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
7697 hstate
.add_wide_int (TREE_INT_CST_ELT (t
, i
));
7701 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
7702 hstate
.merge_hash (val2
);
7707 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
7708 hstate
.merge_hash (val2
);
7712 hstate
.add ((const void *) TREE_STRING_POINTER (t
), TREE_STRING_LENGTH (t
));
7715 inchash::add_expr (TREE_REALPART (t
), hstate
);
7716 inchash::add_expr (TREE_IMAGPART (t
), hstate
);
7721 for (i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
7722 inchash::add_expr (VECTOR_CST_ELT (t
, i
), hstate
);
7726 /* We can just compare by pointer. */
7727 hstate
.add_wide_int (SSA_NAME_VERSION (t
));
7729 case PLACEHOLDER_EXPR
:
7730 /* The node itself doesn't matter. */
7733 /* A list of expressions, for a CALL_EXPR or as the elements of a
7735 for (; t
; t
= TREE_CHAIN (t
))
7736 inchash::add_expr (TREE_VALUE (t
), hstate
);
7740 unsigned HOST_WIDE_INT idx
;
7742 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
7744 inchash::add_expr (field
, hstate
);
7745 inchash::add_expr (value
, hstate
);
7750 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7751 Otherwise nodes that compare equal according to operand_equal_p might
7752 get different hash codes. However, don't do this for machine specific
7753 or front end builtins, since the function code is overloaded in those
7755 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
7756 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t
)))
7758 t
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
7759 code
= TREE_CODE (t
);
7763 tclass
= TREE_CODE_CLASS (code
);
7765 if (tclass
== tcc_declaration
)
7767 /* DECL's have a unique ID */
7768 hstate
.add_wide_int (DECL_UID (t
));
7772 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
7774 hstate
.add_object (code
);
7776 /* Don't hash the type, that can lead to having nodes which
7777 compare equal according to operand_equal_p, but which
7778 have different hash codes. */
7779 if (CONVERT_EXPR_CODE_P (code
)
7780 || code
== NON_LVALUE_EXPR
)
7782 /* Make sure to include signness in the hash computation. */
7783 hstate
.add_int (TYPE_UNSIGNED (TREE_TYPE (t
)));
7784 inchash::add_expr (TREE_OPERAND (t
, 0), hstate
);
7787 else if (commutative_tree_code (code
))
7789 /* It's a commutative expression. We want to hash it the same
7790 however it appears. We do this by first hashing both operands
7791 and then rehashing based on the order of their independent
7793 inchash::hash one
, two
;
7794 inchash::add_expr (TREE_OPERAND (t
, 0), one
);
7795 inchash::add_expr (TREE_OPERAND (t
, 1), two
);
7796 hstate
.add_commutative (one
, two
);
7799 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
7800 inchash::add_expr (TREE_OPERAND (t
, i
), hstate
);
7808 /* Constructors for pointer, array and function types.
7809 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7810 constructed by language-dependent code, not here.) */
7812 /* Construct, lay out and return the type of pointers to TO_TYPE with
7813 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7814 reference all of memory. If such a type has already been
7815 constructed, reuse it. */
7818 build_pointer_type_for_mode (tree to_type
, machine_mode mode
,
7822 bool could_alias
= can_alias_all
;
7824 if (to_type
== error_mark_node
)
7825 return error_mark_node
;
7827 /* If the pointed-to type has the may_alias attribute set, force
7828 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7829 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7830 can_alias_all
= true;
7832 /* In some cases, languages will have things that aren't a POINTER_TYPE
7833 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7834 In that case, return that type without regard to the rest of our
7837 ??? This is a kludge, but consistent with the way this function has
7838 always operated and there doesn't seem to be a good way to avoid this
7840 if (TYPE_POINTER_TO (to_type
) != 0
7841 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7842 return TYPE_POINTER_TO (to_type
);
7844 /* First, if we already have a type for pointers to TO_TYPE and it's
7845 the proper mode, use it. */
7846 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7847 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7850 t
= make_node (POINTER_TYPE
);
7852 TREE_TYPE (t
) = to_type
;
7853 SET_TYPE_MODE (t
, mode
);
7854 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7855 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7856 TYPE_POINTER_TO (to_type
) = t
;
7858 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7859 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7860 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
7862 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7865 /* Lay out the type. This function has many callers that are concerned
7866 with expression-construction, and this simplifies them all. */
7872 /* By default build pointers in ptr_mode. */
7875 build_pointer_type (tree to_type
)
7877 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7878 : TYPE_ADDR_SPACE (to_type
);
7879 machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7880 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7883 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7886 build_reference_type_for_mode (tree to_type
, machine_mode mode
,
7890 bool could_alias
= can_alias_all
;
7892 if (to_type
== error_mark_node
)
7893 return error_mark_node
;
7895 /* If the pointed-to type has the may_alias attribute set, force
7896 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7897 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7898 can_alias_all
= true;
7900 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7901 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7902 In that case, return that type without regard to the rest of our
7905 ??? This is a kludge, but consistent with the way this function has
7906 always operated and there doesn't seem to be a good way to avoid this
7908 if (TYPE_REFERENCE_TO (to_type
) != 0
7909 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7910 return TYPE_REFERENCE_TO (to_type
);
7912 /* First, if we already have a type for pointers to TO_TYPE and it's
7913 the proper mode, use it. */
7914 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7915 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7918 t
= make_node (REFERENCE_TYPE
);
7920 TREE_TYPE (t
) = to_type
;
7921 SET_TYPE_MODE (t
, mode
);
7922 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7923 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7924 TYPE_REFERENCE_TO (to_type
) = t
;
7926 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7927 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7928 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
7930 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7939 /* Build the node for the type of references-to-TO_TYPE by default
7943 build_reference_type (tree to_type
)
7945 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7946 : TYPE_ADDR_SPACE (to_type
);
7947 machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7948 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7951 #define MAX_INT_CACHED_PREC \
7952 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7953 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7955 /* Builds a signed or unsigned integer type of precision PRECISION.
7956 Used for C bitfields whose precision does not match that of
7957 built-in target types. */
7959 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7965 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7967 if (precision
<= MAX_INT_CACHED_PREC
)
7969 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7974 itype
= make_node (INTEGER_TYPE
);
7975 TYPE_PRECISION (itype
) = precision
;
7978 fixup_unsigned_type (itype
);
7980 fixup_signed_type (itype
);
7983 if (tree_fits_uhwi_p (TYPE_MAX_VALUE (itype
)))
7984 ret
= type_hash_canon (tree_to_uhwi (TYPE_MAX_VALUE (itype
)), itype
);
7985 if (precision
<= MAX_INT_CACHED_PREC
)
7986 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7991 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7992 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7993 is true, reuse such a type that has already been constructed. */
7996 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7998 tree itype
= make_node (INTEGER_TYPE
);
7999 inchash::hash hstate
;
8001 TREE_TYPE (itype
) = type
;
8003 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
8004 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
8006 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
8007 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
8008 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
8009 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
8010 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
8011 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
8016 if ((TYPE_MIN_VALUE (itype
)
8017 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
8018 || (TYPE_MAX_VALUE (itype
)
8019 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
8021 /* Since we cannot reliably merge this type, we need to compare it using
8022 structural equality checks. */
8023 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
8027 inchash::add_expr (TYPE_MIN_VALUE (itype
), hstate
);
8028 inchash::add_expr (TYPE_MAX_VALUE (itype
), hstate
);
8029 hstate
.merge_hash (TYPE_HASH (type
));
8030 itype
= type_hash_canon (hstate
.end (), itype
);
8035 /* Wrapper around build_range_type_1 with SHARED set to true. */
8038 build_range_type (tree type
, tree lowval
, tree highval
)
8040 return build_range_type_1 (type
, lowval
, highval
, true);
8043 /* Wrapper around build_range_type_1 with SHARED set to false. */
8046 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
8048 return build_range_type_1 (type
, lowval
, highval
, false);
8051 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
8052 MAXVAL should be the maximum value in the domain
8053 (one less than the length of the array).
8055 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
8056 We don't enforce this limit, that is up to caller (e.g. language front end).
8057 The limit exists because the result is a signed type and we don't handle
8058 sizes that use more than one HOST_WIDE_INT. */
8061 build_index_type (tree maxval
)
8063 return build_range_type (sizetype
, size_zero_node
, maxval
);
8066 /* Return true if the debug information for TYPE, a subtype, should be emitted
8067 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
8068 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
8069 debug info and doesn't reflect the source code. */
8072 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
8074 tree base_type
= TREE_TYPE (type
), low
, high
;
8076 /* Subrange types have a base type which is an integral type. */
8077 if (!INTEGRAL_TYPE_P (base_type
))
8080 /* Get the real bounds of the subtype. */
8081 if (lang_hooks
.types
.get_subrange_bounds
)
8082 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
8085 low
= TYPE_MIN_VALUE (type
);
8086 high
= TYPE_MAX_VALUE (type
);
8089 /* If the type and its base type have the same representation and the same
8090 name, then the type is not a subrange but a copy of the base type. */
8091 if ((TREE_CODE (base_type
) == INTEGER_TYPE
8092 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
8093 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
8094 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
8095 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
))
8096 && TYPE_IDENTIFIER (type
) == TYPE_IDENTIFIER (base_type
))
8106 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
8107 and number of elements specified by the range of values of INDEX_TYPE.
8108 If SHARED is true, reuse such a type that has already been constructed. */
8111 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
8115 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
8117 error ("arrays of functions are not meaningful");
8118 elt_type
= integer_type_node
;
8121 t
= make_node (ARRAY_TYPE
);
8122 TREE_TYPE (t
) = elt_type
;
8123 TYPE_DOMAIN (t
) = index_type
;
8124 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
8127 /* If the element type is incomplete at this point we get marked for
8128 structural equality. Do not record these types in the canonical
8130 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
8135 inchash::hash hstate
;
8136 hstate
.add_object (TYPE_HASH (elt_type
));
8138 hstate
.add_object (TYPE_HASH (index_type
));
8139 t
= type_hash_canon (hstate
.end (), t
);
8142 if (TYPE_CANONICAL (t
) == t
)
8144 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
8145 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
8146 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8147 else if (TYPE_CANONICAL (elt_type
) != elt_type
8148 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
8150 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
8152 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
8159 /* Wrapper around build_array_type_1 with SHARED set to true. */
8162 build_array_type (tree elt_type
, tree index_type
)
8164 return build_array_type_1 (elt_type
, index_type
, true);
8167 /* Wrapper around build_array_type_1 with SHARED set to false. */
8170 build_nonshared_array_type (tree elt_type
, tree index_type
)
8172 return build_array_type_1 (elt_type
, index_type
, false);
8175 /* Return a representation of ELT_TYPE[NELTS], using indices of type
8179 build_array_type_nelts (tree elt_type
, unsigned HOST_WIDE_INT nelts
)
8181 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
8184 /* Recursively examines the array elements of TYPE, until a non-array
8185 element type is found. */
8188 strip_array_types (tree type
)
8190 while (TREE_CODE (type
) == ARRAY_TYPE
)
8191 type
= TREE_TYPE (type
);
8196 /* Computes the canonical argument types from the argument type list
8199 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
8200 on entry to this function, or if any of the ARGTYPES are
8203 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
8204 true on entry to this function, or if any of the ARGTYPES are
8207 Returns a canonical argument list, which may be ARGTYPES when the
8208 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
8209 true) or would not differ from ARGTYPES. */
8212 maybe_canonicalize_argtypes (tree argtypes
,
8213 bool *any_structural_p
,
8214 bool *any_noncanonical_p
)
8217 bool any_noncanonical_argtypes_p
= false;
8219 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
8221 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
8222 /* Fail gracefully by stating that the type is structural. */
8223 *any_structural_p
= true;
8224 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
8225 *any_structural_p
= true;
8226 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
8227 || TREE_PURPOSE (arg
))
8228 /* If the argument has a default argument, we consider it
8229 non-canonical even though the type itself is canonical.
8230 That way, different variants of function and method types
8231 with default arguments will all point to the variant with
8232 no defaults as their canonical type. */
8233 any_noncanonical_argtypes_p
= true;
8236 if (*any_structural_p
)
8239 if (any_noncanonical_argtypes_p
)
8241 /* Build the canonical list of argument types. */
8242 tree canon_argtypes
= NULL_TREE
;
8243 bool is_void
= false;
8245 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
8247 if (arg
== void_list_node
)
8250 canon_argtypes
= tree_cons (NULL_TREE
,
8251 TYPE_CANONICAL (TREE_VALUE (arg
)),
8255 canon_argtypes
= nreverse (canon_argtypes
);
8257 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
8259 /* There is a non-canonical type. */
8260 *any_noncanonical_p
= true;
8261 return canon_argtypes
;
8264 /* The canonical argument types are the same as ARGTYPES. */
8268 /* Construct, lay out and return
8269 the type of functions returning type VALUE_TYPE
8270 given arguments of types ARG_TYPES.
8271 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
8272 are data type nodes for the arguments of the function.
8273 If such a type has already been constructed, reuse it. */
8276 build_function_type (tree value_type
, tree arg_types
)
8279 inchash::hash hstate
;
8280 bool any_structural_p
, any_noncanonical_p
;
8281 tree canon_argtypes
;
8283 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
8285 error ("function return type cannot be function");
8286 value_type
= integer_type_node
;
8289 /* Make a node of the sort we want. */
8290 t
= make_node (FUNCTION_TYPE
);
8291 TREE_TYPE (t
) = value_type
;
8292 TYPE_ARG_TYPES (t
) = arg_types
;
8294 /* If we already have such a type, use the old one. */
8295 hstate
.add_object (TYPE_HASH (value_type
));
8296 type_hash_list (arg_types
, hstate
);
8297 t
= type_hash_canon (hstate
.end (), t
);
8299 /* Set up the canonical type. */
8300 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
8301 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
8302 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
8304 &any_noncanonical_p
);
8305 if (any_structural_p
)
8306 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8307 else if (any_noncanonical_p
)
8308 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
8311 if (!COMPLETE_TYPE_P (t
))
8316 /* Build a function type. The RETURN_TYPE is the type returned by the
8317 function. If VAARGS is set, no void_type_node is appended to the
8318 the list. ARGP must be always be terminated be a NULL_TREE. */
8321 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
8325 t
= va_arg (argp
, tree
);
8326 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
8327 args
= tree_cons (NULL_TREE
, t
, args
);
8332 if (args
!= NULL_TREE
)
8333 args
= nreverse (args
);
8334 gcc_assert (last
!= void_list_node
);
8336 else if (args
== NULL_TREE
)
8337 args
= void_list_node
;
8341 args
= nreverse (args
);
8342 TREE_CHAIN (last
) = void_list_node
;
8344 args
= build_function_type (return_type
, args
);
8349 /* Build a function type. The RETURN_TYPE is the type returned by the
8350 function. If additional arguments are provided, they are
8351 additional argument types. The list of argument types must always
8352 be terminated by NULL_TREE. */
8355 build_function_type_list (tree return_type
, ...)
8360 va_start (p
, return_type
);
8361 args
= build_function_type_list_1 (false, return_type
, p
);
8366 /* Build a variable argument function type. The RETURN_TYPE is the
8367 type returned by the function. If additional arguments are provided,
8368 they are additional argument types. The list of argument types must
8369 always be terminated by NULL_TREE. */
8372 build_varargs_function_type_list (tree return_type
, ...)
8377 va_start (p
, return_type
);
8378 args
= build_function_type_list_1 (true, return_type
, p
);
8384 /* Build a function type. RETURN_TYPE is the type returned by the
8385 function; VAARGS indicates whether the function takes varargs. The
8386 function takes N named arguments, the types of which are provided in
8390 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
8394 tree t
= vaargs
? NULL_TREE
: void_list_node
;
8396 for (i
= n
- 1; i
>= 0; i
--)
8397 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
8399 return build_function_type (return_type
, t
);
8402 /* Build a function type. RETURN_TYPE is the type returned by the
8403 function. The function takes N named arguments, the types of which
8404 are provided in ARG_TYPES. */
8407 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8409 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
8412 /* Build a variable argument function type. RETURN_TYPE is the type
8413 returned by the function. The function takes N named arguments, the
8414 types of which are provided in ARG_TYPES. */
8417 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8419 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
8422 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8423 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8424 for the method. An implicit additional parameter (of type
8425 pointer-to-BASETYPE) is added to the ARGTYPES. */
8428 build_method_type_directly (tree basetype
,
8434 inchash::hash hstate
;
8435 bool any_structural_p
, any_noncanonical_p
;
8436 tree canon_argtypes
;
8438 /* Make a node of the sort we want. */
8439 t
= make_node (METHOD_TYPE
);
8441 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8442 TREE_TYPE (t
) = rettype
;
8443 ptype
= build_pointer_type (basetype
);
8445 /* The actual arglist for this function includes a "hidden" argument
8446 which is "this". Put it into the list of argument types. */
8447 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
8448 TYPE_ARG_TYPES (t
) = argtypes
;
8450 /* If we already have such a type, use the old one. */
8451 hstate
.add_object (TYPE_HASH (basetype
));
8452 hstate
.add_object (TYPE_HASH (rettype
));
8453 type_hash_list (argtypes
, hstate
);
8454 t
= type_hash_canon (hstate
.end (), t
);
8456 /* Set up the canonical type. */
8458 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8459 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
8461 = (TYPE_CANONICAL (basetype
) != basetype
8462 || TYPE_CANONICAL (rettype
) != rettype
);
8463 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
8465 &any_noncanonical_p
);
8466 if (any_structural_p
)
8467 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8468 else if (any_noncanonical_p
)
8470 = build_method_type_directly (TYPE_CANONICAL (basetype
),
8471 TYPE_CANONICAL (rettype
),
8473 if (!COMPLETE_TYPE_P (t
))
8479 /* Construct, lay out and return the type of methods belonging to class
8480 BASETYPE and whose arguments and values are described by TYPE.
8481 If that type exists already, reuse it.
8482 TYPE must be a FUNCTION_TYPE node. */
8485 build_method_type (tree basetype
, tree type
)
8487 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
8489 return build_method_type_directly (basetype
,
8491 TYPE_ARG_TYPES (type
));
8494 /* Construct, lay out and return the type of offsets to a value
8495 of type TYPE, within an object of type BASETYPE.
8496 If a suitable offset type exists already, reuse it. */
8499 build_offset_type (tree basetype
, tree type
)
8502 inchash::hash hstate
;
8504 /* Make a node of the sort we want. */
8505 t
= make_node (OFFSET_TYPE
);
8507 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8508 TREE_TYPE (t
) = type
;
8510 /* If we already have such a type, use the old one. */
8511 hstate
.add_object (TYPE_HASH (basetype
));
8512 hstate
.add_object (TYPE_HASH (type
));
8513 t
= type_hash_canon (hstate
.end (), t
);
8515 if (!COMPLETE_TYPE_P (t
))
8518 if (TYPE_CANONICAL (t
) == t
)
8520 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8521 || TYPE_STRUCTURAL_EQUALITY_P (type
))
8522 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8523 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
8524 || TYPE_CANONICAL (type
) != type
)
8526 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
8527 TYPE_CANONICAL (type
));
8533 /* Create a complex type whose components are COMPONENT_TYPE. */
8536 build_complex_type (tree component_type
)
8539 inchash::hash hstate
;
8541 gcc_assert (INTEGRAL_TYPE_P (component_type
)
8542 || SCALAR_FLOAT_TYPE_P (component_type
)
8543 || FIXED_POINT_TYPE_P (component_type
));
8545 /* Make a node of the sort we want. */
8546 t
= make_node (COMPLEX_TYPE
);
8548 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
8550 /* If we already have such a type, use the old one. */
8551 hstate
.add_object (TYPE_HASH (component_type
));
8552 t
= type_hash_canon (hstate
.end (), t
);
8554 if (!COMPLETE_TYPE_P (t
))
8557 if (TYPE_CANONICAL (t
) == t
)
8559 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
8560 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8561 else if (TYPE_CANONICAL (component_type
) != component_type
)
8563 = build_complex_type (TYPE_CANONICAL (component_type
));
8566 /* We need to create a name, since complex is a fundamental type. */
8567 if (! TYPE_NAME (t
))
8570 if (component_type
== char_type_node
)
8571 name
= "complex char";
8572 else if (component_type
== signed_char_type_node
)
8573 name
= "complex signed char";
8574 else if (component_type
== unsigned_char_type_node
)
8575 name
= "complex unsigned char";
8576 else if (component_type
== short_integer_type_node
)
8577 name
= "complex short int";
8578 else if (component_type
== short_unsigned_type_node
)
8579 name
= "complex short unsigned int";
8580 else if (component_type
== integer_type_node
)
8581 name
= "complex int";
8582 else if (component_type
== unsigned_type_node
)
8583 name
= "complex unsigned int";
8584 else if (component_type
== long_integer_type_node
)
8585 name
= "complex long int";
8586 else if (component_type
== long_unsigned_type_node
)
8587 name
= "complex long unsigned int";
8588 else if (component_type
== long_long_integer_type_node
)
8589 name
= "complex long long int";
8590 else if (component_type
== long_long_unsigned_type_node
)
8591 name
= "complex long long unsigned int";
8596 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
8597 get_identifier (name
), t
);
8600 return build_qualified_type (t
, TYPE_QUALS (component_type
));
8603 /* If TYPE is a real or complex floating-point type and the target
8604 does not directly support arithmetic on TYPE then return the wider
8605 type to be used for arithmetic on TYPE. Otherwise, return
8609 excess_precision_type (tree type
)
8611 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
8613 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
8614 switch (TREE_CODE (type
))
8617 switch (flt_eval_method
)
8620 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
8621 return double_type_node
;
8624 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
8625 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
8626 return long_double_type_node
;
8633 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
8635 switch (flt_eval_method
)
8638 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
8639 return complex_double_type_node
;
8642 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
8643 || (TYPE_MODE (TREE_TYPE (type
))
8644 == TYPE_MODE (double_type_node
)))
8645 return complex_long_double_type_node
;
8658 /* Return OP, stripped of any conversions to wider types as much as is safe.
8659 Converting the value back to OP's type makes a value equivalent to OP.
8661 If FOR_TYPE is nonzero, we return a value which, if converted to
8662 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8664 OP must have integer, real or enumeral type. Pointers are not allowed!
8666 There are some cases where the obvious value we could return
8667 would regenerate to OP if converted to OP's type,
8668 but would not extend like OP to wider types.
8669 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8670 For example, if OP is (unsigned short)(signed char)-1,
8671 we avoid returning (signed char)-1 if FOR_TYPE is int,
8672 even though extending that to an unsigned short would regenerate OP,
8673 since the result of extending (signed char)-1 to (int)
8674 is different from (int) OP. */
8677 get_unwidened (tree op
, tree for_type
)
8679 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8680 tree type
= TREE_TYPE (op
);
8682 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
8684 = (for_type
!= 0 && for_type
!= type
8685 && final_prec
> TYPE_PRECISION (type
)
8686 && TYPE_UNSIGNED (type
));
8689 while (CONVERT_EXPR_P (op
))
8693 /* TYPE_PRECISION on vector types has different meaning
8694 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8695 so avoid them here. */
8696 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
8699 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
8700 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
8702 /* Truncations are many-one so cannot be removed.
8703 Unless we are later going to truncate down even farther. */
8705 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
8708 /* See what's inside this conversion. If we decide to strip it,
8710 op
= TREE_OPERAND (op
, 0);
8712 /* If we have not stripped any zero-extensions (uns is 0),
8713 we can strip any kind of extension.
8714 If we have previously stripped a zero-extension,
8715 only zero-extensions can safely be stripped.
8716 Any extension can be stripped if the bits it would produce
8717 are all going to be discarded later by truncating to FOR_TYPE. */
8721 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
8723 /* TYPE_UNSIGNED says whether this is a zero-extension.
8724 Let's avoid computing it if it does not affect WIN
8725 and if UNS will not be needed again. */
8727 || CONVERT_EXPR_P (op
))
8728 && TYPE_UNSIGNED (TREE_TYPE (op
)))
8736 /* If we finally reach a constant see if it fits in for_type and
8737 in that case convert it. */
8739 && TREE_CODE (win
) == INTEGER_CST
8740 && TREE_TYPE (win
) != for_type
8741 && int_fits_type_p (win
, for_type
))
8742 win
= fold_convert (for_type
, win
);
8747 /* Return OP or a simpler expression for a narrower value
8748 which can be sign-extended or zero-extended to give back OP.
8749 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8750 or 0 if the value should be sign-extended. */
8753 get_narrower (tree op
, int *unsignedp_ptr
)
8758 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8760 while (TREE_CODE (op
) == NOP_EXPR
)
8763 = (TYPE_PRECISION (TREE_TYPE (op
))
8764 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8766 /* Truncations are many-one so cannot be removed. */
8770 /* See what's inside this conversion. If we decide to strip it,
8775 op
= TREE_OPERAND (op
, 0);
8776 /* An extension: the outermost one can be stripped,
8777 but remember whether it is zero or sign extension. */
8779 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8780 /* Otherwise, if a sign extension has been stripped,
8781 only sign extensions can now be stripped;
8782 if a zero extension has been stripped, only zero-extensions. */
8783 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8787 else /* bitschange == 0 */
8789 /* A change in nominal type can always be stripped, but we must
8790 preserve the unsignedness. */
8792 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8794 op
= TREE_OPERAND (op
, 0);
8795 /* Keep trying to narrow, but don't assign op to win if it
8796 would turn an integral type into something else. */
8797 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8804 if (TREE_CODE (op
) == COMPONENT_REF
8805 /* Since type_for_size always gives an integer type. */
8806 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8807 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8808 /* Ensure field is laid out already. */
8809 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8810 && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op
, 1))))
8812 unsigned HOST_WIDE_INT innerprec
8813 = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op
, 1)));
8814 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8815 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8816 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8818 /* We can get this structure field in a narrower type that fits it,
8819 but the resulting extension to its nominal type (a fullword type)
8820 must satisfy the same conditions as for other extensions.
8822 Do this only for fields that are aligned (not bit-fields),
8823 because when bit-field insns will be used there is no
8824 advantage in doing this. */
8826 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8827 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8828 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8832 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8833 win
= fold_convert (type
, op
);
8837 *unsignedp_ptr
= uns
;
8841 /* Returns true if integer constant C has a value that is permissible
8842 for type TYPE (an INTEGER_TYPE). */
8845 int_fits_type_p (const_tree c
, const_tree type
)
8847 tree type_low_bound
, type_high_bound
;
8848 bool ok_for_low_bound
, ok_for_high_bound
;
8849 signop sgn_c
= TYPE_SIGN (TREE_TYPE (c
));
8852 type_low_bound
= TYPE_MIN_VALUE (type
);
8853 type_high_bound
= TYPE_MAX_VALUE (type
);
8855 /* If at least one bound of the type is a constant integer, we can check
8856 ourselves and maybe make a decision. If no such decision is possible, but
8857 this type is a subtype, try checking against that. Otherwise, use
8858 fits_to_tree_p, which checks against the precision.
8860 Compute the status for each possibly constant bound, and return if we see
8861 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8862 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8863 for "constant known to fit". */
8865 /* Check if c >= type_low_bound. */
8866 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8868 if (tree_int_cst_lt (c
, type_low_bound
))
8870 ok_for_low_bound
= true;
8873 ok_for_low_bound
= false;
8875 /* Check if c <= type_high_bound. */
8876 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8878 if (tree_int_cst_lt (type_high_bound
, c
))
8880 ok_for_high_bound
= true;
8883 ok_for_high_bound
= false;
8885 /* If the constant fits both bounds, the result is known. */
8886 if (ok_for_low_bound
&& ok_for_high_bound
)
8889 /* Perform some generic filtering which may allow making a decision
8890 even if the bounds are not constant. First, negative integers
8891 never fit in unsigned types, */
8892 if (TYPE_UNSIGNED (type
) && sgn_c
== SIGNED
&& wi::neg_p (c
))
8895 /* Second, narrower types always fit in wider ones. */
8896 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8899 /* Third, unsigned integers with top bit set never fit signed types. */
8900 if (!TYPE_UNSIGNED (type
) && sgn_c
== UNSIGNED
)
8902 int prec
= GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (c
))) - 1;
8903 if (prec
< TYPE_PRECISION (TREE_TYPE (c
)))
8905 /* When a tree_cst is converted to a wide-int, the precision
8906 is taken from the type. However, if the precision of the
8907 mode underneath the type is smaller than that, it is
8908 possible that the value will not fit. The test below
8909 fails if any bit is set between the sign bit of the
8910 underlying mode and the top bit of the type. */
8911 if (wi::ne_p (wi::zext (c
, prec
- 1), c
))
8914 else if (wi::neg_p (c
))
8918 /* If we haven't been able to decide at this point, there nothing more we
8919 can check ourselves here. Look at the base type if we have one and it
8920 has the same precision. */
8921 if (TREE_CODE (type
) == INTEGER_TYPE
8922 && TREE_TYPE (type
) != 0
8923 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8925 type
= TREE_TYPE (type
);
8929 /* Or to fits_to_tree_p, if nothing else. */
8930 return wi::fits_to_tree_p (c
, type
);
8933 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8934 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8935 represented (assuming two's-complement arithmetic) within the bit
8936 precision of the type are returned instead. */
8939 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8941 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8942 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8943 wi::to_mpz (TYPE_MIN_VALUE (type
), min
, TYPE_SIGN (type
));
8946 if (TYPE_UNSIGNED (type
))
8947 mpz_set_ui (min
, 0);
8950 wide_int mn
= wi::min_value (TYPE_PRECISION (type
), SIGNED
);
8951 wi::to_mpz (mn
, min
, SIGNED
);
8955 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8956 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8957 wi::to_mpz (TYPE_MAX_VALUE (type
), max
, TYPE_SIGN (type
));
8960 wide_int mn
= wi::max_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
8961 wi::to_mpz (mn
, max
, TYPE_SIGN (type
));
8965 /* Return true if VAR is an automatic variable defined in function FN. */
8968 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8970 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8971 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8972 || TREE_CODE (var
) == PARM_DECL
)
8973 && ! TREE_STATIC (var
))
8974 || TREE_CODE (var
) == LABEL_DECL
8975 || TREE_CODE (var
) == RESULT_DECL
));
8978 /* Subprogram of following function. Called by walk_tree.
8980 Return *TP if it is an automatic variable or parameter of the
8981 function passed in as DATA. */
8984 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8986 tree fn
= (tree
) data
;
8991 else if (DECL_P (*tp
)
8992 && auto_var_in_fn_p (*tp
, fn
))
8998 /* Returns true if T is, contains, or refers to a type with variable
8999 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
9000 arguments, but not the return type. If FN is nonzero, only return
9001 true if a modifier of the type or position of FN is a variable or
9002 parameter inside FN.
9004 This concept is more general than that of C99 'variably modified types':
9005 in C99, a struct type is never variably modified because a VLA may not
9006 appear as a structure member. However, in GNU C code like:
9008 struct S { int i[f()]; };
9010 is valid, and other languages may define similar constructs. */
9013 variably_modified_type_p (tree type
, tree fn
)
9017 /* Test if T is either variable (if FN is zero) or an expression containing
9018 a variable in FN. If TYPE isn't gimplified, return true also if
9019 gimplify_one_sizepos would gimplify the expression into a local
9021 #define RETURN_TRUE_IF_VAR(T) \
9022 do { tree _t = (T); \
9023 if (_t != NULL_TREE \
9024 && _t != error_mark_node \
9025 && TREE_CODE (_t) != INTEGER_CST \
9026 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
9028 || (!TYPE_SIZES_GIMPLIFIED (type) \
9029 && !is_gimple_sizepos (_t)) \
9030 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
9031 return true; } while (0)
9033 if (type
== error_mark_node
)
9036 /* If TYPE itself has variable size, it is variably modified. */
9037 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
9038 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
9040 switch (TREE_CODE (type
))
9043 case REFERENCE_TYPE
:
9045 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
9051 /* If TYPE is a function type, it is variably modified if the
9052 return type is variably modified. */
9053 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
9059 case FIXED_POINT_TYPE
:
9062 /* Scalar types are variably modified if their end points
9064 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
9065 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
9070 case QUAL_UNION_TYPE
:
9071 /* We can't see if any of the fields are variably-modified by the
9072 definition we normally use, since that would produce infinite
9073 recursion via pointers. */
9074 /* This is variably modified if some field's type is. */
9075 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
9076 if (TREE_CODE (t
) == FIELD_DECL
)
9078 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
9079 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
9080 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
9082 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
9083 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
9088 /* Do not call ourselves to avoid infinite recursion. This is
9089 variably modified if the element type is. */
9090 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
9091 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
9098 /* The current language may have other cases to check, but in general,
9099 all other types are not variably modified. */
9100 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
9102 #undef RETURN_TRUE_IF_VAR
9105 /* Given a DECL or TYPE, return the scope in which it was declared, or
9106 NULL_TREE if there is no containing scope. */
9109 get_containing_scope (const_tree t
)
9111 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
9114 /* Return the innermost context enclosing DECL that is
9115 a FUNCTION_DECL, or zero if none. */
9118 decl_function_context (const_tree decl
)
9122 if (TREE_CODE (decl
) == ERROR_MARK
)
9125 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
9126 where we look up the function at runtime. Such functions always take
9127 a first argument of type 'pointer to real context'.
9129 C++ should really be fixed to use DECL_CONTEXT for the real context,
9130 and use something else for the "virtual context". */
9131 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
9134 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
9136 context
= DECL_CONTEXT (decl
);
9138 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
9140 if (TREE_CODE (context
) == BLOCK
)
9141 context
= BLOCK_SUPERCONTEXT (context
);
9143 context
= get_containing_scope (context
);
9149 /* Return the innermost context enclosing DECL that is
9150 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
9151 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
9154 decl_type_context (const_tree decl
)
9156 tree context
= DECL_CONTEXT (decl
);
9159 switch (TREE_CODE (context
))
9161 case NAMESPACE_DECL
:
9162 case TRANSLATION_UNIT_DECL
:
9167 case QUAL_UNION_TYPE
:
9172 context
= DECL_CONTEXT (context
);
9176 context
= BLOCK_SUPERCONTEXT (context
);
9186 /* CALL is a CALL_EXPR. Return the declaration for the function
9187 called, or NULL_TREE if the called function cannot be
9191 get_callee_fndecl (const_tree call
)
9195 if (call
== error_mark_node
)
9196 return error_mark_node
;
9198 /* It's invalid to call this function with anything but a
9200 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
9202 /* The first operand to the CALL is the address of the function
9204 addr
= CALL_EXPR_FN (call
);
9206 /* If there is no function, return early. */
9207 if (addr
== NULL_TREE
)
9212 /* If this is a readonly function pointer, extract its initial value. */
9213 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
9214 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
9215 && DECL_INITIAL (addr
))
9216 addr
= DECL_INITIAL (addr
);
9218 /* If the address is just `&f' for some function `f', then we know
9219 that `f' is being called. */
9220 if (TREE_CODE (addr
) == ADDR_EXPR
9221 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
9222 return TREE_OPERAND (addr
, 0);
9224 /* We couldn't figure out what was being called. */
9228 #define TREE_MEM_USAGE_SPACES 40
9230 /* Print debugging information about tree nodes generated during the compile,
9231 and any language-specific information. */
9234 dump_tree_statistics (void)
9236 if (GATHER_STATISTICS
)
9239 int total_nodes
, total_bytes
;
9240 fprintf (stderr
, "\nKind Nodes Bytes\n");
9241 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9242 total_nodes
= total_bytes
= 0;
9243 for (i
= 0; i
< (int) all_kinds
; i
++)
9245 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
9246 tree_node_counts
[i
], tree_node_sizes
[i
]);
9247 total_nodes
+= tree_node_counts
[i
];
9248 total_bytes
+= tree_node_sizes
[i
];
9250 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9251 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
9252 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9253 fprintf (stderr
, "Code Nodes\n");
9254 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9255 for (i
= 0; i
< (int) MAX_TREE_CODES
; i
++)
9256 fprintf (stderr
, "%-32s %7d\n", get_tree_code_name ((enum tree_code
) i
),
9257 tree_code_counts
[i
]);
9258 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9259 fprintf (stderr
, "\n");
9260 ssanames_print_statistics ();
9261 fprintf (stderr
, "\n");
9262 phinodes_print_statistics ();
9263 fprintf (stderr
, "\n");
9266 fprintf (stderr
, "(No per-node statistics)\n");
9268 print_type_hash_statistics ();
9269 print_debug_expr_statistics ();
9270 print_value_expr_statistics ();
9271 lang_hooks
.print_statistics ();
9274 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9276 /* Generate a crc32 of a byte. */
9279 crc32_unsigned_bits (unsigned chksum
, unsigned value
, unsigned bits
)
9283 for (ix
= bits
; ix
--; value
<<= 1)
9287 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
9294 /* Generate a crc32 of a 32-bit unsigned. */
9297 crc32_unsigned (unsigned chksum
, unsigned value
)
9299 return crc32_unsigned_bits (chksum
, value
, 32);
9302 /* Generate a crc32 of a byte. */
9305 crc32_byte (unsigned chksum
, char byte
)
9307 return crc32_unsigned_bits (chksum
, (unsigned) byte
<< 24, 8);
9310 /* Generate a crc32 of a string. */
9313 crc32_string (unsigned chksum
, const char *string
)
9317 chksum
= crc32_byte (chksum
, *string
);
9323 /* P is a string that will be used in a symbol. Mask out any characters
9324 that are not valid in that context. */
9327 clean_symbol_name (char *p
)
9331 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9334 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9341 /* For anonymous aggregate types, we need some sort of name to
9342 hold on to. In practice, this should not appear, but it should
9343 not be harmful if it does. */
9345 anon_aggrname_p(const_tree id_node
)
9347 #ifndef NO_DOT_IN_LABEL
9348 return (IDENTIFIER_POINTER (id_node
)[0] == '.'
9349 && IDENTIFIER_POINTER (id_node
)[1] == '_');
9350 #else /* NO_DOT_IN_LABEL */
9351 #ifndef NO_DOLLAR_IN_LABEL
9352 return (IDENTIFIER_POINTER (id_node
)[0] == '$' \
9353 && IDENTIFIER_POINTER (id_node
)[1] == '_');
9354 #else /* NO_DOLLAR_IN_LABEL */
9355 #define ANON_AGGRNAME_PREFIX "__anon_"
9356 return (!strncmp (IDENTIFIER_POINTER (id_node
), ANON_AGGRNAME_PREFIX
,
9357 sizeof (ANON_AGGRNAME_PREFIX
) - 1));
9358 #endif /* NO_DOLLAR_IN_LABEL */
9359 #endif /* NO_DOT_IN_LABEL */
9362 /* Return a format for an anonymous aggregate name. */
9364 anon_aggrname_format()
9366 #ifndef NO_DOT_IN_LABEL
9368 #else /* NO_DOT_IN_LABEL */
9369 #ifndef NO_DOLLAR_IN_LABEL
9371 #else /* NO_DOLLAR_IN_LABEL */
9373 #endif /* NO_DOLLAR_IN_LABEL */
9374 #endif /* NO_DOT_IN_LABEL */
9377 /* Generate a name for a special-purpose function.
9378 The generated name may need to be unique across the whole link.
9379 Changes to this function may also require corresponding changes to
9380 xstrdup_mask_random.
9381 TYPE is some string to identify the purpose of this function to the
9382 linker or collect2; it must start with an uppercase letter,
9384 I - for constructors
9386 N - for C++ anonymous namespaces
9387 F - for DWARF unwind frame information. */
9390 get_file_function_name (const char *type
)
9396 /* If we already have a name we know to be unique, just use that. */
9397 if (first_global_object_name
)
9398 p
= q
= ASTRDUP (first_global_object_name
);
9399 /* If the target is handling the constructors/destructors, they
9400 will be local to this file and the name is only necessary for
9402 We also assign sub_I and sub_D sufixes to constructors called from
9403 the global static constructors. These are always local. */
9404 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
9405 || (strncmp (type
, "sub_", 4) == 0
9406 && (type
[4] == 'I' || type
[4] == 'D')))
9408 const char *file
= main_input_filename
;
9410 file
= LOCATION_FILE (input_location
);
9411 /* Just use the file's basename, because the full pathname
9412 might be quite long. */
9413 p
= q
= ASTRDUP (lbasename (file
));
9417 /* Otherwise, the name must be unique across the entire link.
9418 We don't have anything that we know to be unique to this translation
9419 unit, so use what we do have and throw in some randomness. */
9421 const char *name
= weak_global_object_name
;
9422 const char *file
= main_input_filename
;
9427 file
= LOCATION_FILE (input_location
);
9429 len
= strlen (file
);
9430 q
= (char *) alloca (9 + 17 + len
+ 1);
9431 memcpy (q
, file
, len
+ 1);
9433 snprintf (q
+ len
, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
9434 crc32_string (0, name
), get_random_seed (false));
9439 clean_symbol_name (q
);
9440 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
9443 /* Set up the name of the file-level functions we may need.
9444 Use a global object (which is already required to be unique over
9445 the program) rather than the file name (which imposes extra
9447 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
9449 return get_identifier (buf
);
9452 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9454 /* Complain that the tree code of NODE does not match the expected 0
9455 terminated list of trailing codes. The trailing code list can be
9456 empty, for a more vague error message. FILE, LINE, and FUNCTION
9457 are of the caller. */
9460 tree_check_failed (const_tree node
, const char *file
,
9461 int line
, const char *function
, ...)
9465 unsigned length
= 0;
9466 enum tree_code code
;
9468 va_start (args
, function
);
9469 while ((code
= (enum tree_code
) va_arg (args
, int)))
9470 length
+= 4 + strlen (get_tree_code_name (code
));
9475 va_start (args
, function
);
9476 length
+= strlen ("expected ");
9477 buffer
= tmp
= (char *) alloca (length
);
9479 while ((code
= (enum tree_code
) va_arg (args
, int)))
9481 const char *prefix
= length
? " or " : "expected ";
9483 strcpy (tmp
+ length
, prefix
);
9484 length
+= strlen (prefix
);
9485 strcpy (tmp
+ length
, get_tree_code_name (code
));
9486 length
+= strlen (get_tree_code_name (code
));
9491 buffer
= "unexpected node";
9493 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9494 buffer
, get_tree_code_name (TREE_CODE (node
)),
9495 function
, trim_filename (file
), line
);
9498 /* Complain that the tree code of NODE does match the expected 0
9499 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9503 tree_not_check_failed (const_tree node
, const char *file
,
9504 int line
, const char *function
, ...)
9508 unsigned length
= 0;
9509 enum tree_code code
;
9511 va_start (args
, function
);
9512 while ((code
= (enum tree_code
) va_arg (args
, int)))
9513 length
+= 4 + strlen (get_tree_code_name (code
));
9515 va_start (args
, function
);
9516 buffer
= (char *) alloca (length
);
9518 while ((code
= (enum tree_code
) va_arg (args
, int)))
9522 strcpy (buffer
+ length
, " or ");
9525 strcpy (buffer
+ length
, get_tree_code_name (code
));
9526 length
+= strlen (get_tree_code_name (code
));
9530 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9531 buffer
, get_tree_code_name (TREE_CODE (node
)),
9532 function
, trim_filename (file
), line
);
9535 /* Similar to tree_check_failed, except that we check for a class of tree
9536 code, given in CL. */
9539 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9540 const char *file
, int line
, const char *function
)
9543 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9544 TREE_CODE_CLASS_STRING (cl
),
9545 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9546 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9549 /* Similar to tree_check_failed, except that instead of specifying a
9550 dozen codes, use the knowledge that they're all sequential. */
9553 tree_range_check_failed (const_tree node
, const char *file
, int line
,
9554 const char *function
, enum tree_code c1
,
9558 unsigned length
= 0;
9561 for (c
= c1
; c
<= c2
; ++c
)
9562 length
+= 4 + strlen (get_tree_code_name ((enum tree_code
) c
));
9564 length
+= strlen ("expected ");
9565 buffer
= (char *) alloca (length
);
9568 for (c
= c1
; c
<= c2
; ++c
)
9570 const char *prefix
= length
? " or " : "expected ";
9572 strcpy (buffer
+ length
, prefix
);
9573 length
+= strlen (prefix
);
9574 strcpy (buffer
+ length
, get_tree_code_name ((enum tree_code
) c
));
9575 length
+= strlen (get_tree_code_name ((enum tree_code
) c
));
9578 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9579 buffer
, get_tree_code_name (TREE_CODE (node
)),
9580 function
, trim_filename (file
), line
);
9584 /* Similar to tree_check_failed, except that we check that a tree does
9585 not have the specified code, given in CL. */
9588 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9589 const char *file
, int line
, const char *function
)
9592 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9593 TREE_CODE_CLASS_STRING (cl
),
9594 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9595 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9599 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9602 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
9603 const char *function
, enum omp_clause_code code
)
9605 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9606 omp_clause_code_name
[code
], get_tree_code_name (TREE_CODE (node
)),
9607 function
, trim_filename (file
), line
);
9611 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9614 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
9615 const char *function
, enum omp_clause_code c1
,
9616 enum omp_clause_code c2
)
9619 unsigned length
= 0;
9622 for (c
= c1
; c
<= c2
; ++c
)
9623 length
+= 4 + strlen (omp_clause_code_name
[c
]);
9625 length
+= strlen ("expected ");
9626 buffer
= (char *) alloca (length
);
9629 for (c
= c1
; c
<= c2
; ++c
)
9631 const char *prefix
= length
? " or " : "expected ";
9633 strcpy (buffer
+ length
, prefix
);
9634 length
+= strlen (prefix
);
9635 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
9636 length
+= strlen (omp_clause_code_name
[c
]);
9639 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9640 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
9641 function
, trim_filename (file
), line
);
9645 #undef DEFTREESTRUCT
9646 #define DEFTREESTRUCT(VAL, NAME) NAME,
9648 static const char *ts_enum_names
[] = {
9649 #include "treestruct.def"
9651 #undef DEFTREESTRUCT
9653 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9655 /* Similar to tree_class_check_failed, except that we check for
9656 whether CODE contains the tree structure identified by EN. */
9659 tree_contains_struct_check_failed (const_tree node
,
9660 const enum tree_node_structure_enum en
,
9661 const char *file
, int line
,
9662 const char *function
)
9665 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9667 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9671 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9672 (dynamically sized) vector. */
9675 tree_int_cst_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9676 const char *function
)
9679 ("tree check: accessed elt %d of tree_int_cst with %d elts in %s, at %s:%d",
9680 idx
+ 1, len
, function
, trim_filename (file
), line
);
9683 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9684 (dynamically sized) vector. */
9687 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9688 const char *function
)
9691 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9692 idx
+ 1, len
, function
, trim_filename (file
), line
);
9695 /* Similar to above, except that the check is for the bounds of the operand
9696 vector of an expression node EXP. */
9699 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
9700 int line
, const char *function
)
9702 enum tree_code code
= TREE_CODE (exp
);
9704 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9705 idx
+ 1, get_tree_code_name (code
), TREE_OPERAND_LENGTH (exp
),
9706 function
, trim_filename (file
), line
);
9709 /* Similar to above, except that the check is for the number of
9710 operands of an OMP_CLAUSE node. */
9713 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
9714 int line
, const char *function
)
9717 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9718 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
9719 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
9720 trim_filename (file
), line
);
9722 #endif /* ENABLE_TREE_CHECKING */
9724 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9725 and mapped to the machine mode MODE. Initialize its fields and build
9726 the information necessary for debugging output. */
9729 make_vector_type (tree innertype
, int nunits
, machine_mode mode
)
9732 inchash::hash hstate
;
9734 t
= make_node (VECTOR_TYPE
);
9735 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
9736 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
9737 SET_TYPE_MODE (t
, mode
);
9739 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
9740 SET_TYPE_STRUCTURAL_EQUALITY (t
);
9741 else if (TYPE_CANONICAL (innertype
) != innertype
9742 || mode
!= VOIDmode
)
9744 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
9748 hstate
.add_wide_int (VECTOR_TYPE
);
9749 hstate
.add_wide_int (nunits
);
9750 hstate
.add_wide_int (mode
);
9751 hstate
.add_object (TYPE_HASH (TREE_TYPE (t
)));
9752 t
= type_hash_canon (hstate
.end (), t
);
9754 /* We have built a main variant, based on the main variant of the
9755 inner type. Use it to build the variant we return. */
9756 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
9757 && TREE_TYPE (t
) != innertype
)
9758 return build_type_attribute_qual_variant (t
,
9759 TYPE_ATTRIBUTES (innertype
),
9760 TYPE_QUALS (innertype
));
9766 make_or_reuse_type (unsigned size
, int unsignedp
)
9770 if (size
== INT_TYPE_SIZE
)
9771 return unsignedp
? unsigned_type_node
: integer_type_node
;
9772 if (size
== CHAR_TYPE_SIZE
)
9773 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
9774 if (size
== SHORT_TYPE_SIZE
)
9775 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
9776 if (size
== LONG_TYPE_SIZE
)
9777 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
9778 if (size
== LONG_LONG_TYPE_SIZE
)
9779 return (unsignedp
? long_long_unsigned_type_node
9780 : long_long_integer_type_node
);
9782 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9783 if (size
== int_n_data
[i
].bitsize
9784 && int_n_enabled_p
[i
])
9785 return (unsignedp
? int_n_trees
[i
].unsigned_type
9786 : int_n_trees
[i
].signed_type
);
9789 return make_unsigned_type (size
);
9791 return make_signed_type (size
);
9794 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9797 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
9801 if (size
== SHORT_FRACT_TYPE_SIZE
)
9802 return unsignedp
? sat_unsigned_short_fract_type_node
9803 : sat_short_fract_type_node
;
9804 if (size
== FRACT_TYPE_SIZE
)
9805 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9806 if (size
== LONG_FRACT_TYPE_SIZE
)
9807 return unsignedp
? sat_unsigned_long_fract_type_node
9808 : sat_long_fract_type_node
;
9809 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9810 return unsignedp
? sat_unsigned_long_long_fract_type_node
9811 : sat_long_long_fract_type_node
;
9815 if (size
== SHORT_FRACT_TYPE_SIZE
)
9816 return unsignedp
? unsigned_short_fract_type_node
9817 : short_fract_type_node
;
9818 if (size
== FRACT_TYPE_SIZE
)
9819 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9820 if (size
== LONG_FRACT_TYPE_SIZE
)
9821 return unsignedp
? unsigned_long_fract_type_node
9822 : long_fract_type_node
;
9823 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9824 return unsignedp
? unsigned_long_long_fract_type_node
9825 : long_long_fract_type_node
;
9828 return make_fract_type (size
, unsignedp
, satp
);
9831 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9834 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9838 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9839 return unsignedp
? sat_unsigned_short_accum_type_node
9840 : sat_short_accum_type_node
;
9841 if (size
== ACCUM_TYPE_SIZE
)
9842 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9843 if (size
== LONG_ACCUM_TYPE_SIZE
)
9844 return unsignedp
? sat_unsigned_long_accum_type_node
9845 : sat_long_accum_type_node
;
9846 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9847 return unsignedp
? sat_unsigned_long_long_accum_type_node
9848 : sat_long_long_accum_type_node
;
9852 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9853 return unsignedp
? unsigned_short_accum_type_node
9854 : short_accum_type_node
;
9855 if (size
== ACCUM_TYPE_SIZE
)
9856 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9857 if (size
== LONG_ACCUM_TYPE_SIZE
)
9858 return unsignedp
? unsigned_long_accum_type_node
9859 : long_accum_type_node
;
9860 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9861 return unsignedp
? unsigned_long_long_accum_type_node
9862 : long_long_accum_type_node
;
9865 return make_accum_type (size
, unsignedp
, satp
);
9869 /* Create an atomic variant node for TYPE. This routine is called
9870 during initialization of data types to create the 5 basic atomic
9871 types. The generic build_variant_type function requires these to
9872 already be set up in order to function properly, so cannot be
9873 called from there. If ALIGN is non-zero, then ensure alignment is
9874 overridden to this value. */
9877 build_atomic_base (tree type
, unsigned int align
)
9881 /* Make sure its not already registered. */
9882 if ((t
= get_qualified_type (type
, TYPE_QUAL_ATOMIC
)))
9885 t
= build_variant_type_copy (type
);
9886 set_type_quals (t
, TYPE_QUAL_ATOMIC
);
9889 TYPE_ALIGN (t
) = align
;
9894 /* Create nodes for all integer types (and error_mark_node) using the sizes
9895 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9896 SHORT_DOUBLE specifies whether double should be of the same precision
9900 build_common_tree_nodes (bool signed_char
, bool short_double
)
9904 error_mark_node
= make_node (ERROR_MARK
);
9905 TREE_TYPE (error_mark_node
) = error_mark_node
;
9907 initialize_sizetypes ();
9909 /* Define both `signed char' and `unsigned char'. */
9910 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9911 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9912 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9913 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9915 /* Define `char', which is like either `signed char' or `unsigned char'
9916 but not the same as either. */
9919 ? make_signed_type (CHAR_TYPE_SIZE
)
9920 : make_unsigned_type (CHAR_TYPE_SIZE
));
9921 TYPE_STRING_FLAG (char_type_node
) = 1;
9923 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9924 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9925 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9926 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9927 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9928 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9929 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9930 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9932 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9934 int_n_trees
[i
].signed_type
= make_signed_type (int_n_data
[i
].bitsize
);
9935 int_n_trees
[i
].unsigned_type
= make_unsigned_type (int_n_data
[i
].bitsize
);
9936 TYPE_SIZE (int_n_trees
[i
].signed_type
) = bitsize_int (int_n_data
[i
].bitsize
);
9937 TYPE_SIZE (int_n_trees
[i
].unsigned_type
) = bitsize_int (int_n_data
[i
].bitsize
);
9939 if (int_n_data
[i
].bitsize
> LONG_LONG_TYPE_SIZE
9940 && int_n_enabled_p
[i
])
9942 integer_types
[itk_intN_0
+ i
* 2] = int_n_trees
[i
].signed_type
;
9943 integer_types
[itk_unsigned_intN_0
+ i
* 2] = int_n_trees
[i
].unsigned_type
;
9947 /* Define a boolean type. This type only represents boolean values but
9948 may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9949 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9950 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9951 TYPE_PRECISION (boolean_type_node
) = 1;
9952 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9954 /* Define what type to use for size_t. */
9955 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
9956 size_type_node
= unsigned_type_node
;
9957 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
9958 size_type_node
= long_unsigned_type_node
;
9959 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
9960 size_type_node
= long_long_unsigned_type_node
;
9961 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
9962 size_type_node
= short_unsigned_type_node
;
9967 size_type_node
= NULL_TREE
;
9968 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9969 if (int_n_enabled_p
[i
])
9972 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
9974 if (strcmp (name
, SIZE_TYPE
) == 0)
9976 size_type_node
= int_n_trees
[i
].unsigned_type
;
9979 if (size_type_node
== NULL_TREE
)
9983 /* Fill in the rest of the sized types. Reuse existing type nodes
9985 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9986 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9987 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9988 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9989 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9991 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9992 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9993 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9994 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9995 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9997 /* Don't call build_qualified type for atomics. That routine does
9998 special processing for atomics, and until they are initialized
9999 it's better not to make that call.
10001 Check to see if there is a target override for atomic types. */
10003 atomicQI_type_node
= build_atomic_base (unsigned_intQI_type_node
,
10004 targetm
.atomic_align_for_mode (QImode
));
10005 atomicHI_type_node
= build_atomic_base (unsigned_intHI_type_node
,
10006 targetm
.atomic_align_for_mode (HImode
));
10007 atomicSI_type_node
= build_atomic_base (unsigned_intSI_type_node
,
10008 targetm
.atomic_align_for_mode (SImode
));
10009 atomicDI_type_node
= build_atomic_base (unsigned_intDI_type_node
,
10010 targetm
.atomic_align_for_mode (DImode
));
10011 atomicTI_type_node
= build_atomic_base (unsigned_intTI_type_node
,
10012 targetm
.atomic_align_for_mode (TImode
));
10014 access_public_node
= get_identifier ("public");
10015 access_protected_node
= get_identifier ("protected");
10016 access_private_node
= get_identifier ("private");
10018 /* Define these next since types below may used them. */
10019 integer_zero_node
= build_int_cst (integer_type_node
, 0);
10020 integer_one_node
= build_int_cst (integer_type_node
, 1);
10021 integer_three_node
= build_int_cst (integer_type_node
, 3);
10022 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
10024 size_zero_node
= size_int (0);
10025 size_one_node
= size_int (1);
10026 bitsize_zero_node
= bitsize_int (0);
10027 bitsize_one_node
= bitsize_int (1);
10028 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
10030 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
10031 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
10033 void_type_node
= make_node (VOID_TYPE
);
10034 layout_type (void_type_node
);
10036 pointer_bounds_type_node
= targetm
.chkp_bound_type ();
10038 /* We are not going to have real types in C with less than byte alignment,
10039 so we might as well not have any types that claim to have it. */
10040 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
10041 TYPE_USER_ALIGN (void_type_node
) = 0;
10043 void_node
= make_node (VOID_CST
);
10044 TREE_TYPE (void_node
) = void_type_node
;
10046 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
10047 layout_type (TREE_TYPE (null_pointer_node
));
10049 ptr_type_node
= build_pointer_type (void_type_node
);
10050 const_ptr_type_node
10051 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
10052 fileptr_type_node
= ptr_type_node
;
10054 pointer_sized_int_node
= build_nonstandard_integer_type (POINTER_SIZE
, 1);
10056 float_type_node
= make_node (REAL_TYPE
);
10057 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
10058 layout_type (float_type_node
);
10060 double_type_node
= make_node (REAL_TYPE
);
10062 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
10064 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
10065 layout_type (double_type_node
);
10067 long_double_type_node
= make_node (REAL_TYPE
);
10068 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
10069 layout_type (long_double_type_node
);
10071 float_ptr_type_node
= build_pointer_type (float_type_node
);
10072 double_ptr_type_node
= build_pointer_type (double_type_node
);
10073 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
10074 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
10076 /* Fixed size integer types. */
10077 uint16_type_node
= make_or_reuse_type (16, 1);
10078 uint32_type_node
= make_or_reuse_type (32, 1);
10079 uint64_type_node
= make_or_reuse_type (64, 1);
10081 /* Decimal float types. */
10082 dfloat32_type_node
= make_node (REAL_TYPE
);
10083 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
10084 layout_type (dfloat32_type_node
);
10085 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
10086 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
10088 dfloat64_type_node
= make_node (REAL_TYPE
);
10089 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
10090 layout_type (dfloat64_type_node
);
10091 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
10092 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
10094 dfloat128_type_node
= make_node (REAL_TYPE
);
10095 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
10096 layout_type (dfloat128_type_node
);
10097 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
10098 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
10100 complex_integer_type_node
= build_complex_type (integer_type_node
);
10101 complex_float_type_node
= build_complex_type (float_type_node
);
10102 complex_double_type_node
= build_complex_type (double_type_node
);
10103 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
10105 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
10106 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
10107 sat_ ## KIND ## _type_node = \
10108 make_sat_signed_ ## KIND ## _type (SIZE); \
10109 sat_unsigned_ ## KIND ## _type_node = \
10110 make_sat_unsigned_ ## KIND ## _type (SIZE); \
10111 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
10112 unsigned_ ## KIND ## _type_node = \
10113 make_unsigned_ ## KIND ## _type (SIZE);
10115 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
10116 sat_ ## WIDTH ## KIND ## _type_node = \
10117 make_sat_signed_ ## KIND ## _type (SIZE); \
10118 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
10119 make_sat_unsigned_ ## KIND ## _type (SIZE); \
10120 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
10121 unsigned_ ## WIDTH ## KIND ## _type_node = \
10122 make_unsigned_ ## KIND ## _type (SIZE);
10124 /* Make fixed-point type nodes based on four different widths. */
10125 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
10126 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
10127 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
10128 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
10129 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
10131 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
10132 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
10133 NAME ## _type_node = \
10134 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
10135 u ## NAME ## _type_node = \
10136 make_or_reuse_unsigned_ ## KIND ## _type \
10137 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
10138 sat_ ## NAME ## _type_node = \
10139 make_or_reuse_sat_signed_ ## KIND ## _type \
10140 (GET_MODE_BITSIZE (MODE ## mode)); \
10141 sat_u ## NAME ## _type_node = \
10142 make_or_reuse_sat_unsigned_ ## KIND ## _type \
10143 (GET_MODE_BITSIZE (U ## MODE ## mode));
10145 /* Fixed-point type and mode nodes. */
10146 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
10147 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
10148 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
10149 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
10150 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
10151 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
10152 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
10153 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
10154 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
10155 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
10156 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
10159 tree t
= targetm
.build_builtin_va_list ();
10161 /* Many back-ends define record types without setting TYPE_NAME.
10162 If we copied the record type here, we'd keep the original
10163 record type without a name. This breaks name mangling. So,
10164 don't copy record types and let c_common_nodes_and_builtins()
10165 declare the type to be __builtin_va_list. */
10166 if (TREE_CODE (t
) != RECORD_TYPE
)
10167 t
= build_variant_type_copy (t
);
10169 va_list_type_node
= t
;
10173 /* Modify DECL for given flags.
10174 TM_PURE attribute is set only on types, so the function will modify
10175 DECL's type when ECF_TM_PURE is used. */
10178 set_call_expr_flags (tree decl
, int flags
)
10180 if (flags
& ECF_NOTHROW
)
10181 TREE_NOTHROW (decl
) = 1;
10182 if (flags
& ECF_CONST
)
10183 TREE_READONLY (decl
) = 1;
10184 if (flags
& ECF_PURE
)
10185 DECL_PURE_P (decl
) = 1;
10186 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
10187 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
10188 if (flags
& ECF_NOVOPS
)
10189 DECL_IS_NOVOPS (decl
) = 1;
10190 if (flags
& ECF_NORETURN
)
10191 TREE_THIS_VOLATILE (decl
) = 1;
10192 if (flags
& ECF_MALLOC
)
10193 DECL_IS_MALLOC (decl
) = 1;
10194 if (flags
& ECF_RETURNS_TWICE
)
10195 DECL_IS_RETURNS_TWICE (decl
) = 1;
10196 if (flags
& ECF_LEAF
)
10197 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
10198 NULL
, DECL_ATTRIBUTES (decl
));
10199 if ((flags
& ECF_TM_PURE
) && flag_tm
)
10200 apply_tm_attr (decl
, get_identifier ("transaction_pure"));
10201 /* Looping const or pure is implied by noreturn.
10202 There is currently no way to declare looping const or looping pure alone. */
10203 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
10204 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
10208 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10211 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
10212 const char *library_name
, int ecf_flags
)
10216 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
10217 library_name
, NULL_TREE
);
10218 set_call_expr_flags (decl
, ecf_flags
);
10220 set_builtin_decl (code
, decl
, true);
10223 /* Call this function after instantiating all builtins that the language
10224 front end cares about. This will build the rest of the builtins
10225 and internal functions that are relied upon by the tree optimizers and
10229 build_common_builtin_nodes (void)
10234 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
10236 ftype
= build_function_type (void_type_node
, void_list_node
);
10237 local_define_builtin ("__builtin_unreachable", ftype
, BUILT_IN_UNREACHABLE
,
10238 "__builtin_unreachable",
10239 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
10243 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
10244 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
10246 ftype
= build_function_type_list (ptr_type_node
,
10247 ptr_type_node
, const_ptr_type_node
,
10248 size_type_node
, NULL_TREE
);
10250 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
10251 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
10252 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
10253 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
10254 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
10255 "memmove", ECF_NOTHROW
| ECF_LEAF
);
10258 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
10260 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
10261 const_ptr_type_node
, size_type_node
,
10263 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
10264 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10267 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
10269 ftype
= build_function_type_list (ptr_type_node
,
10270 ptr_type_node
, integer_type_node
,
10271 size_type_node
, NULL_TREE
);
10272 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
10273 "memset", ECF_NOTHROW
| ECF_LEAF
);
10276 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
10278 ftype
= build_function_type_list (ptr_type_node
,
10279 size_type_node
, NULL_TREE
);
10280 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
10281 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10284 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
10285 size_type_node
, NULL_TREE
);
10286 local_define_builtin ("__builtin_alloca_with_align", ftype
,
10287 BUILT_IN_ALLOCA_WITH_ALIGN
,
10288 "__builtin_alloca_with_align",
10289 ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10291 /* If we're checking the stack, `alloca' can throw. */
10292 if (flag_stack_check
)
10294 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA
)) = 0;
10295 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
)) = 0;
10298 ftype
= build_function_type_list (void_type_node
,
10299 ptr_type_node
, ptr_type_node
,
10300 ptr_type_node
, NULL_TREE
);
10301 local_define_builtin ("__builtin_init_trampoline", ftype
,
10302 BUILT_IN_INIT_TRAMPOLINE
,
10303 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
10304 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
10305 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
10306 "__builtin_init_heap_trampoline",
10307 ECF_NOTHROW
| ECF_LEAF
);
10309 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
10310 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
10311 BUILT_IN_ADJUST_TRAMPOLINE
,
10312 "__builtin_adjust_trampoline",
10313 ECF_CONST
| ECF_NOTHROW
);
10315 ftype
= build_function_type_list (void_type_node
,
10316 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10317 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
10318 BUILT_IN_NONLOCAL_GOTO
,
10319 "__builtin_nonlocal_goto",
10320 ECF_NORETURN
| ECF_NOTHROW
);
10322 ftype
= build_function_type_list (void_type_node
,
10323 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10324 local_define_builtin ("__builtin_setjmp_setup", ftype
,
10325 BUILT_IN_SETJMP_SETUP
,
10326 "__builtin_setjmp_setup", ECF_NOTHROW
);
10328 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10329 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
10330 BUILT_IN_SETJMP_RECEIVER
,
10331 "__builtin_setjmp_receiver", ECF_NOTHROW
| ECF_LEAF
);
10333 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
10334 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
10335 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
10337 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10338 local_define_builtin ("__builtin_stack_restore", ftype
,
10339 BUILT_IN_STACK_RESTORE
,
10340 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
10342 /* If there's a possibility that we might use the ARM EABI, build the
10343 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
10344 if (targetm
.arm_eabi_unwinder
)
10346 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
10347 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
10348 BUILT_IN_CXA_END_CLEANUP
,
10349 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
10352 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10353 local_define_builtin ("__builtin_unwind_resume", ftype
,
10354 BUILT_IN_UNWIND_RESUME
,
10355 ((targetm_common
.except_unwind_info (&global_options
)
10357 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10360 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
10362 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
10364 local_define_builtin ("__builtin_return_address", ftype
,
10365 BUILT_IN_RETURN_ADDRESS
,
10366 "__builtin_return_address",
10370 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
10371 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10373 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
10374 ptr_type_node
, NULL_TREE
);
10375 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
10376 local_define_builtin ("__cyg_profile_func_enter", ftype
,
10377 BUILT_IN_PROFILE_FUNC_ENTER
,
10378 "__cyg_profile_func_enter", 0);
10379 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10380 local_define_builtin ("__cyg_profile_func_exit", ftype
,
10381 BUILT_IN_PROFILE_FUNC_EXIT
,
10382 "__cyg_profile_func_exit", 0);
10385 /* The exception object and filter values from the runtime. The argument
10386 must be zero before exception lowering, i.e. from the front end. After
10387 exception lowering, it will be the region number for the exception
10388 landing pad. These functions are PURE instead of CONST to prevent
10389 them from being hoisted past the exception edge that will initialize
10390 its value in the landing pad. */
10391 ftype
= build_function_type_list (ptr_type_node
,
10392 integer_type_node
, NULL_TREE
);
10393 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
10394 /* Only use TM_PURE if we have TM language support. */
10395 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
10396 ecf_flags
|= ECF_TM_PURE
;
10397 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
10398 "__builtin_eh_pointer", ecf_flags
);
10400 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
10401 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
10402 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
10403 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10405 ftype
= build_function_type_list (void_type_node
,
10406 integer_type_node
, integer_type_node
,
10408 local_define_builtin ("__builtin_eh_copy_values", ftype
,
10409 BUILT_IN_EH_COPY_VALUES
,
10410 "__builtin_eh_copy_values", ECF_NOTHROW
);
10412 /* Complex multiplication and division. These are handled as builtins
10413 rather than optabs because emit_library_call_value doesn't support
10414 complex. Further, we can do slightly better with folding these
10415 beasties if the real and complex parts of the arguments are separate. */
10419 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
10421 char mode_name_buf
[4], *q
;
10423 enum built_in_function mcode
, dcode
;
10424 tree type
, inner_type
;
10425 const char *prefix
= "__";
10427 if (targetm
.libfunc_gnu_prefix
)
10430 type
= lang_hooks
.types
.type_for_mode ((machine_mode
) mode
, 0);
10433 inner_type
= TREE_TYPE (type
);
10435 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
10436 inner_type
, inner_type
, NULL_TREE
);
10438 mcode
= ((enum built_in_function
)
10439 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10440 dcode
= ((enum built_in_function
)
10441 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10443 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
10447 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
10449 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
10450 built_in_names
[mcode
],
10451 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10453 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
10455 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
10456 built_in_names
[dcode
],
10457 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10461 init_internal_fns ();
10464 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10467 If we requested a pointer to a vector, build up the pointers that
10468 we stripped off while looking for the inner type. Similarly for
10469 return values from functions.
10471 The argument TYPE is the top of the chain, and BOTTOM is the
10472 new type which we will point to. */
10475 reconstruct_complex_type (tree type
, tree bottom
)
10479 if (TREE_CODE (type
) == POINTER_TYPE
)
10481 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10482 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
10483 TYPE_REF_CAN_ALIAS_ALL (type
));
10485 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
10487 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10488 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
10489 TYPE_REF_CAN_ALIAS_ALL (type
));
10491 else if (TREE_CODE (type
) == ARRAY_TYPE
)
10493 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10494 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
10496 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
10498 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10499 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
10501 else if (TREE_CODE (type
) == METHOD_TYPE
)
10503 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10504 /* The build_method_type_directly() routine prepends 'this' to argument list,
10505 so we must compensate by getting rid of it. */
10507 = build_method_type_directly
10508 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
10510 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
10512 else if (TREE_CODE (type
) == OFFSET_TYPE
)
10514 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10515 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
10520 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
10521 TYPE_QUALS (type
));
10524 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10527 build_vector_type_for_mode (tree innertype
, machine_mode mode
)
10531 switch (GET_MODE_CLASS (mode
))
10533 case MODE_VECTOR_INT
:
10534 case MODE_VECTOR_FLOAT
:
10535 case MODE_VECTOR_FRACT
:
10536 case MODE_VECTOR_UFRACT
:
10537 case MODE_VECTOR_ACCUM
:
10538 case MODE_VECTOR_UACCUM
:
10539 nunits
= GET_MODE_NUNITS (mode
);
10543 /* Check that there are no leftover bits. */
10544 gcc_assert (GET_MODE_BITSIZE (mode
)
10545 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
10547 nunits
= GET_MODE_BITSIZE (mode
)
10548 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
10552 gcc_unreachable ();
10555 return make_vector_type (innertype
, nunits
, mode
);
10558 /* Similarly, but takes the inner type and number of units, which must be
10562 build_vector_type (tree innertype
, int nunits
)
10564 return make_vector_type (innertype
, nunits
, VOIDmode
);
10567 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10570 build_opaque_vector_type (tree innertype
, int nunits
)
10572 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
10574 /* We always build the non-opaque variant before the opaque one,
10575 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10576 cand
= TYPE_NEXT_VARIANT (t
);
10578 && TYPE_VECTOR_OPAQUE (cand
)
10579 && check_qualified_type (cand
, t
, TYPE_QUALS (t
)))
10581 /* Othewise build a variant type and make sure to queue it after
10582 the non-opaque type. */
10583 cand
= build_distinct_type_copy (t
);
10584 TYPE_VECTOR_OPAQUE (cand
) = true;
10585 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
10586 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
10587 TYPE_NEXT_VARIANT (t
) = cand
;
10588 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
10593 /* Given an initializer INIT, return TRUE if INIT is zero or some
10594 aggregate of zeros. Otherwise return FALSE. */
10596 initializer_zerop (const_tree init
)
10602 switch (TREE_CODE (init
))
10605 return integer_zerop (init
);
10608 /* ??? Note that this is not correct for C4X float formats. There,
10609 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10610 negative exponent. */
10611 return real_zerop (init
)
10612 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
10615 return fixed_zerop (init
);
10618 return integer_zerop (init
)
10619 || (real_zerop (init
)
10620 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10621 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
10626 for (i
= 0; i
< VECTOR_CST_NELTS (init
); ++i
)
10627 if (!initializer_zerop (VECTOR_CST_ELT (init
, i
)))
10634 unsigned HOST_WIDE_INT idx
;
10636 if (TREE_CLOBBER_P (init
))
10638 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10639 if (!initializer_zerop (elt
))
10648 /* We need to loop through all elements to handle cases like
10649 "\0" and "\0foobar". */
10650 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
10651 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10662 /* Check if vector VEC consists of all the equal elements and
10663 that the number of elements corresponds to the type of VEC.
10664 The function returns first element of the vector
10665 or NULL_TREE if the vector is not uniform. */
10667 uniform_vector_p (const_tree vec
)
10672 if (vec
== NULL_TREE
)
10675 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10677 if (TREE_CODE (vec
) == VECTOR_CST
)
10679 first
= VECTOR_CST_ELT (vec
, 0);
10680 for (i
= 1; i
< VECTOR_CST_NELTS (vec
); ++i
)
10681 if (!operand_equal_p (first
, VECTOR_CST_ELT (vec
, i
), 0))
10687 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
10689 first
= error_mark_node
;
10691 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10698 if (!operand_equal_p (first
, t
, 0))
10701 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
10710 /* Build an empty statement at location LOC. */
10713 build_empty_stmt (location_t loc
)
10715 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10716 SET_EXPR_LOCATION (t
, loc
);
10721 /* Build an OpenMP clause with code CODE. LOC is the location of the
10725 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10730 length
= omp_clause_num_ops
[code
];
10731 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10733 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10735 t
= (tree
) ggc_internal_alloc (size
);
10736 memset (t
, 0, size
);
10737 TREE_SET_CODE (t
, OMP_CLAUSE
);
10738 OMP_CLAUSE_SET_CODE (t
, code
);
10739 OMP_CLAUSE_LOCATION (t
) = loc
;
10744 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10745 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10746 Except for the CODE and operand count field, other storage for the
10747 object is initialized to zeros. */
10750 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
10753 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10755 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10756 gcc_assert (len
>= 1);
10758 record_node_allocation_statistics (code
, length
);
10760 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10762 TREE_SET_CODE (t
, code
);
10764 /* Can't use TREE_OPERAND to store the length because if checking is
10765 enabled, it will try to check the length before we store it. :-P */
10766 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10771 /* Helper function for build_call_* functions; build a CALL_EXPR with
10772 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10773 the argument slots. */
10776 build_call_1 (tree return_type
, tree fn
, int nargs
)
10780 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10781 TREE_TYPE (t
) = return_type
;
10782 CALL_EXPR_FN (t
) = fn
;
10783 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10788 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10789 FN and a null static chain slot. NARGS is the number of call arguments
10790 which are specified as "..." arguments. */
10793 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10797 va_start (args
, nargs
);
10798 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10803 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10804 FN and a null static chain slot. NARGS is the number of call arguments
10805 which are specified as a va_list ARGS. */
10808 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10813 t
= build_call_1 (return_type
, fn
, nargs
);
10814 for (i
= 0; i
< nargs
; i
++)
10815 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10816 process_call_operands (t
);
10820 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10821 FN and a null static chain slot. NARGS is the number of call arguments
10822 which are specified as a tree array ARGS. */
10825 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10826 int nargs
, const tree
*args
)
10831 t
= build_call_1 (return_type
, fn
, nargs
);
10832 for (i
= 0; i
< nargs
; i
++)
10833 CALL_EXPR_ARG (t
, i
) = args
[i
];
10834 process_call_operands (t
);
10835 SET_EXPR_LOCATION (t
, loc
);
10839 /* Like build_call_array, but takes a vec. */
10842 build_call_vec (tree return_type
, tree fn
, vec
<tree
, va_gc
> *args
)
10847 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10848 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10849 CALL_EXPR_ARG (ret
, ix
) = t
;
10850 process_call_operands (ret
);
10854 /* Conveniently construct a function call expression. FNDECL names the
10855 function to be called and N arguments are passed in the array
10859 build_call_expr_loc_array (location_t loc
, tree fndecl
, int n
, tree
*argarray
)
10861 tree fntype
= TREE_TYPE (fndecl
);
10862 tree fn
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), fndecl
);
10864 return fold_build_call_array_loc (loc
, TREE_TYPE (fntype
), fn
, n
, argarray
);
10867 /* Conveniently construct a function call expression. FNDECL names the
10868 function to be called and the arguments are passed in the vector
10872 build_call_expr_loc_vec (location_t loc
, tree fndecl
, vec
<tree
, va_gc
> *vec
)
10874 return build_call_expr_loc_array (loc
, fndecl
, vec_safe_length (vec
),
10875 vec_safe_address (vec
));
10879 /* Conveniently construct a function call expression. FNDECL names the
10880 function to be called, N is the number of arguments, and the "..."
10881 parameters are the argument expressions. */
10884 build_call_expr_loc (location_t loc
, tree fndecl
, int n
, ...)
10887 tree
*argarray
= XALLOCAVEC (tree
, n
);
10891 for (i
= 0; i
< n
; i
++)
10892 argarray
[i
] = va_arg (ap
, tree
);
10894 return build_call_expr_loc_array (loc
, fndecl
, n
, argarray
);
10897 /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
10898 varargs macros aren't supported by all bootstrap compilers. */
10901 build_call_expr (tree fndecl
, int n
, ...)
10904 tree
*argarray
= XALLOCAVEC (tree
, n
);
10908 for (i
= 0; i
< n
; i
++)
10909 argarray
[i
] = va_arg (ap
, tree
);
10911 return build_call_expr_loc_array (UNKNOWN_LOCATION
, fndecl
, n
, argarray
);
10914 /* Build internal call expression. This is just like CALL_EXPR, except
10915 its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
10916 internal function. */
10919 build_call_expr_internal_loc (location_t loc
, enum internal_fn ifn
,
10920 tree type
, int n
, ...)
10925 tree fn
= build_call_1 (type
, NULL_TREE
, n
);
10927 for (i
= 0; i
< n
; i
++)
10928 CALL_EXPR_ARG (fn
, i
) = va_arg (ap
, tree
);
10930 SET_EXPR_LOCATION (fn
, loc
);
10931 CALL_EXPR_IFN (fn
) = ifn
;
10935 /* Create a new constant string literal and return a char* pointer to it.
10936 The STRING_CST value is the LEN characters at STR. */
10938 build_string_literal (int len
, const char *str
)
10940 tree t
, elem
, index
, type
;
10942 t
= build_string (len
, str
);
10943 elem
= build_type_variant (char_type_node
, 1, 0);
10944 index
= build_index_type (size_int (len
- 1));
10945 type
= build_array_type (elem
, index
);
10946 TREE_TYPE (t
) = type
;
10947 TREE_CONSTANT (t
) = 1;
10948 TREE_READONLY (t
) = 1;
10949 TREE_STATIC (t
) = 1;
10951 type
= build_pointer_type (elem
);
10952 t
= build1 (ADDR_EXPR
, type
,
10953 build4 (ARRAY_REF
, elem
,
10954 t
, integer_zero_node
, NULL_TREE
, NULL_TREE
));
10960 /* Return true if T (assumed to be a DECL) must be assigned a memory
10964 needs_to_live_in_memory (const_tree t
)
10966 return (TREE_ADDRESSABLE (t
)
10967 || is_global_var (t
)
10968 || (TREE_CODE (t
) == RESULT_DECL
10969 && !DECL_BY_REFERENCE (t
)
10970 && aggregate_value_p (t
, current_function_decl
)));
10973 /* Return value of a constant X and sign-extend it. */
10976 int_cst_value (const_tree x
)
10978 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10979 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
10981 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10982 gcc_assert (cst_and_fits_in_hwi (x
));
10984 if (bits
< HOST_BITS_PER_WIDE_INT
)
10986 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10988 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
10990 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
10996 /* If TYPE is an integral or pointer type, return an integer type with
10997 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10998 if TYPE is already an integer type of signedness UNSIGNEDP. */
11001 signed_or_unsigned_type_for (int unsignedp
, tree type
)
11003 if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
) == unsignedp
)
11006 if (TREE_CODE (type
) == VECTOR_TYPE
)
11008 tree inner
= TREE_TYPE (type
);
11009 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
11012 if (inner
== inner2
)
11014 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
11017 if (!INTEGRAL_TYPE_P (type
)
11018 && !POINTER_TYPE_P (type
)
11019 && TREE_CODE (type
) != OFFSET_TYPE
)
11022 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
11025 /* If TYPE is an integral or pointer type, return an integer type with
11026 the same precision which is unsigned, or itself if TYPE is already an
11027 unsigned integer type. */
11030 unsigned_type_for (tree type
)
11032 return signed_or_unsigned_type_for (1, type
);
11035 /* If TYPE is an integral or pointer type, return an integer type with
11036 the same precision which is signed, or itself if TYPE is already a
11037 signed integer type. */
11040 signed_type_for (tree type
)
11042 return signed_or_unsigned_type_for (0, type
);
11045 /* If TYPE is a vector type, return a signed integer vector type with the
11046 same width and number of subparts. Otherwise return boolean_type_node. */
11049 truth_type_for (tree type
)
11051 if (TREE_CODE (type
) == VECTOR_TYPE
)
11053 tree elem
= lang_hooks
.types
.type_for_size
11054 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type
))), 0);
11055 return build_opaque_vector_type (elem
, TYPE_VECTOR_SUBPARTS (type
));
11058 return boolean_type_node
;
11061 /* Returns the largest value obtainable by casting something in INNER type to
11065 upper_bound_in_type (tree outer
, tree inner
)
11067 unsigned int det
= 0;
11068 unsigned oprec
= TYPE_PRECISION (outer
);
11069 unsigned iprec
= TYPE_PRECISION (inner
);
11072 /* Compute a unique number for every combination. */
11073 det
|= (oprec
> iprec
) ? 4 : 0;
11074 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
11075 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
11077 /* Determine the exponent to use. */
11082 /* oprec <= iprec, outer: signed, inner: don't care. */
11087 /* oprec <= iprec, outer: unsigned, inner: don't care. */
11091 /* oprec > iprec, outer: signed, inner: signed. */
11095 /* oprec > iprec, outer: signed, inner: unsigned. */
11099 /* oprec > iprec, outer: unsigned, inner: signed. */
11103 /* oprec > iprec, outer: unsigned, inner: unsigned. */
11107 gcc_unreachable ();
11110 return wide_int_to_tree (outer
,
11111 wi::mask (prec
, false, TYPE_PRECISION (outer
)));
11114 /* Returns the smallest value obtainable by casting something in INNER type to
11118 lower_bound_in_type (tree outer
, tree inner
)
11120 unsigned oprec
= TYPE_PRECISION (outer
);
11121 unsigned iprec
= TYPE_PRECISION (inner
);
11123 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11125 if (TYPE_UNSIGNED (outer
)
11126 /* If we are widening something of an unsigned type, OUTER type
11127 contains all values of INNER type. In particular, both INNER
11128 and OUTER types have zero in common. */
11129 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
11130 return build_int_cst (outer
, 0);
11133 /* If we are widening a signed type to another signed type, we
11134 want to obtain -2^^(iprec-1). If we are keeping the
11135 precision or narrowing to a signed type, we want to obtain
11137 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
11138 return wide_int_to_tree (outer
,
11139 wi::mask (prec
- 1, true,
11140 TYPE_PRECISION (outer
)));
11144 /* Return nonzero if two operands that are suitable for PHI nodes are
11145 necessarily equal. Specifically, both ARG0 and ARG1 must be either
11146 SSA_NAME or invariant. Note that this is strictly an optimization.
11147 That is, callers of this function can directly call operand_equal_p
11148 and get the same result, only slower. */
11151 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
11155 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
11157 return operand_equal_p (arg0
, arg1
, 0);
11160 /* Returns number of zeros at the end of binary representation of X. */
11163 num_ending_zeros (const_tree x
)
11165 return build_int_cst (TREE_TYPE (x
), wi::ctz (x
));
11169 #define WALK_SUBTREE(NODE) \
11172 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11178 /* This is a subroutine of walk_tree that walks field of TYPE that are to
11179 be walked whenever a type is seen in the tree. Rest of operands and return
11180 value are as for walk_tree. */
11183 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
11184 hash_set
<tree
> *pset
, walk_tree_lh lh
)
11186 tree result
= NULL_TREE
;
11188 switch (TREE_CODE (type
))
11191 case REFERENCE_TYPE
:
11193 /* We have to worry about mutually recursive pointers. These can't
11194 be written in C. They can in Ada. It's pathological, but
11195 there's an ACATS test (c38102a) that checks it. Deal with this
11196 by checking if we're pointing to another pointer, that one
11197 points to another pointer, that one does too, and we have no htab.
11198 If so, get a hash table. We check three levels deep to avoid
11199 the cost of the hash table if we don't need one. */
11200 if (POINTER_TYPE_P (TREE_TYPE (type
))
11201 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
11202 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
11205 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
11213 /* ... fall through ... */
11216 WALK_SUBTREE (TREE_TYPE (type
));
11220 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
11222 /* Fall through. */
11224 case FUNCTION_TYPE
:
11225 WALK_SUBTREE (TREE_TYPE (type
));
11229 /* We never want to walk into default arguments. */
11230 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
11231 WALK_SUBTREE (TREE_VALUE (arg
));
11236 /* Don't follow this nodes's type if a pointer for fear that
11237 we'll have infinite recursion. If we have a PSET, then we
11240 || (!POINTER_TYPE_P (TREE_TYPE (type
))
11241 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
11242 WALK_SUBTREE (TREE_TYPE (type
));
11243 WALK_SUBTREE (TYPE_DOMAIN (type
));
11247 WALK_SUBTREE (TREE_TYPE (type
));
11248 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
11258 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11259 called with the DATA and the address of each sub-tree. If FUNC returns a
11260 non-NULL value, the traversal is stopped, and the value returned by FUNC
11261 is returned. If PSET is non-NULL it is used to record the nodes visited,
11262 and to avoid visiting a node more than once. */
11265 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11266 hash_set
<tree
> *pset
, walk_tree_lh lh
)
11268 enum tree_code code
;
11272 #define WALK_SUBTREE_TAIL(NODE) \
11276 goto tail_recurse; \
11281 /* Skip empty subtrees. */
11285 /* Don't walk the same tree twice, if the user has requested
11286 that we avoid doing so. */
11287 if (pset
&& pset
->add (*tp
))
11290 /* Call the function. */
11292 result
= (*func
) (tp
, &walk_subtrees
, data
);
11294 /* If we found something, return it. */
11298 code
= TREE_CODE (*tp
);
11300 /* Even if we didn't, FUNC may have decided that there was nothing
11301 interesting below this point in the tree. */
11302 if (!walk_subtrees
)
11304 /* But we still need to check our siblings. */
11305 if (code
== TREE_LIST
)
11306 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11307 else if (code
== OMP_CLAUSE
)
11308 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11315 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
11316 if (result
|| !walk_subtrees
)
11323 case IDENTIFIER_NODE
:
11330 case PLACEHOLDER_EXPR
:
11334 /* None of these have subtrees other than those already walked
11339 WALK_SUBTREE (TREE_VALUE (*tp
));
11340 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11345 int len
= TREE_VEC_LENGTH (*tp
);
11350 /* Walk all elements but the first. */
11352 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
11354 /* Now walk the first one as a tail call. */
11355 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
11359 WALK_SUBTREE (TREE_REALPART (*tp
));
11360 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
11364 unsigned HOST_WIDE_INT idx
;
11365 constructor_elt
*ce
;
11367 for (idx
= 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*tp
), idx
, &ce
);
11369 WALK_SUBTREE (ce
->value
);
11374 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
11379 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
11381 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11382 into declarations that are just mentioned, rather than
11383 declared; they don't really belong to this part of the tree.
11384 And, we can see cycles: the initializer for a declaration
11385 can refer to the declaration itself. */
11386 WALK_SUBTREE (DECL_INITIAL (decl
));
11387 WALK_SUBTREE (DECL_SIZE (decl
));
11388 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
11390 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
11393 case STATEMENT_LIST
:
11395 tree_stmt_iterator i
;
11396 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
11397 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11402 switch (OMP_CLAUSE_CODE (*tp
))
11404 case OMP_CLAUSE_GANG
:
11405 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 1));
11408 case OMP_CLAUSE_DEVICE_RESIDENT
:
11409 case OMP_CLAUSE_USE_DEVICE
:
11410 case OMP_CLAUSE_ASYNC
:
11411 case OMP_CLAUSE_WAIT
:
11412 case OMP_CLAUSE_WORKER
:
11413 case OMP_CLAUSE_VECTOR
:
11414 case OMP_CLAUSE_NUM_GANGS
:
11415 case OMP_CLAUSE_NUM_WORKERS
:
11416 case OMP_CLAUSE_VECTOR_LENGTH
:
11417 case OMP_CLAUSE_PRIVATE
:
11418 case OMP_CLAUSE_SHARED
:
11419 case OMP_CLAUSE_FIRSTPRIVATE
:
11420 case OMP_CLAUSE_COPYIN
:
11421 case OMP_CLAUSE_COPYPRIVATE
:
11422 case OMP_CLAUSE_FINAL
:
11423 case OMP_CLAUSE_IF
:
11424 case OMP_CLAUSE_NUM_THREADS
:
11425 case OMP_CLAUSE_SCHEDULE
:
11426 case OMP_CLAUSE_UNIFORM
:
11427 case OMP_CLAUSE_DEPEND
:
11428 case OMP_CLAUSE_NUM_TEAMS
:
11429 case OMP_CLAUSE_THREAD_LIMIT
:
11430 case OMP_CLAUSE_DEVICE
:
11431 case OMP_CLAUSE_DIST_SCHEDULE
:
11432 case OMP_CLAUSE_SAFELEN
:
11433 case OMP_CLAUSE_SIMDLEN
:
11434 case OMP_CLAUSE__LOOPTEMP_
:
11435 case OMP_CLAUSE__SIMDUID_
:
11436 case OMP_CLAUSE__CILK_FOR_COUNT_
:
11437 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
11440 case OMP_CLAUSE_INDEPENDENT
:
11441 case OMP_CLAUSE_NOWAIT
:
11442 case OMP_CLAUSE_ORDERED
:
11443 case OMP_CLAUSE_DEFAULT
:
11444 case OMP_CLAUSE_UNTIED
:
11445 case OMP_CLAUSE_MERGEABLE
:
11446 case OMP_CLAUSE_PROC_BIND
:
11447 case OMP_CLAUSE_INBRANCH
:
11448 case OMP_CLAUSE_NOTINBRANCH
:
11449 case OMP_CLAUSE_FOR
:
11450 case OMP_CLAUSE_PARALLEL
:
11451 case OMP_CLAUSE_SECTIONS
:
11452 case OMP_CLAUSE_TASKGROUP
:
11453 case OMP_CLAUSE_AUTO
:
11454 case OMP_CLAUSE_SEQ
:
11455 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11457 case OMP_CLAUSE_LASTPRIVATE
:
11458 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11459 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
11460 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11462 case OMP_CLAUSE_COLLAPSE
:
11465 for (i
= 0; i
< 3; i
++)
11466 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11467 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11470 case OMP_CLAUSE_LINEAR
:
11471 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11472 WALK_SUBTREE (OMP_CLAUSE_LINEAR_STEP (*tp
));
11473 WALK_SUBTREE (OMP_CLAUSE_LINEAR_STMT (*tp
));
11474 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11476 case OMP_CLAUSE_ALIGNED
:
11477 case OMP_CLAUSE_FROM
:
11478 case OMP_CLAUSE_TO
:
11479 case OMP_CLAUSE_MAP
:
11480 case OMP_CLAUSE__CACHE_
:
11481 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11482 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 1));
11483 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11485 case OMP_CLAUSE_REDUCTION
:
11488 for (i
= 0; i
< 4; i
++)
11489 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11490 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11494 gcc_unreachable ();
11502 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11503 But, we only want to walk once. */
11504 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11505 for (i
= 0; i
< len
; ++i
)
11506 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11507 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11511 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11512 defining. We only want to walk into these fields of a type in this
11513 case and not in the general case of a mere reference to the type.
11515 The criterion is as follows: if the field can be an expression, it
11516 must be walked only here. This should be in keeping with the fields
11517 that are directly gimplified in gimplify_type_sizes in order for the
11518 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11519 variable-sized types.
11521 Note that DECLs get walked as part of processing the BIND_EXPR. */
11522 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11524 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11525 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11528 /* Call the function for the type. See if it returns anything or
11529 doesn't want us to continue. If we are to continue, walk both
11530 the normal fields and those for the declaration case. */
11531 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11532 if (result
|| !walk_subtrees
)
11535 /* But do not walk a pointed-to type since it may itself need to
11536 be walked in the declaration case if it isn't anonymous. */
11537 if (!POINTER_TYPE_P (*type_p
))
11539 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11544 /* If this is a record type, also walk the fields. */
11545 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11549 for (field
= TYPE_FIELDS (*type_p
); field
;
11550 field
= DECL_CHAIN (field
))
11552 /* We'd like to look at the type of the field, but we can
11553 easily get infinite recursion. So assume it's pointed
11554 to elsewhere in the tree. Also, ignore things that
11556 if (TREE_CODE (field
) != FIELD_DECL
)
11559 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11560 WALK_SUBTREE (DECL_SIZE (field
));
11561 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11562 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11563 WALK_SUBTREE (DECL_QUALIFIER (field
));
11567 /* Same for scalar types. */
11568 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11569 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11570 || TREE_CODE (*type_p
) == INTEGER_TYPE
11571 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11572 || TREE_CODE (*type_p
) == REAL_TYPE
)
11574 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11575 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11578 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11579 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11584 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11588 /* Walk over all the sub-trees of this operand. */
11589 len
= TREE_OPERAND_LENGTH (*tp
);
11591 /* Go through the subtrees. We need to do this in forward order so
11592 that the scope of a FOR_EXPR is handled properly. */
11595 for (i
= 0; i
< len
- 1; ++i
)
11596 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11597 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11600 /* If this is a type, walk the needed fields in the type. */
11601 else if (TYPE_P (*tp
))
11602 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11606 /* We didn't find what we were looking for. */
11609 #undef WALK_SUBTREE_TAIL
11611 #undef WALK_SUBTREE
11613 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11616 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11621 hash_set
<tree
> pset
;
11622 result
= walk_tree_1 (tp
, func
, data
, &pset
, lh
);
11628 tree_block (tree t
)
11630 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11632 if (IS_EXPR_CODE_CLASS (c
))
11633 return LOCATION_BLOCK (t
->exp
.locus
);
11634 gcc_unreachable ();
11639 tree_set_block (tree t
, tree b
)
11641 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11643 if (IS_EXPR_CODE_CLASS (c
))
11646 t
->exp
.locus
= COMBINE_LOCATION_DATA (line_table
, t
->exp
.locus
, b
);
11648 t
->exp
.locus
= LOCATION_LOCUS (t
->exp
.locus
);
11651 gcc_unreachable ();
11654 /* Create a nameless artificial label and put it in the current
11655 function context. The label has a location of LOC. Returns the
11656 newly created label. */
11659 create_artificial_label (location_t loc
)
11661 tree lab
= build_decl (loc
,
11662 LABEL_DECL
, NULL_TREE
, void_type_node
);
11664 DECL_ARTIFICIAL (lab
) = 1;
11665 DECL_IGNORED_P (lab
) = 1;
11666 DECL_CONTEXT (lab
) = current_function_decl
;
11670 /* Given a tree, try to return a useful variable name that we can use
11671 to prefix a temporary that is being assigned the value of the tree.
11672 I.E. given <temp> = &A, return A. */
11677 tree stripped_decl
;
11680 STRIP_NOPS (stripped_decl
);
11681 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11682 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11683 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11685 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11688 return IDENTIFIER_POINTER (name
);
11692 switch (TREE_CODE (stripped_decl
))
11695 return get_name (TREE_OPERAND (stripped_decl
, 0));
11702 /* Return true if TYPE has a variable argument list. */
11705 stdarg_p (const_tree fntype
)
11707 function_args_iterator args_iter
;
11708 tree n
= NULL_TREE
, t
;
11713 FOREACH_FUNCTION_ARGS (fntype
, t
, args_iter
)
11718 return n
!= NULL_TREE
&& n
!= void_type_node
;
11721 /* Return true if TYPE has a prototype. */
11724 prototype_p (const_tree fntype
)
11728 gcc_assert (fntype
!= NULL_TREE
);
11730 t
= TYPE_ARG_TYPES (fntype
);
11731 return (t
!= NULL_TREE
);
11734 /* If BLOCK is inlined from an __attribute__((__artificial__))
11735 routine, return pointer to location from where it has been
11738 block_nonartificial_location (tree block
)
11740 location_t
*ret
= NULL
;
11742 while (block
&& TREE_CODE (block
) == BLOCK
11743 && BLOCK_ABSTRACT_ORIGIN (block
))
11745 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11747 while (TREE_CODE (ao
) == BLOCK
11748 && BLOCK_ABSTRACT_ORIGIN (ao
)
11749 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
11750 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
11752 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11754 /* If AO is an artificial inline, point RET to the
11755 call site locus at which it has been inlined and continue
11756 the loop, in case AO's caller is also an artificial
11758 if (DECL_DECLARED_INLINE_P (ao
)
11759 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11760 ret
= &BLOCK_SOURCE_LOCATION (block
);
11764 else if (TREE_CODE (ao
) != BLOCK
)
11767 block
= BLOCK_SUPERCONTEXT (block
);
11773 /* If EXP is inlined from an __attribute__((__artificial__))
11774 function, return the location of the original call expression. */
11777 tree_nonartificial_location (tree exp
)
11779 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11784 return EXPR_LOCATION (exp
);
11788 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11791 /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11794 cl_option_hasher::hash (tree x
)
11796 const_tree
const t
= x
;
11800 hashval_t hash
= 0;
11802 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11804 p
= (const char *)TREE_OPTIMIZATION (t
);
11805 len
= sizeof (struct cl_optimization
);
11808 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11809 return cl_target_option_hash (TREE_TARGET_OPTION (t
));
11812 gcc_unreachable ();
11814 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11816 for (i
= 0; i
< len
; i
++)
11818 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
11823 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11824 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11828 cl_option_hasher::equal (tree x
, tree y
)
11830 const_tree
const xt
= x
;
11831 const_tree
const yt
= y
;
11836 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11839 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11841 xp
= (const char *)TREE_OPTIMIZATION (xt
);
11842 yp
= (const char *)TREE_OPTIMIZATION (yt
);
11843 len
= sizeof (struct cl_optimization
);
11846 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11848 return cl_target_option_eq (TREE_TARGET_OPTION (xt
),
11849 TREE_TARGET_OPTION (yt
));
11853 gcc_unreachable ();
11855 return (memcmp (xp
, yp
, len
) == 0);
11858 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */
11861 build_optimization_node (struct gcc_options
*opts
)
11865 /* Use the cache of optimization nodes. */
11867 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
11870 tree
*slot
= cl_option_hash_table
->find_slot (cl_optimization_node
, INSERT
);
11874 /* Insert this one into the hash table. */
11875 t
= cl_optimization_node
;
11878 /* Make a new node for next time round. */
11879 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
11885 /* Build a TARGET_OPTION_NODE based on the options in OPTS. */
11888 build_target_option_node (struct gcc_options
*opts
)
11892 /* Use the cache of optimization nodes. */
11894 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
11897 tree
*slot
= cl_option_hash_table
->find_slot (cl_target_option_node
, INSERT
);
11901 /* Insert this one into the hash table. */
11902 t
= cl_target_option_node
;
11905 /* Make a new node for next time round. */
11906 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
11912 /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
11913 so that they aren't saved during PCH writing. */
11916 prepare_target_option_nodes_for_pch (void)
11918 hash_table
<cl_option_hasher
>::iterator iter
= cl_option_hash_table
->begin ();
11919 for (; iter
!= cl_option_hash_table
->end (); ++iter
)
11920 if (TREE_CODE (*iter
) == TARGET_OPTION_NODE
)
11921 TREE_TARGET_GLOBALS (*iter
) = NULL
;
11924 /* Determine the "ultimate origin" of a block. The block may be an inlined
11925 instance of an inlined instance of a block which is local to an inline
11926 function, so we have to trace all of the way back through the origin chain
11927 to find out what sort of node actually served as the original seed for the
11931 block_ultimate_origin (const_tree block
)
11933 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
11935 /* BLOCK_ABSTRACT_ORIGIN can point to itself; ignore that if
11936 we're trying to output the abstract instance of this function. */
11937 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
11940 if (immediate_origin
== NULL_TREE
)
11945 tree lookahead
= immediate_origin
;
11949 ret_val
= lookahead
;
11950 lookahead
= (TREE_CODE (ret_val
) == BLOCK
11951 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
11953 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
11955 /* The block's abstract origin chain may not be the *ultimate* origin of
11956 the block. It could lead to a DECL that has an abstract origin set.
11957 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11958 will give us if it has one). Note that DECL's abstract origins are
11959 supposed to be the most distant ancestor (or so decl_ultimate_origin
11960 claims), so we don't need to loop following the DECL origins. */
11961 if (DECL_P (ret_val
))
11962 return DECL_ORIGIN (ret_val
);
11968 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
11972 tree_nop_conversion_p (const_tree outer_type
, const_tree inner_type
)
11974 /* Use precision rather then machine mode when we can, which gives
11975 the correct answer even for submode (bit-field) types. */
11976 if ((INTEGRAL_TYPE_P (outer_type
)
11977 || POINTER_TYPE_P (outer_type
)
11978 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
11979 && (INTEGRAL_TYPE_P (inner_type
)
11980 || POINTER_TYPE_P (inner_type
)
11981 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
11982 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
11984 /* Otherwise fall back on comparing machine modes (e.g. for
11985 aggregate types, floats). */
11986 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
11989 /* Return true iff conversion in EXP generates no instruction. Mark
11990 it inline so that we fully inline into the stripping functions even
11991 though we have two uses of this function. */
11994 tree_nop_conversion (const_tree exp
)
11996 tree outer_type
, inner_type
;
11998 if (!CONVERT_EXPR_P (exp
)
11999 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
12001 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
12004 outer_type
= TREE_TYPE (exp
);
12005 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
12010 return tree_nop_conversion_p (outer_type
, inner_type
);
12013 /* Return true iff conversion in EXP generates no instruction. Don't
12014 consider conversions changing the signedness. */
12017 tree_sign_nop_conversion (const_tree exp
)
12019 tree outer_type
, inner_type
;
12021 if (!tree_nop_conversion (exp
))
12024 outer_type
= TREE_TYPE (exp
);
12025 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
12027 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
12028 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
12031 /* Strip conversions from EXP according to tree_nop_conversion and
12032 return the resulting expression. */
12035 tree_strip_nop_conversions (tree exp
)
12037 while (tree_nop_conversion (exp
))
12038 exp
= TREE_OPERAND (exp
, 0);
12042 /* Strip conversions from EXP according to tree_sign_nop_conversion
12043 and return the resulting expression. */
12046 tree_strip_sign_nop_conversions (tree exp
)
12048 while (tree_sign_nop_conversion (exp
))
12049 exp
= TREE_OPERAND (exp
, 0);
12053 /* Avoid any floating point extensions from EXP. */
12055 strip_float_extensions (tree exp
)
12057 tree sub
, expt
, subt
;
12059 /* For floating point constant look up the narrowest type that can hold
12060 it properly and handle it like (type)(narrowest_type)constant.
12061 This way we can optimize for instance a=a*2.0 where "a" is float
12062 but 2.0 is double constant. */
12063 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
12065 REAL_VALUE_TYPE orig
;
12068 orig
= TREE_REAL_CST (exp
);
12069 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
12070 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
12071 type
= float_type_node
;
12072 else if (TYPE_PRECISION (TREE_TYPE (exp
))
12073 > TYPE_PRECISION (double_type_node
)
12074 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
12075 type
= double_type_node
;
12077 return build_real (type
, real_value_truncate (TYPE_MODE (type
), orig
));
12080 if (!CONVERT_EXPR_P (exp
))
12083 sub
= TREE_OPERAND (exp
, 0);
12084 subt
= TREE_TYPE (sub
);
12085 expt
= TREE_TYPE (exp
);
12087 if (!FLOAT_TYPE_P (subt
))
12090 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
12093 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
12096 return strip_float_extensions (sub
);
12099 /* Strip out all handled components that produce invariant
12103 strip_invariant_refs (const_tree op
)
12105 while (handled_component_p (op
))
12107 switch (TREE_CODE (op
))
12110 case ARRAY_RANGE_REF
:
12111 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
12112 || TREE_OPERAND (op
, 2) != NULL_TREE
12113 || TREE_OPERAND (op
, 3) != NULL_TREE
)
12117 case COMPONENT_REF
:
12118 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
12124 op
= TREE_OPERAND (op
, 0);
12130 static GTY(()) tree gcc_eh_personality_decl
;
12132 /* Return the GCC personality function decl. */
12135 lhd_gcc_personality (void)
12137 if (!gcc_eh_personality_decl
)
12138 gcc_eh_personality_decl
= build_personality_function ("gcc");
12139 return gcc_eh_personality_decl
;
12142 /* TARGET is a call target of GIMPLE call statement
12143 (obtained by gimple_call_fn). Return true if it is
12144 OBJ_TYPE_REF representing an virtual call of C++ method.
12145 (As opposed to OBJ_TYPE_REF representing objc calls
12146 through a cast where middle-end devirtualization machinery
12150 virtual_method_call_p (const_tree target
)
12152 if (TREE_CODE (target
) != OBJ_TYPE_REF
)
12154 tree t
= TREE_TYPE (target
);
12155 gcc_checking_assert (TREE_CODE (t
) == POINTER_TYPE
);
12157 if (TREE_CODE (t
) == FUNCTION_TYPE
)
12159 gcc_checking_assert (TREE_CODE (t
) == METHOD_TYPE
);
12160 /* If we do not have BINFO associated, it means that type was built
12161 without devirtualization enabled. Do not consider this a virtual
12163 if (!TYPE_BINFO (obj_type_ref_class (target
)))
12168 /* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */
12171 obj_type_ref_class (const_tree ref
)
12173 gcc_checking_assert (TREE_CODE (ref
) == OBJ_TYPE_REF
);
12174 ref
= TREE_TYPE (ref
);
12175 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12176 ref
= TREE_TYPE (ref
);
12177 /* We look for type THIS points to. ObjC also builds
12178 OBJ_TYPE_REF with non-method calls, Their first parameter
12179 ID however also corresponds to class type. */
12180 gcc_checking_assert (TREE_CODE (ref
) == METHOD_TYPE
12181 || TREE_CODE (ref
) == FUNCTION_TYPE
);
12182 ref
= TREE_VALUE (TYPE_ARG_TYPES (ref
));
12183 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12184 return TREE_TYPE (ref
);
12187 /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12190 lookup_binfo_at_offset (tree binfo
, tree type
, HOST_WIDE_INT pos
)
12193 tree base_binfo
, b
;
12195 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
12196 if (pos
== tree_to_shwi (BINFO_OFFSET (base_binfo
))
12197 && types_same_for_odr (TREE_TYPE (base_binfo
), type
))
12199 else if ((b
= lookup_binfo_at_offset (base_binfo
, type
, pos
)) != NULL
)
12204 /* Try to find a base info of BINFO that would have its field decl at offset
12205 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12206 found, return, otherwise return NULL_TREE. */
12209 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
12211 tree type
= BINFO_TYPE (binfo
);
12215 HOST_WIDE_INT pos
, size
;
12219 if (types_same_for_odr (type
, expected_type
))
12224 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
12226 if (TREE_CODE (fld
) != FIELD_DECL
|| !DECL_ARTIFICIAL (fld
))
12229 pos
= int_bit_position (fld
);
12230 size
= tree_to_uhwi (DECL_SIZE (fld
));
12231 if (pos
<= offset
&& (pos
+ size
) > offset
)
12234 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
12237 /* Offset 0 indicates the primary base, whose vtable contents are
12238 represented in the binfo for the derived class. */
12239 else if (offset
!= 0)
12241 tree found_binfo
= NULL
, base_binfo
;
12242 /* Offsets in BINFO are in bytes relative to the whole structure
12243 while POS is in bits relative to the containing field. */
12244 int binfo_offset
= (tree_to_shwi (BINFO_OFFSET (binfo
)) + pos
12247 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
12248 if (tree_to_shwi (BINFO_OFFSET (base_binfo
)) == binfo_offset
12249 && types_same_for_odr (TREE_TYPE (base_binfo
), TREE_TYPE (fld
)))
12251 found_binfo
= base_binfo
;
12255 binfo
= found_binfo
;
12257 binfo
= lookup_binfo_at_offset (binfo
, TREE_TYPE (fld
),
12261 type
= TREE_TYPE (fld
);
12266 /* Returns true if X is a typedef decl. */
12269 is_typedef_decl (const_tree x
)
12271 return (x
&& TREE_CODE (x
) == TYPE_DECL
12272 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
12275 /* Returns true iff TYPE is a type variant created for a typedef. */
12278 typedef_variant_p (const_tree type
)
12280 return is_typedef_decl (TYPE_NAME (type
));
12283 /* Warn about a use of an identifier which was marked deprecated. */
12285 warn_deprecated_use (tree node
, tree attr
)
12289 if (node
== 0 || !warn_deprecated_decl
)
12295 attr
= DECL_ATTRIBUTES (node
);
12296 else if (TYPE_P (node
))
12298 tree decl
= TYPE_STUB_DECL (node
);
12300 attr
= lookup_attribute ("deprecated",
12301 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
12306 attr
= lookup_attribute ("deprecated", attr
);
12309 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
12317 w
= warning (OPT_Wdeprecated_declarations
,
12318 "%qD is deprecated: %s", node
, msg
);
12320 w
= warning (OPT_Wdeprecated_declarations
,
12321 "%qD is deprecated", node
);
12323 inform (DECL_SOURCE_LOCATION (node
), "declared here");
12325 else if (TYPE_P (node
))
12327 tree what
= NULL_TREE
;
12328 tree decl
= TYPE_STUB_DECL (node
);
12330 if (TYPE_NAME (node
))
12332 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
12333 what
= TYPE_NAME (node
);
12334 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
12335 && DECL_NAME (TYPE_NAME (node
)))
12336 what
= DECL_NAME (TYPE_NAME (node
));
12344 w
= warning (OPT_Wdeprecated_declarations
,
12345 "%qE is deprecated: %s", what
, msg
);
12347 w
= warning (OPT_Wdeprecated_declarations
,
12348 "%qE is deprecated", what
);
12353 w
= warning (OPT_Wdeprecated_declarations
,
12354 "type is deprecated: %s", msg
);
12356 w
= warning (OPT_Wdeprecated_declarations
,
12357 "type is deprecated");
12360 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
12367 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
12370 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
12375 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
12378 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
12384 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12385 somewhere in it. */
12388 contains_bitfld_component_ref_p (const_tree ref
)
12390 while (handled_component_p (ref
))
12392 if (TREE_CODE (ref
) == COMPONENT_REF
12393 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
12395 ref
= TREE_OPERAND (ref
, 0);
12401 /* Try to determine whether a TRY_CATCH expression can fall through.
12402 This is a subroutine of block_may_fallthru. */
12405 try_catch_may_fallthru (const_tree stmt
)
12407 tree_stmt_iterator i
;
12409 /* If the TRY block can fall through, the whole TRY_CATCH can
12411 if (block_may_fallthru (TREE_OPERAND (stmt
, 0)))
12414 i
= tsi_start (TREE_OPERAND (stmt
, 1));
12415 switch (TREE_CODE (tsi_stmt (i
)))
12418 /* We expect to see a sequence of CATCH_EXPR trees, each with a
12419 catch expression and a body. The whole TRY_CATCH may fall
12420 through iff any of the catch bodies falls through. */
12421 for (; !tsi_end_p (i
); tsi_next (&i
))
12423 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i
))))
12428 case EH_FILTER_EXPR
:
12429 /* The exception filter expression only matters if there is an
12430 exception. If the exception does not match EH_FILTER_TYPES,
12431 we will execute EH_FILTER_FAILURE, and we will fall through
12432 if that falls through. If the exception does match
12433 EH_FILTER_TYPES, the stack unwinder will continue up the
12434 stack, so we will not fall through. We don't know whether we
12435 will throw an exception which matches EH_FILTER_TYPES or not,
12436 so we just ignore EH_FILTER_TYPES and assume that we might
12437 throw an exception which doesn't match. */
12438 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i
)));
12441 /* This case represents statements to be executed when an
12442 exception occurs. Those statements are implicitly followed
12443 by a RESX statement to resume execution after the exception.
12444 So in this case the TRY_CATCH never falls through. */
12449 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12450 need not be 100% accurate; simply be conservative and return true if we
12451 don't know. This is used only to avoid stupidly generating extra code.
12452 If we're wrong, we'll just delete the extra code later. */
12455 block_may_fallthru (const_tree block
)
12457 /* This CONST_CAST is okay because expr_last returns its argument
12458 unmodified and we assign it to a const_tree. */
12459 const_tree stmt
= expr_last (CONST_CAST_TREE (block
));
12461 switch (stmt
? TREE_CODE (stmt
) : ERROR_MARK
)
12465 /* Easy cases. If the last statement of the block implies
12466 control transfer, then we can't fall through. */
12470 /* If SWITCH_LABELS is set, this is lowered, and represents a
12471 branch to a selected label and hence can not fall through.
12472 Otherwise SWITCH_BODY is set, and the switch can fall
12474 return SWITCH_LABELS (stmt
) == NULL_TREE
;
12477 if (block_may_fallthru (COND_EXPR_THEN (stmt
)))
12479 return block_may_fallthru (COND_EXPR_ELSE (stmt
));
12482 return block_may_fallthru (BIND_EXPR_BODY (stmt
));
12484 case TRY_CATCH_EXPR
:
12485 return try_catch_may_fallthru (stmt
);
12487 case TRY_FINALLY_EXPR
:
12488 /* The finally clause is always executed after the try clause,
12489 so if it does not fall through, then the try-finally will not
12490 fall through. Otherwise, if the try clause does not fall
12491 through, then when the finally clause falls through it will
12492 resume execution wherever the try clause was going. So the
12493 whole try-finally will only fall through if both the try
12494 clause and the finally clause fall through. */
12495 return (block_may_fallthru (TREE_OPERAND (stmt
, 0))
12496 && block_may_fallthru (TREE_OPERAND (stmt
, 1)));
12499 if (TREE_CODE (TREE_OPERAND (stmt
, 1)) == CALL_EXPR
)
12500 stmt
= TREE_OPERAND (stmt
, 1);
12506 /* Functions that do not return do not fall through. */
12507 return (call_expr_flags (stmt
) & ECF_NORETURN
) == 0;
12509 case CLEANUP_POINT_EXPR
:
12510 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
12513 return block_may_fallthru (TREE_OPERAND (stmt
, 1));
12519 return lang_hooks
.block_may_fallthru (stmt
);
12523 /* True if we are using EH to handle cleanups. */
12524 static bool using_eh_for_cleanups_flag
= false;
12526 /* This routine is called from front ends to indicate eh should be used for
12529 using_eh_for_cleanups (void)
12531 using_eh_for_cleanups_flag
= true;
12534 /* Query whether EH is used for cleanups. */
12536 using_eh_for_cleanups_p (void)
12538 return using_eh_for_cleanups_flag
;
12541 /* Wrapper for tree_code_name to ensure that tree code is valid */
12543 get_tree_code_name (enum tree_code code
)
12545 const char *invalid
= "<invalid tree code>";
12547 if (code
>= MAX_TREE_CODES
)
12550 return tree_code_name
[code
];
12553 /* Drops the TREE_OVERFLOW flag from T. */
12556 drop_tree_overflow (tree t
)
12558 gcc_checking_assert (TREE_OVERFLOW (t
));
12560 /* For tree codes with a sharing machinery re-build the result. */
12561 if (TREE_CODE (t
) == INTEGER_CST
)
12562 return wide_int_to_tree (TREE_TYPE (t
), t
);
12564 /* Otherwise, as all tcc_constants are possibly shared, copy the node
12565 and drop the flag. */
12567 TREE_OVERFLOW (t
) = 0;
12571 /* Given a memory reference expression T, return its base address.
12572 The base address of a memory reference expression is the main
12573 object being referenced. For instance, the base address for
12574 'array[i].fld[j]' is 'array'. You can think of this as stripping
12575 away the offset part from a memory address.
12577 This function calls handled_component_p to strip away all the inner
12578 parts of the memory reference until it reaches the base object. */
12581 get_base_address (tree t
)
12583 while (handled_component_p (t
))
12584 t
= TREE_OPERAND (t
, 0);
12586 if ((TREE_CODE (t
) == MEM_REF
12587 || TREE_CODE (t
) == TARGET_MEM_REF
)
12588 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
12589 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
12591 /* ??? Either the alias oracle or all callers need to properly deal
12592 with WITH_SIZE_EXPRs before we can look through those. */
12593 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
12599 /* Return a tree of sizetype representing the size, in bytes, of the element
12600 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12603 array_ref_element_size (tree exp
)
12605 tree aligned_size
= TREE_OPERAND (exp
, 3);
12606 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12607 location_t loc
= EXPR_LOCATION (exp
);
12609 /* If a size was specified in the ARRAY_REF, it's the size measured
12610 in alignment units of the element type. So multiply by that value. */
12613 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12614 sizetype from another type of the same width and signedness. */
12615 if (TREE_TYPE (aligned_size
) != sizetype
)
12616 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
12617 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
12618 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
12621 /* Otherwise, take the size from that of the element type. Substitute
12622 any PLACEHOLDER_EXPR that we have. */
12624 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
12627 /* Return a tree representing the lower bound of the array mentioned in
12628 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12631 array_ref_low_bound (tree exp
)
12633 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12635 /* If a lower bound is specified in EXP, use it. */
12636 if (TREE_OPERAND (exp
, 2))
12637 return TREE_OPERAND (exp
, 2);
12639 /* Otherwise, if there is a domain type and it has a lower bound, use it,
12640 substituting for a PLACEHOLDER_EXPR as needed. */
12641 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
12642 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
12644 /* Otherwise, return a zero of the appropriate type. */
12645 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
12648 /* Return a tree representing the upper bound of the array mentioned in
12649 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12652 array_ref_up_bound (tree exp
)
12654 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12656 /* If there is a domain type and it has an upper bound, use it, substituting
12657 for a PLACEHOLDER_EXPR as needed. */
12658 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
12659 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
12661 /* Otherwise fail. */
12665 /* Returns true if REF is an array reference to an array at the end of
12666 a structure. If this is the case, the array may be allocated larger
12667 than its upper bound implies. */
12670 array_at_struct_end_p (tree ref
)
12672 if (TREE_CODE (ref
) != ARRAY_REF
12673 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
12676 while (handled_component_p (ref
))
12678 /* If the reference chain contains a component reference to a
12679 non-union type and there follows another field the reference
12680 is not at the end of a structure. */
12681 if (TREE_CODE (ref
) == COMPONENT_REF
12682 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
12684 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
12685 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
12686 nextf
= DECL_CHAIN (nextf
);
12691 ref
= TREE_OPERAND (ref
, 0);
12694 /* If the reference is based on a declared entity, the size of the array
12695 is constrained by its given domain. */
12702 /* Return a tree representing the offset, in bytes, of the field referenced
12703 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
12706 component_ref_field_offset (tree exp
)
12708 tree aligned_offset
= TREE_OPERAND (exp
, 2);
12709 tree field
= TREE_OPERAND (exp
, 1);
12710 location_t loc
= EXPR_LOCATION (exp
);
12712 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
12713 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
12715 if (aligned_offset
)
12717 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12718 sizetype from another type of the same width and signedness. */
12719 if (TREE_TYPE (aligned_offset
) != sizetype
)
12720 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
12721 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
12722 size_int (DECL_OFFSET_ALIGN (field
)
12726 /* Otherwise, take the offset from that of the field. Substitute
12727 any PLACEHOLDER_EXPR that we have. */
12729 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
12732 /* Return the machine mode of T. For vectors, returns the mode of the
12733 inner type. The main use case is to feed the result to HONOR_NANS,
12734 avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
12737 element_mode (const_tree t
)
12741 if (VECTOR_TYPE_P (t
) || TREE_CODE (t
) == COMPLEX_TYPE
)
12743 return TYPE_MODE (t
);
12747 /* Veirfy that basic properties of T match TV and thus T can be a variant of
12748 TV. TV should be the more specified variant (i.e. the main variant). */
12751 verify_type_variant (const_tree t
, tree tv
)
12753 /* Type variant can differ by:
12755 - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
12756 ENCODE_QUAL_ADDR_SPACE.
12757 - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
12758 in this case some values may not be set in the variant types
12759 (see TYPE_COMPLETE_P checks).
12760 - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
12761 - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
12762 - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
12763 - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
12764 - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
12765 this is necessary to make it possible to merge types form different TUs
12766 - arrays, pointers and references may have TREE_TYPE that is a variant
12767 of TREE_TYPE of their main variants.
12768 - aggregates may have new TYPE_FIELDS list that list variants of
12769 the main variant TYPE_FIELDS.
12770 - vector types may differ by TYPE_VECTOR_OPAQUE
12771 - TYPE_METHODS is always NULL for vairant types and maintained for
12775 /* Convenience macro for matching individual fields. */
12776 #define verify_variant_match(flag) \
12778 if (flag (tv) != flag (t)) \
12780 error ("type variant differs by " #flag "."); \
12786 /* tree_base checks. */
12788 verify_variant_match (TREE_CODE
);
12789 /* FIXME: Ada builds non-artificial variants of artificial types. */
12790 if (TYPE_ARTIFICIAL (tv
) && 0)
12791 verify_variant_match (TYPE_ARTIFICIAL
);
12792 if (POINTER_TYPE_P (tv
))
12793 verify_variant_match (TYPE_REF_CAN_ALIAS_ALL
);
12794 /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
12795 verify_variant_match (TYPE_UNSIGNED
);
12796 verify_variant_match (TYPE_ALIGN_OK
);
12797 verify_variant_match (TYPE_PACKED
);
12798 if (TREE_CODE (t
) == REFERENCE_TYPE
)
12799 verify_variant_match (TYPE_REF_IS_RVALUE
);
12800 verify_variant_match (TYPE_SATURATING
);
12801 /* FIXME: This check trigger during libstdc++ build. */
12802 if (RECORD_OR_UNION_TYPE_P (t
) && COMPLETE_TYPE_P (t
) && 0)
12803 verify_variant_match (TYPE_FINAL_P
);
12805 /* tree_type_common checks. */
12807 if (COMPLETE_TYPE_P (t
))
12809 verify_variant_match (TYPE_SIZE
);
12810 verify_variant_match (TYPE_MODE
);
12811 if (TYPE_SIZE_UNIT (t
) != TYPE_SIZE_UNIT (tv
)
12812 /* FIXME: ideally we should compare pointer equality, but java FE
12813 produce variants where size is INTEGER_CST of different type (int
12814 wrt size_type) during libjava biuld. */
12815 && !operand_equal_p (TYPE_SIZE_UNIT (t
), TYPE_SIZE_UNIT (tv
), 0))
12817 error ("type variant has different TYPE_SIZE_UNIT");
12819 error ("type variant's TYPE_SIZE_UNIT");
12820 debug_tree (TYPE_SIZE_UNIT (tv
));
12821 error ("type's TYPE_SIZE_UNIT");
12822 debug_tree (TYPE_SIZE_UNIT (t
));
12826 verify_variant_match (TYPE_PRECISION
);
12827 verify_variant_match (TYPE_NEEDS_CONSTRUCTING
);
12828 if (RECORD_OR_UNION_TYPE_P (t
))
12829 verify_variant_match (TYPE_TRANSPARENT_AGGR
);
12830 else if (TREE_CODE (t
) == ARRAY_TYPE
)
12831 verify_variant_match (TYPE_NONALIASED_COMPONENT
);
12832 /* During LTO we merge variant lists from diferent translation units
12833 that may differ BY TYPE_CONTEXT that in turn may point
12834 to TRANSLATION_UNIT_DECL.
12835 Ada also builds variants of types with different TYPE_CONTEXT. */
12836 if ((!in_lto_p
|| !TYPE_FILE_SCOPE_P (t
)) && 0)
12837 verify_variant_match (TYPE_CONTEXT
);
12838 verify_variant_match (TYPE_STRING_FLAG
);
12839 if (TYPE_ALIAS_SET_KNOWN_P (t
) && TYPE_ALIAS_SET_KNOWN_P (tv
))
12840 verify_variant_match (TYPE_ALIAS_SET
);
12842 /* tree_type_non_common checks. */
12844 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
12845 and dangle the pointer from time to time. */
12846 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_VFIELD (t
) != TYPE_VFIELD (tv
)
12847 && (in_lto_p
|| !TYPE_VFIELD (tv
)
12848 || TREE_CODE (TYPE_VFIELD (tv
)) != TREE_LIST
))
12850 error ("type variant has different TYPE_VFIELD");
12854 if ((TREE_CODE (t
) == ENUMERAL_TYPE
&& COMPLETE_TYPE_P (t
))
12855 || TREE_CODE (t
) == INTEGER_TYPE
12856 || TREE_CODE (t
) == BOOLEAN_TYPE
12857 || TREE_CODE (t
) == REAL_TYPE
12858 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
12860 verify_variant_match (TYPE_MAX_VALUE
);
12861 verify_variant_match (TYPE_MIN_VALUE
);
12863 if (TREE_CODE (t
) == METHOD_TYPE
)
12864 verify_variant_match (TYPE_METHOD_BASETYPE
);
12865 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_METHODS (t
))
12867 error ("type variant has TYPE_METHODS");
12871 if (TREE_CODE (t
) == OFFSET_TYPE
)
12872 verify_variant_match (TYPE_OFFSET_BASETYPE
);
12873 if (TREE_CODE (t
) == ARRAY_TYPE
)
12874 verify_variant_match (TYPE_ARRAY_MAX_SIZE
);
12875 /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
12876 or even type's main variant. This is needed to make bootstrap pass
12877 and the bug seems new in GCC 5.
12878 C++ FE should be updated to make this consistent and we should check
12879 that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
12880 is a match with main variant.
12882 Also disable the check for Java for now because of parser hack that builds
12883 first an dummy BINFO and then sometimes replace it by real BINFO in some
12885 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
) && TYPE_BINFO (tv
)
12886 && TYPE_BINFO (t
) != TYPE_BINFO (tv
)
12887 /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
12888 Since there is no cheap way to tell C++/Java type w/o LTO, do checking
12889 at LTO time only. */
12890 && (in_lto_p
&& odr_type_p (t
)))
12892 error ("type variant has different TYPE_BINFO");
12894 error ("type variant's TYPE_BINFO");
12895 debug_tree (TYPE_BINFO (tv
));
12896 error ("type's TYPE_BINFO");
12897 debug_tree (TYPE_BINFO (t
));
12901 /* Check various uses of TYPE_VALUES_RAW. */
12902 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
12903 verify_variant_match (TYPE_VALUES
);
12904 else if (TREE_CODE (t
) == ARRAY_TYPE
)
12905 verify_variant_match (TYPE_DOMAIN
);
12906 /* Permit incomplete variants of complete type. While FEs may complete
12907 all variants, this does not happen for C++ templates in all cases. */
12908 else if (RECORD_OR_UNION_TYPE_P (t
)
12909 && COMPLETE_TYPE_P (t
)
12910 && TYPE_FIELDS (t
) != TYPE_FIELDS (tv
))
12914 /* Fortran builds qualified variants as new records with items of
12915 qualified type. Verify that they looks same. */
12916 for (f1
= TYPE_FIELDS (t
), f2
= TYPE_FIELDS (tv
);
12918 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
12919 if (TREE_CODE (f1
) != FIELD_DECL
|| TREE_CODE (f2
) != FIELD_DECL
12920 || (TYPE_MAIN_VARIANT (TREE_TYPE (f1
))
12921 != TYPE_MAIN_VARIANT (TREE_TYPE (f2
))
12922 /* FIXME: gfc_nonrestricted_type builds all types as variants
12923 with exception of pointer types. It deeply copies the type
12924 which means that we may end up with a variant type
12925 referring non-variant pointer. We may change it to
12926 produce types as variants, too, like
12927 objc_get_protocol_qualified_type does. */
12928 && !POINTER_TYPE_P (TREE_TYPE (f1
)))
12929 || DECL_FIELD_OFFSET (f1
) != DECL_FIELD_OFFSET (f2
)
12930 || DECL_FIELD_BIT_OFFSET (f1
) != DECL_FIELD_BIT_OFFSET (f2
))
12934 error ("type variant has different TYPE_FIELDS");
12936 error ("first mismatch is field");
12938 error ("and field");
12943 else if ((TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
))
12944 verify_variant_match (TYPE_ARG_TYPES
);
12945 /* For C++ the qualified variant of array type is really an array type
12946 of qualified TREE_TYPE.
12947 objc builds variants of pointer where pointer to type is a variant, too
12948 in objc_get_protocol_qualified_type. */
12949 if (TREE_TYPE (t
) != TREE_TYPE (tv
)
12950 && ((TREE_CODE (t
) != ARRAY_TYPE
12951 && !POINTER_TYPE_P (t
))
12952 || TYPE_MAIN_VARIANT (TREE_TYPE (t
))
12953 != TYPE_MAIN_VARIANT (TREE_TYPE (tv
))))
12955 error ("type variant has different TREE_TYPE");
12957 error ("type variant's TREE_TYPE");
12958 debug_tree (TREE_TYPE (tv
));
12959 error ("type's TREE_TYPE");
12960 debug_tree (TREE_TYPE (t
));
12963 if (type_with_alias_set_p (t
)
12964 && !gimple_canonical_types_compatible_p (t
, tv
, false))
12966 error ("type is not compatible with its vairant");
12968 error ("type variant's TREE_TYPE");
12969 debug_tree (TREE_TYPE (tv
));
12970 error ("type's TREE_TYPE");
12971 debug_tree (TREE_TYPE (t
));
12975 #undef verify_variant_match
12979 /* The TYPE_CANONICAL merging machinery. It should closely resemble
12980 the middle-end types_compatible_p function. It needs to avoid
12981 claiming types are different for types that should be treated
12982 the same with respect to TBAA. Canonical types are also used
12983 for IL consistency checks via the useless_type_conversion_p
12984 predicate which does not handle all type kinds itself but falls
12985 back to pointer-comparison of TYPE_CANONICAL for aggregates
12988 /* Return true iff T1 and T2 are structurally identical for what
12990 This function is used both by lto.c canonical type merging and by the
12991 verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
12992 that have TYPE_CANONICAL defined and assume them equivalent. */
12995 gimple_canonical_types_compatible_p (const_tree t1
, const_tree t2
,
12996 bool trust_type_canonical
)
12998 /* Type variants should be same as the main variant. When not doing sanity
12999 checking to verify this fact, go to main variants and save some work. */
13000 if (trust_type_canonical
)
13002 t1
= TYPE_MAIN_VARIANT (t1
);
13003 t2
= TYPE_MAIN_VARIANT (t2
);
13006 /* Check first for the obvious case of pointer identity. */
13010 /* Check that we have two types to compare. */
13011 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
13014 /* We consider complete types always compatible with incomplete type.
13015 This does not make sense for canonical type calculation and thus we
13016 need to ensure that we are never called on it.
13018 FIXME: For more correctness the function probably should have three modes
13019 1) mode assuming that types are complete mathcing their structure
13020 2) mode allowing incomplete types but producing equivalence classes
13021 and thus ignoring all info from complete types
13022 3) mode allowing incomplete types to match complete but checking
13023 compatibility between complete types.
13025 1 and 2 can be used for canonical type calculation. 3 is the real
13026 definition of type compatibility that can be used i.e. for warnings during
13027 declaration merging. */
13029 gcc_assert (!trust_type_canonical
13030 || (type_with_alias_set_p (t1
) && type_with_alias_set_p (t2
)));
13031 /* If the types have been previously registered and found equal
13033 if (TYPE_CANONICAL (t1
) && TYPE_CANONICAL (t2
)
13034 && trust_type_canonical
)
13035 return TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
);
13037 /* Can't be the same type if the types don't have the same code. */
13038 if (tree_code_for_canonical_type_merging (TREE_CODE (t1
))
13039 != tree_code_for_canonical_type_merging (TREE_CODE (t2
)))
13042 /* Qualifiers do not matter for canonical type comparison purposes. */
13044 /* Void types and nullptr types are always the same. */
13045 if (TREE_CODE (t1
) == VOID_TYPE
13046 || TREE_CODE (t1
) == NULLPTR_TYPE
)
13049 /* Can't be the same type if they have different mode. */
13050 if (TYPE_MODE (t1
) != TYPE_MODE (t2
))
13053 /* Non-aggregate types can be handled cheaply. */
13054 if (INTEGRAL_TYPE_P (t1
)
13055 || SCALAR_FLOAT_TYPE_P (t1
)
13056 || FIXED_POINT_TYPE_P (t1
)
13057 || TREE_CODE (t1
) == VECTOR_TYPE
13058 || TREE_CODE (t1
) == COMPLEX_TYPE
13059 || TREE_CODE (t1
) == OFFSET_TYPE
13060 || POINTER_TYPE_P (t1
))
13062 /* Can't be the same type if they have different sign or precision. */
13063 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
13064 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
13067 /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
13068 interoperable with "signed char". Unless all frontends are revisited
13069 to agree on these types, we must ignore the flag completely. */
13071 /* Fortran standard define C_PTR type that is compatible with every
13072 C pointer. For this reason we need to glob all pointers into one.
13073 Still pointers in different address spaces are not compatible. */
13074 if (POINTER_TYPE_P (t1
))
13076 if (TYPE_ADDR_SPACE (TREE_TYPE (t1
))
13077 != TYPE_ADDR_SPACE (TREE_TYPE (t2
)))
13081 /* Tail-recurse to components. */
13082 if (TREE_CODE (t1
) == VECTOR_TYPE
13083 || TREE_CODE (t1
) == COMPLEX_TYPE
)
13084 return gimple_canonical_types_compatible_p (TREE_TYPE (t1
),
13086 trust_type_canonical
);
13091 /* Do type-specific comparisons. */
13092 switch (TREE_CODE (t1
))
13095 /* Array types are the same if the element types are the same and
13096 the number of elements are the same. */
13097 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13098 trust_type_canonical
)
13099 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
13100 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
13104 tree i1
= TYPE_DOMAIN (t1
);
13105 tree i2
= TYPE_DOMAIN (t2
);
13107 /* For an incomplete external array, the type domain can be
13108 NULL_TREE. Check this condition also. */
13109 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
13111 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
13115 tree min1
= TYPE_MIN_VALUE (i1
);
13116 tree min2
= TYPE_MIN_VALUE (i2
);
13117 tree max1
= TYPE_MAX_VALUE (i1
);
13118 tree max2
= TYPE_MAX_VALUE (i2
);
13120 /* The minimum/maximum values have to be the same. */
13123 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
13124 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
13125 || operand_equal_p (min1
, min2
, 0))))
13128 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
13129 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
13130 || operand_equal_p (max1
, max2
, 0)))))
13138 case FUNCTION_TYPE
:
13139 /* Function types are the same if the return type and arguments types
13141 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13142 trust_type_canonical
))
13145 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
13149 tree parms1
, parms2
;
13151 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
13153 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
13155 if (!gimple_canonical_types_compatible_p
13156 (TREE_VALUE (parms1
), TREE_VALUE (parms2
),
13157 trust_type_canonical
))
13161 if (parms1
|| parms2
)
13169 case QUAL_UNION_TYPE
:
13173 /* For aggregate types, all the fields must be the same. */
13174 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
13176 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
13178 /* Skip non-fields. */
13179 while (f1
&& TREE_CODE (f1
) != FIELD_DECL
)
13180 f1
= TREE_CHAIN (f1
);
13181 while (f2
&& TREE_CODE (f2
) != FIELD_DECL
)
13182 f2
= TREE_CHAIN (f2
);
13185 /* The fields must have the same name, offset and type. */
13186 if (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
13187 || !gimple_compare_field_offset (f1
, f2
)
13188 || !gimple_canonical_types_compatible_p
13189 (TREE_TYPE (f1
), TREE_TYPE (f2
),
13190 trust_type_canonical
))
13194 /* If one aggregate has more fields than the other, they
13195 are not the same. */
13203 /* Consider all types with language specific trees in them mutually
13204 compatible. This is executed only from verify_type and false
13205 positives can be tolerated. */
13206 gcc_assert (!in_lto_p
);
13211 /* Verify type T. */
13214 verify_type (const_tree t
)
13216 bool error_found
= false;
13217 tree mv
= TYPE_MAIN_VARIANT (t
);
13220 error ("Main variant is not defined");
13221 error_found
= true;
13223 else if (mv
!= TYPE_MAIN_VARIANT (mv
))
13225 error ("TYPE_MAIN_VARIANT has different TYPE_MAIN_VARIANT");
13227 error_found
= true;
13229 else if (t
!= mv
&& !verify_type_variant (t
, mv
))
13230 error_found
= true;
13232 tree ct
= TYPE_CANONICAL (t
);
13235 else if (TYPE_CANONICAL (t
) != ct
)
13237 error ("TYPE_CANONICAL has different TYPE_CANONICAL");
13239 error_found
= true;
13241 /* Method and function types can not be used to address memory and thus
13242 TYPE_CANONICAL really matters only for determining useless conversions.
13244 FIXME: C++ FE produce declarations of builtin functions that are not
13245 compatible with main variants. */
13246 else if (TREE_CODE (t
) == FUNCTION_TYPE
)
13249 /* FIXME: gimple_canonical_types_compatible_p can not compare types
13250 with variably sized arrays because their sizes possibly
13251 gimplified to different variables. */
13252 && !variably_modified_type_p (ct
, NULL
)
13253 && !gimple_canonical_types_compatible_p (t
, ct
, false))
13255 error ("TYPE_CANONICAL is not compatible");
13257 error_found
= true;
13261 /* Check various uses of TYPE_MINVAL. */
13262 if (RECORD_OR_UNION_TYPE_P (t
))
13264 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13265 and danagle the pointer from time to time. */
13266 if (TYPE_VFIELD (t
)
13267 && TREE_CODE (TYPE_VFIELD (t
)) != FIELD_DECL
13268 && TREE_CODE (TYPE_VFIELD (t
)) != TREE_LIST
)
13270 error ("TYPE_VFIELD is not FIELD_DECL nor TREE_LIST");
13271 debug_tree (TYPE_VFIELD (t
));
13272 error_found
= true;
13275 else if (TREE_CODE (t
) == POINTER_TYPE
)
13277 if (TYPE_NEXT_PTR_TO (t
)
13278 && TREE_CODE (TYPE_NEXT_PTR_TO (t
)) != POINTER_TYPE
)
13280 error ("TYPE_NEXT_PTR_TO is not POINTER_TYPE");
13281 debug_tree (TYPE_NEXT_PTR_TO (t
));
13282 error_found
= true;
13285 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
13287 if (TYPE_NEXT_REF_TO (t
)
13288 && TREE_CODE (TYPE_NEXT_REF_TO (t
)) != REFERENCE_TYPE
)
13290 error ("TYPE_NEXT_REF_TO is not REFERENCE_TYPE");
13291 debug_tree (TYPE_NEXT_REF_TO (t
));
13292 error_found
= true;
13295 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13296 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13298 /* FIXME: The following check should pass:
13299 useless_type_conversion_p (const_cast <tree> (t),
13300 TREE_TYPE (TYPE_MIN_VALUE (t))
13301 but does not for C sizetypes in LTO. */
13303 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
13304 else if (TYPE_MINVAL (t
)
13305 && ((TREE_CODE (t
) != METHOD_TYPE
&& TREE_CODE (t
) != FUNCTION_TYPE
)
13308 error ("TYPE_MINVAL non-NULL");
13309 debug_tree (TYPE_MINVAL (t
));
13310 error_found
= true;
13313 /* Check various uses of TYPE_MAXVAL. */
13314 if (RECORD_OR_UNION_TYPE_P (t
))
13316 if (TYPE_METHODS (t
) && TREE_CODE (TYPE_METHODS (t
)) != FUNCTION_DECL
13317 && TREE_CODE (TYPE_METHODS (t
)) != TEMPLATE_DECL
13318 && TYPE_METHODS (t
) != error_mark_node
)
13320 error ("TYPE_METHODS is not FUNCTION_DECL, TEMPLATE_DECL nor error_mark_node");
13321 debug_tree (TYPE_METHODS (t
));
13322 error_found
= true;
13325 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13327 if (TYPE_METHOD_BASETYPE (t
)
13328 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != RECORD_TYPE
13329 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != UNION_TYPE
)
13331 error ("TYPE_METHOD_BASETYPE is not record nor union");
13332 debug_tree (TYPE_METHOD_BASETYPE (t
));
13333 error_found
= true;
13336 else if (TREE_CODE (t
) == OFFSET_TYPE
)
13338 if (TYPE_OFFSET_BASETYPE (t
)
13339 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != RECORD_TYPE
13340 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != UNION_TYPE
)
13342 error ("TYPE_OFFSET_BASETYPE is not record nor union");
13343 debug_tree (TYPE_OFFSET_BASETYPE (t
));
13344 error_found
= true;
13347 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13348 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13350 /* FIXME: The following check should pass:
13351 useless_type_conversion_p (const_cast <tree> (t),
13352 TREE_TYPE (TYPE_MAX_VALUE (t))
13353 but does not for C sizetypes in LTO. */
13355 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13357 if (TYPE_ARRAY_MAX_SIZE (t
)
13358 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t
)) != INTEGER_CST
)
13360 error ("TYPE_ARRAY_MAX_SIZE not INTEGER_CST");
13361 debug_tree (TYPE_ARRAY_MAX_SIZE (t
));
13362 error_found
= true;
13365 else if (TYPE_MAXVAL (t
))
13367 error ("TYPE_MAXVAL non-NULL");
13368 debug_tree (TYPE_MAXVAL (t
));
13369 error_found
= true;
13372 /* Check various uses of TYPE_BINFO. */
13373 if (RECORD_OR_UNION_TYPE_P (t
))
13375 if (!TYPE_BINFO (t
))
13377 else if (TREE_CODE (TYPE_BINFO (t
)) != TREE_BINFO
)
13379 error ("TYPE_BINFO is not TREE_BINFO");
13380 debug_tree (TYPE_BINFO (t
));
13381 error_found
= true;
13383 /* FIXME: Java builds invalid empty binfos that do not have
13385 else if (TREE_TYPE (TYPE_BINFO (t
)) != TYPE_MAIN_VARIANT (t
) && 0)
13387 error ("TYPE_BINFO type is not TYPE_MAIN_VARIANT");
13388 debug_tree (TREE_TYPE (TYPE_BINFO (t
)));
13389 error_found
= true;
13392 else if (TYPE_LANG_SLOT_1 (t
) && in_lto_p
)
13394 error ("TYPE_LANG_SLOT_1 (binfo) field is non-NULL");
13395 debug_tree (TYPE_LANG_SLOT_1 (t
));
13396 error_found
= true;
13399 /* Check various uses of TYPE_VALUES_RAW. */
13400 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
13401 for (tree l
= TYPE_VALUES (t
); l
; l
= TREE_CHAIN (l
))
13403 tree value
= TREE_VALUE (l
);
13404 tree name
= TREE_PURPOSE (l
);
13406 /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
13407 CONST_DECL of ENUMERAL TYPE. */
13408 if (TREE_CODE (value
) != INTEGER_CST
&& TREE_CODE (value
) != CONST_DECL
)
13410 error ("Enum value is not CONST_DECL or INTEGER_CST");
13411 debug_tree (value
);
13413 error_found
= true;
13415 if (TREE_CODE (TREE_TYPE (value
)) != INTEGER_TYPE
13416 && !useless_type_conversion_p (const_cast <tree
> (t
), TREE_TYPE (value
)))
13418 error ("Enum value type is not INTEGER_TYPE nor convertible to the enum");
13419 debug_tree (value
);
13421 error_found
= true;
13423 if (TREE_CODE (name
) != IDENTIFIER_NODE
)
13425 error ("Enum value name is not IDENTIFIER_NODE");
13426 debug_tree (value
);
13428 error_found
= true;
13431 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13433 if (TYPE_DOMAIN (t
) && TREE_CODE (TYPE_DOMAIN (t
)) != INTEGER_TYPE
)
13435 error ("Array TYPE_DOMAIN is not integer type");
13436 debug_tree (TYPE_DOMAIN (t
));
13437 error_found
= true;
13440 else if (RECORD_OR_UNION_TYPE_P (t
))
13441 for (tree fld
= TYPE_FIELDS (t
); fld
; fld
= TREE_CHAIN (fld
))
13443 /* TODO: verify properties of decls. */
13444 if (TREE_CODE (fld
) == FIELD_DECL
)
13446 else if (TREE_CODE (fld
) == TYPE_DECL
)
13448 else if (TREE_CODE (fld
) == CONST_DECL
)
13450 else if (TREE_CODE (fld
) == VAR_DECL
)
13452 else if (TREE_CODE (fld
) == TEMPLATE_DECL
)
13454 else if (TREE_CODE (fld
) == USING_DECL
)
13458 error ("Wrong tree in TYPE_FIELDS list");
13460 error_found
= true;
13463 else if (TREE_CODE (t
) == INTEGER_TYPE
13464 || TREE_CODE (t
) == BOOLEAN_TYPE
13465 || TREE_CODE (t
) == OFFSET_TYPE
13466 || TREE_CODE (t
) == REFERENCE_TYPE
13467 || TREE_CODE (t
) == NULLPTR_TYPE
13468 || TREE_CODE (t
) == POINTER_TYPE
)
13470 if (TYPE_CACHED_VALUES_P (t
) != (TYPE_CACHED_VALUES (t
) != NULL
))
13472 error ("TYPE_CACHED_VALUES_P is %i while TYPE_CACHED_VALUES is %p",
13473 TYPE_CACHED_VALUES_P (t
), (void *)TYPE_CACHED_VALUES (t
));
13474 error_found
= true;
13476 else if (TYPE_CACHED_VALUES_P (t
) && TREE_CODE (TYPE_CACHED_VALUES (t
)) != TREE_VEC
)
13478 error ("TYPE_CACHED_VALUES is not TREE_VEC");
13479 debug_tree (TYPE_CACHED_VALUES (t
));
13480 error_found
= true;
13482 /* Verify just enough of cache to ensure that no one copied it to new type.
13483 All copying should go by copy_node that should clear it. */
13484 else if (TYPE_CACHED_VALUES_P (t
))
13487 for (i
= 0; i
< TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t
)); i
++)
13488 if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)
13489 && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)) != t
)
13491 error ("wrong TYPE_CACHED_VALUES entry");
13492 debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
));
13493 error_found
= true;
13498 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13499 for (tree l
= TYPE_ARG_TYPES (t
); l
; l
= TREE_CHAIN (l
))
13501 /* C++ FE uses TREE_PURPOSE to store initial values. */
13502 if (TREE_PURPOSE (l
) && in_lto_p
)
13504 error ("TREE_PURPOSE is non-NULL in TYPE_ARG_TYPES list");
13506 error_found
= true;
13508 if (!TYPE_P (TREE_VALUE (l
)))
13510 error ("Wrong entry in TYPE_ARG_TYPES list");
13512 error_found
= true;
13515 else if (!is_lang_specific (t
) && TYPE_VALUES_RAW (t
))
13517 error ("TYPE_VALUES_RAW field is non-NULL");
13518 debug_tree (TYPE_VALUES_RAW (t
));
13519 error_found
= true;
13521 if (TREE_CODE (t
) != INTEGER_TYPE
13522 && TREE_CODE (t
) != BOOLEAN_TYPE
13523 && TREE_CODE (t
) != OFFSET_TYPE
13524 && TREE_CODE (t
) != REFERENCE_TYPE
13525 && TREE_CODE (t
) != NULLPTR_TYPE
13526 && TREE_CODE (t
) != POINTER_TYPE
13527 && TYPE_CACHED_VALUES_P (t
))
13529 error ("TYPE_CACHED_VALUES_P is set while it should not");
13530 error_found
= true;
13532 if (TYPE_STRING_FLAG (t
)
13533 && TREE_CODE (t
) != ARRAY_TYPE
&& TREE_CODE (t
) != INTEGER_TYPE
)
13535 error ("TYPE_STRING_FLAG is set on wrong type code");
13536 error_found
= true;
13538 else if (TYPE_STRING_FLAG (t
))
13541 if (TREE_CODE (b
) == ARRAY_TYPE
)
13543 /* Java builds arrays with TYPE_STRING_FLAG of promoted_char_type
13545 if (TREE_CODE (b
) != INTEGER_TYPE
)
13547 error ("TYPE_STRING_FLAG is set on type that does not look like "
13548 "char nor array of chars");
13549 error_found
= true;
13553 /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
13554 TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
13556 if (TREE_CODE (t
) == METHOD_TYPE
13557 && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t
)) != TYPE_METHOD_BASETYPE (t
))
13559 error ("TYPE_METHOD_BASETYPE is not main variant");
13560 error_found
= true;
13565 debug_tree (const_cast <tree
> (t
));
13566 internal_error ("verify_type failed");
13570 #include "gt-tree.h"