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"
37 #include "tree-pass.h"
40 #include "diagnostic.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
47 #include "toplev.h" /* get_random_seed */
49 #include "common/common-target.h"
50 #include "langhooks.h"
51 #include "tree-inline.h"
52 #include "tree-iterator.h"
53 #include "internal-fn.h"
54 #include "gimple-iterator.h"
58 #include "langhooks-def.h"
59 #include "tree-diagnostic.h"
62 #include "print-tree.h"
63 #include "ipa-utils.h"
65 /* Tree code classes. */
67 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
68 #define END_OF_BASE_TREE_CODES tcc_exceptional,
70 const enum tree_code_class tree_code_type
[] = {
71 #include "all-tree.def"
75 #undef END_OF_BASE_TREE_CODES
77 /* Table indexed by tree code giving number of expression
78 operands beyond the fixed part of the node structure.
79 Not used for types or decls. */
81 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
82 #define END_OF_BASE_TREE_CODES 0,
84 const unsigned char tree_code_length
[] = {
85 #include "all-tree.def"
89 #undef END_OF_BASE_TREE_CODES
91 /* Names of tree components.
92 Used for printing out the tree and error messages. */
93 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
94 #define END_OF_BASE_TREE_CODES "@dummy",
96 static const char *const tree_code_name
[] = {
97 #include "all-tree.def"
101 #undef END_OF_BASE_TREE_CODES
103 /* Each tree code class has an associated string representation.
104 These must correspond to the tree_code_class entries. */
106 const char *const tree_code_class_strings
[] =
121 /* obstack.[ch] explicitly declined to prototype this. */
122 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
124 /* Statistics-gathering stuff. */
126 static int tree_code_counts
[MAX_TREE_CODES
];
127 int tree_node_counts
[(int) all_kinds
];
128 int tree_node_sizes
[(int) all_kinds
];
130 /* Keep in sync with tree.h:enum tree_node_kind. */
131 static const char * const tree_node_kind_names
[] = {
150 /* Unique id for next decl created. */
151 static GTY(()) int next_decl_uid
;
152 /* Unique id for next type created. */
153 static GTY(()) int next_type_uid
= 1;
154 /* Unique id for next debug decl created. Use negative numbers,
155 to catch erroneous uses. */
156 static GTY(()) int next_debug_decl_uid
;
158 /* Since we cannot rehash a type after it is in the table, we have to
159 keep the hash code. */
161 struct GTY((for_user
)) type_hash
{
166 /* Initial size of the hash table (rounded to next prime). */
167 #define TYPE_HASH_INITIAL_SIZE 1000
169 struct type_cache_hasher
: ggc_cache_ptr_hash
<type_hash
>
171 static hashval_t
hash (type_hash
*t
) { return t
->hash
; }
172 static bool equal (type_hash
*a
, type_hash
*b
);
175 keep_cache_entry (type_hash
*&t
)
177 return ggc_marked_p (t
->type
);
181 /* Now here is the hash table. When recording a type, it is added to
182 the slot whose index is the hash code. Note that the hash table is
183 used for several kinds of types (function types, array types and
184 array index range types, for now). While all these live in the
185 same table, they are completely independent, and the hash code is
186 computed differently for each of these. */
188 static GTY ((cache
)) hash_table
<type_cache_hasher
> *type_hash_table
;
190 /* Hash table and temporary node for larger integer const values. */
191 static GTY (()) tree int_cst_node
;
193 struct int_cst_hasher
: ggc_cache_ptr_hash
<tree_node
>
195 static hashval_t
hash (tree t
);
196 static bool equal (tree x
, tree y
);
199 static GTY ((cache
)) hash_table
<int_cst_hasher
> *int_cst_hash_table
;
201 /* Hash table for optimization flags and target option flags. Use the same
202 hash table for both sets of options. Nodes for building the current
203 optimization and target option nodes. The assumption is most of the time
204 the options created will already be in the hash table, so we avoid
205 allocating and freeing up a node repeatably. */
206 static GTY (()) tree cl_optimization_node
;
207 static GTY (()) tree cl_target_option_node
;
209 struct cl_option_hasher
: ggc_cache_ptr_hash
<tree_node
>
211 static hashval_t
hash (tree t
);
212 static bool equal (tree x
, tree y
);
215 static GTY ((cache
)) hash_table
<cl_option_hasher
> *cl_option_hash_table
;
217 /* General tree->tree mapping structure for use in hash tables. */
221 hash_table
<tree_decl_map_cache_hasher
> *debug_expr_for_decl
;
224 hash_table
<tree_decl_map_cache_hasher
> *value_expr_for_decl
;
226 struct tree_vec_map_cache_hasher
: ggc_cache_ptr_hash
<tree_vec_map
>
228 static hashval_t
hash (tree_vec_map
*m
) { return DECL_UID (m
->base
.from
); }
231 equal (tree_vec_map
*a
, tree_vec_map
*b
)
233 return a
->base
.from
== b
->base
.from
;
237 keep_cache_entry (tree_vec_map
*&m
)
239 return ggc_marked_p (m
->base
.from
);
244 hash_table
<tree_vec_map_cache_hasher
> *debug_args_for_decl
;
246 static void set_type_quals (tree
, int);
247 static void print_type_hash_statistics (void);
248 static void print_debug_expr_statistics (void);
249 static void print_value_expr_statistics (void);
250 static void type_hash_list (const_tree
, inchash::hash
&);
251 static void attribute_hash_list (const_tree
, inchash::hash
&);
253 tree global_trees
[TI_MAX
];
254 tree integer_types
[itk_none
];
256 bool int_n_enabled_p
[NUM_INT_N_ENTS
];
257 struct int_n_trees_t int_n_trees
[NUM_INT_N_ENTS
];
259 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
261 /* Number of operands for each OpenMP clause. */
262 unsigned const char omp_clause_num_ops
[] =
264 0, /* OMP_CLAUSE_ERROR */
265 1, /* OMP_CLAUSE_PRIVATE */
266 1, /* OMP_CLAUSE_SHARED */
267 1, /* OMP_CLAUSE_FIRSTPRIVATE */
268 2, /* OMP_CLAUSE_LASTPRIVATE */
269 5, /* OMP_CLAUSE_REDUCTION */
270 1, /* OMP_CLAUSE_COPYIN */
271 1, /* OMP_CLAUSE_COPYPRIVATE */
272 3, /* OMP_CLAUSE_LINEAR */
273 2, /* OMP_CLAUSE_ALIGNED */
274 1, /* OMP_CLAUSE_DEPEND */
275 1, /* OMP_CLAUSE_UNIFORM */
276 1, /* OMP_CLAUSE_TO_DECLARE */
277 1, /* OMP_CLAUSE_LINK */
278 2, /* OMP_CLAUSE_FROM */
279 2, /* OMP_CLAUSE_TO */
280 2, /* OMP_CLAUSE_MAP */
281 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
282 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
283 2, /* OMP_CLAUSE__CACHE_ */
284 1, /* OMP_CLAUSE_DEVICE_RESIDENT */
285 1, /* OMP_CLAUSE_USE_DEVICE */
286 2, /* OMP_CLAUSE_GANG */
287 1, /* OMP_CLAUSE_ASYNC */
288 1, /* OMP_CLAUSE_WAIT */
289 0, /* OMP_CLAUSE_AUTO */
290 0, /* OMP_CLAUSE_SEQ */
291 1, /* OMP_CLAUSE__LOOPTEMP_ */
292 1, /* OMP_CLAUSE_IF */
293 1, /* OMP_CLAUSE_NUM_THREADS */
294 1, /* OMP_CLAUSE_SCHEDULE */
295 0, /* OMP_CLAUSE_NOWAIT */
296 1, /* OMP_CLAUSE_ORDERED */
297 0, /* OMP_CLAUSE_DEFAULT */
298 3, /* OMP_CLAUSE_COLLAPSE */
299 0, /* OMP_CLAUSE_UNTIED */
300 1, /* OMP_CLAUSE_FINAL */
301 0, /* OMP_CLAUSE_MERGEABLE */
302 1, /* OMP_CLAUSE_DEVICE */
303 1, /* OMP_CLAUSE_DIST_SCHEDULE */
304 0, /* OMP_CLAUSE_INBRANCH */
305 0, /* OMP_CLAUSE_NOTINBRANCH */
306 1, /* OMP_CLAUSE_NUM_TEAMS */
307 1, /* OMP_CLAUSE_THREAD_LIMIT */
308 0, /* OMP_CLAUSE_PROC_BIND */
309 1, /* OMP_CLAUSE_SAFELEN */
310 1, /* OMP_CLAUSE_SIMDLEN */
311 0, /* OMP_CLAUSE_FOR */
312 0, /* OMP_CLAUSE_PARALLEL */
313 0, /* OMP_CLAUSE_SECTIONS */
314 0, /* OMP_CLAUSE_TASKGROUP */
315 1, /* OMP_CLAUSE_PRIORITY */
316 1, /* OMP_CLAUSE_GRAINSIZE */
317 1, /* OMP_CLAUSE_NUM_TASKS */
318 0, /* OMP_CLAUSE_NOGROUP */
319 0, /* OMP_CLAUSE_THREADS */
320 0, /* OMP_CLAUSE_SIMD */
321 1, /* OMP_CLAUSE_HINT */
322 0, /* OMP_CLAUSE_DEFALTMAP */
323 1, /* OMP_CLAUSE__SIMDUID_ */
324 1, /* OMP_CLAUSE__CILK_FOR_COUNT_ */
325 0, /* OMP_CLAUSE_INDEPENDENT */
326 1, /* OMP_CLAUSE_WORKER */
327 1, /* OMP_CLAUSE_VECTOR */
328 1, /* OMP_CLAUSE_NUM_GANGS */
329 1, /* OMP_CLAUSE_NUM_WORKERS */
330 1, /* OMP_CLAUSE_VECTOR_LENGTH */
331 1, /* OMP_CLAUSE_TILE */
334 const char * const omp_clause_code_name
[] =
407 /* Return the tree node structure used by tree code CODE. */
409 static inline enum tree_node_structure_enum
410 tree_node_structure_for_code (enum tree_code code
)
412 switch (TREE_CODE_CLASS (code
))
414 case tcc_declaration
:
419 return TS_FIELD_DECL
;
425 return TS_LABEL_DECL
;
427 return TS_RESULT_DECL
;
428 case DEBUG_EXPR_DECL
:
431 return TS_CONST_DECL
;
435 return TS_FUNCTION_DECL
;
436 case TRANSLATION_UNIT_DECL
:
437 return TS_TRANSLATION_UNIT_DECL
;
439 return TS_DECL_NON_COMMON
;
443 return TS_TYPE_NON_COMMON
;
452 default: /* tcc_constant and tcc_exceptional */
457 /* tcc_constant cases. */
458 case VOID_CST
: return TS_TYPED
;
459 case INTEGER_CST
: return TS_INT_CST
;
460 case REAL_CST
: return TS_REAL_CST
;
461 case FIXED_CST
: return TS_FIXED_CST
;
462 case COMPLEX_CST
: return TS_COMPLEX
;
463 case VECTOR_CST
: return TS_VECTOR
;
464 case STRING_CST
: return TS_STRING
;
465 /* tcc_exceptional cases. */
466 case ERROR_MARK
: return TS_COMMON
;
467 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
468 case TREE_LIST
: return TS_LIST
;
469 case TREE_VEC
: return TS_VEC
;
470 case SSA_NAME
: return TS_SSA_NAME
;
471 case PLACEHOLDER_EXPR
: return TS_COMMON
;
472 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
473 case BLOCK
: return TS_BLOCK
;
474 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
475 case TREE_BINFO
: return TS_BINFO
;
476 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
477 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
478 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
486 /* Initialize tree_contains_struct to describe the hierarchy of tree
490 initialize_tree_contains_struct (void)
494 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
497 enum tree_node_structure_enum ts_code
;
499 code
= (enum tree_code
) i
;
500 ts_code
= tree_node_structure_for_code (code
);
502 /* Mark the TS structure itself. */
503 tree_contains_struct
[code
][ts_code
] = 1;
505 /* Mark all the structures that TS is derived from. */
523 case TS_STATEMENT_LIST
:
524 MARK_TS_TYPED (code
);
528 case TS_DECL_MINIMAL
:
534 case TS_OPTIMIZATION
:
535 case TS_TARGET_OPTION
:
536 MARK_TS_COMMON (code
);
539 case TS_TYPE_WITH_LANG_SPECIFIC
:
540 MARK_TS_TYPE_COMMON (code
);
543 case TS_TYPE_NON_COMMON
:
544 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
548 MARK_TS_DECL_MINIMAL (code
);
553 MARK_TS_DECL_COMMON (code
);
556 case TS_DECL_NON_COMMON
:
557 MARK_TS_DECL_WITH_VIS (code
);
560 case TS_DECL_WITH_VIS
:
564 MARK_TS_DECL_WRTL (code
);
568 MARK_TS_DECL_COMMON (code
);
572 MARK_TS_DECL_WITH_VIS (code
);
576 case TS_FUNCTION_DECL
:
577 MARK_TS_DECL_NON_COMMON (code
);
580 case TS_TRANSLATION_UNIT_DECL
:
581 MARK_TS_DECL_COMMON (code
);
589 /* Basic consistency checks for attributes used in fold. */
590 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
591 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
592 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
593 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
594 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
595 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
596 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
597 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
598 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
599 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
600 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
601 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
602 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
603 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
604 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
605 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
606 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
607 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
608 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
609 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
610 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
611 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
612 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
613 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
614 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
615 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
616 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
617 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
618 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
619 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
620 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
621 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
622 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
623 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
624 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
625 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
626 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
627 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
628 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_MINIMAL
]);
629 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_COMMON
]);
638 /* Initialize the hash table of types. */
640 = hash_table
<type_cache_hasher
>::create_ggc (TYPE_HASH_INITIAL_SIZE
);
643 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
646 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
648 int_cst_hash_table
= hash_table
<int_cst_hasher
>::create_ggc (1024);
650 int_cst_node
= make_int_cst (1, 1);
652 cl_option_hash_table
= hash_table
<cl_option_hasher
>::create_ggc (64);
654 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
655 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
657 /* Initialize the tree_contains_struct array. */
658 initialize_tree_contains_struct ();
659 lang_hooks
.init_ts ();
663 /* The name of the object as the assembler will see it (but before any
664 translations made by ASM_OUTPUT_LABELREF). Often this is the same
665 as DECL_NAME. It is an IDENTIFIER_NODE. */
667 decl_assembler_name (tree decl
)
669 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
670 lang_hooks
.set_decl_assembler_name (decl
);
671 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
674 /* When the target supports COMDAT groups, this indicates which group the
675 DECL is associated with. This can be either an IDENTIFIER_NODE or a
676 decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
678 decl_comdat_group (const_tree node
)
680 struct symtab_node
*snode
= symtab_node::get (node
);
683 return snode
->get_comdat_group ();
686 /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
688 decl_comdat_group_id (const_tree node
)
690 struct symtab_node
*snode
= symtab_node::get (node
);
693 return snode
->get_comdat_group_id ();
696 /* When the target supports named section, return its name as IDENTIFIER_NODE
697 or NULL if it is in no section. */
699 decl_section_name (const_tree node
)
701 struct symtab_node
*snode
= symtab_node::get (node
);
704 return snode
->get_section ();
707 /* Set section name of NODE to VALUE (that is expected to be
710 set_decl_section_name (tree node
, const char *value
)
712 struct symtab_node
*snode
;
716 snode
= symtab_node::get (node
);
720 else if (TREE_CODE (node
) == VAR_DECL
)
721 snode
= varpool_node::get_create (node
);
723 snode
= cgraph_node::get_create (node
);
724 snode
->set_section (value
);
727 /* Return TLS model of a variable NODE. */
729 decl_tls_model (const_tree node
)
731 struct varpool_node
*snode
= varpool_node::get (node
);
733 return TLS_MODEL_NONE
;
734 return snode
->tls_model
;
737 /* Set TLS model of variable NODE to MODEL. */
739 set_decl_tls_model (tree node
, enum tls_model model
)
741 struct varpool_node
*vnode
;
743 if (model
== TLS_MODEL_NONE
)
745 vnode
= varpool_node::get (node
);
750 vnode
= varpool_node::get_create (node
);
751 vnode
->tls_model
= model
;
754 /* Compute the number of bytes occupied by a tree with code CODE.
755 This function cannot be used for nodes that have variable sizes,
756 including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
758 tree_code_size (enum tree_code code
)
760 switch (TREE_CODE_CLASS (code
))
762 case tcc_declaration
: /* A decl node */
767 return sizeof (struct tree_field_decl
);
769 return sizeof (struct tree_parm_decl
);
771 return sizeof (struct tree_var_decl
);
773 return sizeof (struct tree_label_decl
);
775 return sizeof (struct tree_result_decl
);
777 return sizeof (struct tree_const_decl
);
779 return sizeof (struct tree_type_decl
);
781 return sizeof (struct tree_function_decl
);
782 case DEBUG_EXPR_DECL
:
783 return sizeof (struct tree_decl_with_rtl
);
784 case TRANSLATION_UNIT_DECL
:
785 return sizeof (struct tree_translation_unit_decl
);
789 return sizeof (struct tree_decl_non_common
);
791 return lang_hooks
.tree_size (code
);
795 case tcc_type
: /* a type node */
796 return sizeof (struct tree_type_non_common
);
798 case tcc_reference
: /* a reference */
799 case tcc_expression
: /* an expression */
800 case tcc_statement
: /* an expression with side effects */
801 case tcc_comparison
: /* a comparison expression */
802 case tcc_unary
: /* a unary arithmetic expression */
803 case tcc_binary
: /* a binary arithmetic expression */
804 return (sizeof (struct tree_exp
)
805 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
807 case tcc_constant
: /* a constant */
810 case VOID_CST
: return sizeof (struct tree_typed
);
811 case INTEGER_CST
: gcc_unreachable ();
812 case REAL_CST
: return sizeof (struct tree_real_cst
);
813 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
814 case COMPLEX_CST
: return sizeof (struct tree_complex
);
815 case VECTOR_CST
: return sizeof (struct tree_vector
);
816 case STRING_CST
: gcc_unreachable ();
818 return lang_hooks
.tree_size (code
);
821 case tcc_exceptional
: /* something random, like an identifier. */
824 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
825 case TREE_LIST
: return sizeof (struct tree_list
);
828 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
831 case OMP_CLAUSE
: gcc_unreachable ();
833 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
835 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
836 case BLOCK
: return sizeof (struct tree_block
);
837 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
838 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
839 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
842 return lang_hooks
.tree_size (code
);
850 /* Compute the number of bytes occupied by NODE. This routine only
851 looks at TREE_CODE, except for those nodes that have variable sizes. */
853 tree_size (const_tree node
)
855 const enum tree_code code
= TREE_CODE (node
);
859 return (sizeof (struct tree_int_cst
)
860 + (TREE_INT_CST_EXT_NUNITS (node
) - 1) * sizeof (HOST_WIDE_INT
));
863 return (offsetof (struct tree_binfo
, base_binfos
)
865 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
868 return (sizeof (struct tree_vec
)
869 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
872 return (sizeof (struct tree_vector
)
873 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node
)) - 1) * sizeof (tree
));
876 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
879 return (sizeof (struct tree_omp_clause
)
880 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
884 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
885 return (sizeof (struct tree_exp
)
886 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
888 return tree_code_size (code
);
892 /* Record interesting allocation statistics for a tree node with CODE
896 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
897 size_t length ATTRIBUTE_UNUSED
)
899 enum tree_code_class type
= TREE_CODE_CLASS (code
);
902 if (!GATHER_STATISTICS
)
907 case tcc_declaration
: /* A decl node */
911 case tcc_type
: /* a type node */
915 case tcc_statement
: /* an expression with side effects */
919 case tcc_reference
: /* a reference */
923 case tcc_expression
: /* an expression */
924 case tcc_comparison
: /* a comparison expression */
925 case tcc_unary
: /* a unary arithmetic expression */
926 case tcc_binary
: /* a binary arithmetic expression */
930 case tcc_constant
: /* a constant */
934 case tcc_exceptional
: /* something random, like an identifier. */
937 case IDENTIFIER_NODE
:
950 kind
= ssa_name_kind
;
962 kind
= omp_clause_kind
;
979 tree_code_counts
[(int) code
]++;
980 tree_node_counts
[(int) kind
]++;
981 tree_node_sizes
[(int) kind
] += length
;
984 /* Allocate and return a new UID from the DECL_UID namespace. */
987 allocate_decl_uid (void)
989 return next_decl_uid
++;
992 /* Return a newly allocated node of code CODE. For decl and type
993 nodes, some other fields are initialized. The rest of the node is
994 initialized to zero. This function cannot be used for TREE_VEC,
995 INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
998 Achoo! I got a code in the node. */
1001 make_node_stat (enum tree_code code MEM_STAT_DECL
)
1004 enum tree_code_class type
= TREE_CODE_CLASS (code
);
1005 size_t length
= tree_code_size (code
);
1007 record_node_allocation_statistics (code
, length
);
1009 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1010 TREE_SET_CODE (t
, code
);
1015 TREE_SIDE_EFFECTS (t
) = 1;
1018 case tcc_declaration
:
1019 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1021 if (code
== FUNCTION_DECL
)
1023 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
1024 DECL_MODE (t
) = FUNCTION_MODE
;
1029 DECL_SOURCE_LOCATION (t
) = input_location
;
1030 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
1031 DECL_UID (t
) = --next_debug_decl_uid
;
1034 DECL_UID (t
) = allocate_decl_uid ();
1035 SET_DECL_PT_UID (t
, -1);
1037 if (TREE_CODE (t
) == LABEL_DECL
)
1038 LABEL_DECL_UID (t
) = -1;
1043 TYPE_UID (t
) = next_type_uid
++;
1044 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
1045 TYPE_USER_ALIGN (t
) = 0;
1046 TYPE_MAIN_VARIANT (t
) = t
;
1047 TYPE_CANONICAL (t
) = t
;
1049 /* Default to no attributes for type, but let target change that. */
1050 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1051 targetm
.set_default_type_attributes (t
);
1053 /* We have not yet computed the alias set for this type. */
1054 TYPE_ALIAS_SET (t
) = -1;
1058 TREE_CONSTANT (t
) = 1;
1061 case tcc_expression
:
1067 case PREDECREMENT_EXPR
:
1068 case PREINCREMENT_EXPR
:
1069 case POSTDECREMENT_EXPR
:
1070 case POSTINCREMENT_EXPR
:
1071 /* All of these have side-effects, no matter what their
1073 TREE_SIDE_EFFECTS (t
) = 1;
1081 case tcc_exceptional
:
1084 case TARGET_OPTION_NODE
:
1085 TREE_TARGET_OPTION(t
)
1086 = ggc_cleared_alloc
<struct cl_target_option
> ();
1089 case OPTIMIZATION_NODE
:
1090 TREE_OPTIMIZATION (t
)
1091 = ggc_cleared_alloc
<struct cl_optimization
> ();
1100 /* Other classes need no special treatment. */
1107 /* Return a new node with the same contents as NODE except that its
1108 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1111 copy_node_stat (tree node MEM_STAT_DECL
)
1114 enum tree_code code
= TREE_CODE (node
);
1117 gcc_assert (code
!= STATEMENT_LIST
);
1119 length
= tree_size (node
);
1120 record_node_allocation_statistics (code
, length
);
1121 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1122 memcpy (t
, node
, length
);
1124 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1126 TREE_ASM_WRITTEN (t
) = 0;
1127 TREE_VISITED (t
) = 0;
1129 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
1131 if (code
== DEBUG_EXPR_DECL
)
1132 DECL_UID (t
) = --next_debug_decl_uid
;
1135 DECL_UID (t
) = allocate_decl_uid ();
1136 if (DECL_PT_UID_SET_P (node
))
1137 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
1139 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
1140 && DECL_HAS_VALUE_EXPR_P (node
))
1142 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
1143 DECL_HAS_VALUE_EXPR_P (t
) = 1;
1145 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
1146 if (TREE_CODE (node
) == VAR_DECL
)
1148 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
1149 t
->decl_with_vis
.symtab_node
= NULL
;
1151 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
1153 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
1154 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
1156 if (TREE_CODE (node
) == FUNCTION_DECL
)
1158 DECL_STRUCT_FUNCTION (t
) = NULL
;
1159 t
->decl_with_vis
.symtab_node
= NULL
;
1162 else if (TREE_CODE_CLASS (code
) == tcc_type
)
1164 TYPE_UID (t
) = next_type_uid
++;
1165 /* The following is so that the debug code for
1166 the copy is different from the original type.
1167 The two statements usually duplicate each other
1168 (because they clear fields of the same union),
1169 but the optimizer should catch that. */
1170 TYPE_SYMTAB_POINTER (t
) = 0;
1171 TYPE_SYMTAB_ADDRESS (t
) = 0;
1173 /* Do not copy the values cache. */
1174 if (TYPE_CACHED_VALUES_P (t
))
1176 TYPE_CACHED_VALUES_P (t
) = 0;
1177 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1180 else if (code
== TARGET_OPTION_NODE
)
1182 TREE_TARGET_OPTION (t
) = ggc_alloc
<struct cl_target_option
>();
1183 memcpy (TREE_TARGET_OPTION (t
), TREE_TARGET_OPTION (node
),
1184 sizeof (struct cl_target_option
));
1186 else if (code
== OPTIMIZATION_NODE
)
1188 TREE_OPTIMIZATION (t
) = ggc_alloc
<struct cl_optimization
>();
1189 memcpy (TREE_OPTIMIZATION (t
), TREE_OPTIMIZATION (node
),
1190 sizeof (struct cl_optimization
));
1196 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1197 For example, this can copy a list made of TREE_LIST nodes. */
1200 copy_list (tree list
)
1208 head
= prev
= copy_node (list
);
1209 next
= TREE_CHAIN (list
);
1212 TREE_CHAIN (prev
) = copy_node (next
);
1213 prev
= TREE_CHAIN (prev
);
1214 next
= TREE_CHAIN (next
);
1220 /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1221 INTEGER_CST with value CST and type TYPE. */
1224 get_int_cst_ext_nunits (tree type
, const wide_int
&cst
)
1226 gcc_checking_assert (cst
.get_precision () == TYPE_PRECISION (type
));
1227 /* We need an extra zero HWI if CST is an unsigned integer with its
1228 upper bit set, and if CST occupies a whole number of HWIs. */
1229 if (TYPE_UNSIGNED (type
)
1231 && (cst
.get_precision () % HOST_BITS_PER_WIDE_INT
) == 0)
1232 return cst
.get_precision () / HOST_BITS_PER_WIDE_INT
+ 1;
1233 return cst
.get_len ();
1236 /* Return a new INTEGER_CST with value CST and type TYPE. */
1239 build_new_int_cst (tree type
, const wide_int
&cst
)
1241 unsigned int len
= cst
.get_len ();
1242 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1243 tree nt
= make_int_cst (len
, ext_len
);
1248 TREE_INT_CST_ELT (nt
, ext_len
) = 0;
1249 for (unsigned int i
= len
; i
< ext_len
; ++i
)
1250 TREE_INT_CST_ELT (nt
, i
) = -1;
1252 else if (TYPE_UNSIGNED (type
)
1253 && cst
.get_precision () < len
* HOST_BITS_PER_WIDE_INT
)
1256 TREE_INT_CST_ELT (nt
, len
)
1257 = zext_hwi (cst
.elt (len
),
1258 cst
.get_precision () % HOST_BITS_PER_WIDE_INT
);
1261 for (unsigned int i
= 0; i
< len
; i
++)
1262 TREE_INT_CST_ELT (nt
, i
) = cst
.elt (i
);
1263 TREE_TYPE (nt
) = type
;
1267 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1270 build_int_cst (tree type
, HOST_WIDE_INT low
)
1272 /* Support legacy code. */
1274 type
= integer_type_node
;
1276 return wide_int_to_tree (type
, wi::shwi (low
, TYPE_PRECISION (type
)));
1280 build_int_cstu (tree type
, unsigned HOST_WIDE_INT cst
)
1282 return wide_int_to_tree (type
, wi::uhwi (cst
, TYPE_PRECISION (type
)));
1285 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1288 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1291 return wide_int_to_tree (type
, wi::shwi (low
, TYPE_PRECISION (type
)));
1294 /* Constructs tree in type TYPE from with value given by CST. Signedness
1295 of CST is assumed to be the same as the signedness of TYPE. */
1298 double_int_to_tree (tree type
, double_int cst
)
1300 return wide_int_to_tree (type
, widest_int::from (cst
, TYPE_SIGN (type
)));
1303 /* We force the wide_int CST to the range of the type TYPE by sign or
1304 zero extending it. OVERFLOWABLE indicates if we are interested in
1305 overflow of the value, when >0 we are only interested in signed
1306 overflow, for <0 we are interested in any overflow. OVERFLOWED
1307 indicates whether overflow has already occurred. CONST_OVERFLOWED
1308 indicates whether constant overflow has already occurred. We force
1309 T's value to be within range of T's type (by setting to 0 or 1 all
1310 the bits outside the type's range). We set TREE_OVERFLOWED if,
1311 OVERFLOWED is nonzero,
1312 or OVERFLOWABLE is >0 and signed overflow occurs
1313 or OVERFLOWABLE is <0 and any overflow occurs
1314 We return a new tree node for the extended wide_int. The node
1315 is shared if no overflow flags are set. */
1319 force_fit_type (tree type
, const wide_int_ref
&cst
,
1320 int overflowable
, bool overflowed
)
1322 signop sign
= TYPE_SIGN (type
);
1324 /* If we need to set overflow flags, return a new unshared node. */
1325 if (overflowed
|| !wi::fits_to_tree_p (cst
, type
))
1329 || (overflowable
> 0 && sign
== SIGNED
))
1331 wide_int tmp
= wide_int::from (cst
, TYPE_PRECISION (type
), sign
);
1332 tree t
= build_new_int_cst (type
, tmp
);
1333 TREE_OVERFLOW (t
) = 1;
1338 /* Else build a shared node. */
1339 return wide_int_to_tree (type
, cst
);
1342 /* These are the hash table functions for the hash table of INTEGER_CST
1343 nodes of a sizetype. */
1345 /* Return the hash code X, an INTEGER_CST. */
1348 int_cst_hasher::hash (tree x
)
1350 const_tree
const t
= x
;
1351 hashval_t code
= TYPE_UID (TREE_TYPE (t
));
1354 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
1355 code
= iterative_hash_host_wide_int (TREE_INT_CST_ELT(t
, i
), code
);
1360 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1361 is the same as that given by *Y, which is the same. */
1364 int_cst_hasher::equal (tree x
, tree y
)
1366 const_tree
const xt
= x
;
1367 const_tree
const yt
= y
;
1369 if (TREE_TYPE (xt
) != TREE_TYPE (yt
)
1370 || TREE_INT_CST_NUNITS (xt
) != TREE_INT_CST_NUNITS (yt
)
1371 || TREE_INT_CST_EXT_NUNITS (xt
) != TREE_INT_CST_EXT_NUNITS (yt
))
1374 for (int i
= 0; i
< TREE_INT_CST_NUNITS (xt
); i
++)
1375 if (TREE_INT_CST_ELT (xt
, i
) != TREE_INT_CST_ELT (yt
, i
))
1381 /* Create an INT_CST node of TYPE and value CST.
1382 The returned node is always shared. For small integers we use a
1383 per-type vector cache, for larger ones we use a single hash table.
1384 The value is extended from its precision according to the sign of
1385 the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1386 the upper bits and ensures that hashing and value equality based
1387 upon the underlying HOST_WIDE_INTs works without masking. */
1390 wide_int_to_tree (tree type
, const wide_int_ref
&pcst
)
1397 unsigned int prec
= TYPE_PRECISION (type
);
1398 signop sgn
= TYPE_SIGN (type
);
1400 /* Verify that everything is canonical. */
1401 int l
= pcst
.get_len ();
1404 if (pcst
.elt (l
- 1) == 0)
1405 gcc_checking_assert (pcst
.elt (l
- 2) < 0);
1406 if (pcst
.elt (l
- 1) == (HOST_WIDE_INT
) -1)
1407 gcc_checking_assert (pcst
.elt (l
- 2) >= 0);
1410 wide_int cst
= wide_int::from (pcst
, prec
, sgn
);
1411 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1415 /* We just need to store a single HOST_WIDE_INT. */
1417 if (TYPE_UNSIGNED (type
))
1418 hwi
= cst
.to_uhwi ();
1420 hwi
= cst
.to_shwi ();
1422 switch (TREE_CODE (type
))
1425 gcc_assert (hwi
== 0);
1429 case REFERENCE_TYPE
:
1430 case POINTER_BOUNDS_TYPE
:
1431 /* Cache NULL pointer and zero bounds. */
1440 /* Cache false or true. */
1442 if (IN_RANGE (hwi
, 0, 1))
1448 if (TYPE_SIGN (type
) == UNSIGNED
)
1451 limit
= INTEGER_SHARE_LIMIT
;
1452 if (IN_RANGE (hwi
, 0, INTEGER_SHARE_LIMIT
- 1))
1457 /* Cache [-1, N). */
1458 limit
= INTEGER_SHARE_LIMIT
+ 1;
1459 if (IN_RANGE (hwi
, -1, INTEGER_SHARE_LIMIT
- 1))
1473 /* Look for it in the type's vector of small shared ints. */
1474 if (!TYPE_CACHED_VALUES_P (type
))
1476 TYPE_CACHED_VALUES_P (type
) = 1;
1477 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1480 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1482 /* Make sure no one is clobbering the shared constant. */
1483 gcc_checking_assert (TREE_TYPE (t
) == type
1484 && TREE_INT_CST_NUNITS (t
) == 1
1485 && TREE_INT_CST_OFFSET_NUNITS (t
) == 1
1486 && TREE_INT_CST_EXT_NUNITS (t
) == 1
1487 && TREE_INT_CST_ELT (t
, 0) == hwi
);
1490 /* Create a new shared int. */
1491 t
= build_new_int_cst (type
, cst
);
1492 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1497 /* Use the cache of larger shared ints, using int_cst_node as
1500 TREE_INT_CST_ELT (int_cst_node
, 0) = hwi
;
1501 TREE_TYPE (int_cst_node
) = type
;
1503 tree
*slot
= int_cst_hash_table
->find_slot (int_cst_node
, INSERT
);
1507 /* Insert this one into the hash table. */
1510 /* Make a new node for next time round. */
1511 int_cst_node
= make_int_cst (1, 1);
1517 /* The value either hashes properly or we drop it on the floor
1518 for the gc to take care of. There will not be enough of them
1521 tree nt
= build_new_int_cst (type
, cst
);
1522 tree
*slot
= int_cst_hash_table
->find_slot (nt
, INSERT
);
1526 /* Insert this one into the hash table. */
1536 cache_integer_cst (tree t
)
1538 tree type
= TREE_TYPE (t
);
1541 int prec
= TYPE_PRECISION (type
);
1543 gcc_assert (!TREE_OVERFLOW (t
));
1545 switch (TREE_CODE (type
))
1548 gcc_assert (integer_zerop (t
));
1552 case REFERENCE_TYPE
:
1553 /* Cache NULL pointer. */
1554 if (integer_zerop (t
))
1562 /* Cache false or true. */
1564 if (wi::ltu_p (t
, 2))
1565 ix
= TREE_INT_CST_ELT (t
, 0);
1570 if (TYPE_UNSIGNED (type
))
1573 limit
= INTEGER_SHARE_LIMIT
;
1575 /* This is a little hokie, but if the prec is smaller than
1576 what is necessary to hold INTEGER_SHARE_LIMIT, then the
1577 obvious test will not get the correct answer. */
1578 if (prec
< HOST_BITS_PER_WIDE_INT
)
1580 if (tree_to_uhwi (t
) < (unsigned HOST_WIDE_INT
) INTEGER_SHARE_LIMIT
)
1581 ix
= tree_to_uhwi (t
);
1583 else if (wi::ltu_p (t
, INTEGER_SHARE_LIMIT
))
1584 ix
= tree_to_uhwi (t
);
1589 limit
= INTEGER_SHARE_LIMIT
+ 1;
1591 if (integer_minus_onep (t
))
1593 else if (!wi::neg_p (t
))
1595 if (prec
< HOST_BITS_PER_WIDE_INT
)
1597 if (tree_to_shwi (t
) < INTEGER_SHARE_LIMIT
)
1598 ix
= tree_to_shwi (t
) + 1;
1600 else if (wi::ltu_p (t
, INTEGER_SHARE_LIMIT
))
1601 ix
= tree_to_shwi (t
) + 1;
1615 /* Look for it in the type's vector of small shared ints. */
1616 if (!TYPE_CACHED_VALUES_P (type
))
1618 TYPE_CACHED_VALUES_P (type
) = 1;
1619 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1622 gcc_assert (TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) == NULL_TREE
);
1623 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1627 /* Use the cache of larger shared ints. */
1628 tree
*slot
= int_cst_hash_table
->find_slot (t
, INSERT
);
1629 /* If there is already an entry for the number verify it's the
1632 gcc_assert (wi::eq_p (tree (*slot
), t
));
1634 /* Otherwise insert this one into the hash table. */
1640 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1641 and the rest are zeros. */
1644 build_low_bits_mask (tree type
, unsigned bits
)
1646 gcc_assert (bits
<= TYPE_PRECISION (type
));
1648 return wide_int_to_tree (type
, wi::mask (bits
, false,
1649 TYPE_PRECISION (type
)));
1652 /* Checks that X is integer constant that can be expressed in (unsigned)
1653 HOST_WIDE_INT without loss of precision. */
1656 cst_and_fits_in_hwi (const_tree x
)
1658 if (TREE_CODE (x
) != INTEGER_CST
)
1661 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1664 return TREE_INT_CST_NUNITS (x
) == 1;
1667 /* Build a newly constructed VECTOR_CST node of length LEN. */
1670 make_vector_stat (unsigned len MEM_STAT_DECL
)
1673 unsigned length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vector
);
1675 record_node_allocation_statistics (VECTOR_CST
, length
);
1677 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1679 TREE_SET_CODE (t
, VECTOR_CST
);
1680 TREE_CONSTANT (t
) = 1;
1685 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1686 are in a list pointed to by VALS. */
1689 build_vector_stat (tree type
, tree
*vals MEM_STAT_DECL
)
1693 tree v
= make_vector (TYPE_VECTOR_SUBPARTS (type
));
1694 TREE_TYPE (v
) = type
;
1696 /* Iterate through elements and check for overflow. */
1697 for (cnt
= 0; cnt
< TYPE_VECTOR_SUBPARTS (type
); ++cnt
)
1699 tree value
= vals
[cnt
];
1701 VECTOR_CST_ELT (v
, cnt
) = value
;
1703 /* Don't crash if we get an address constant. */
1704 if (!CONSTANT_CLASS_P (value
))
1707 over
|= TREE_OVERFLOW (value
);
1710 TREE_OVERFLOW (v
) = over
;
1714 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1715 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1718 build_vector_from_ctor (tree type
, vec
<constructor_elt
, va_gc
> *v
)
1720 tree
*vec
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (type
));
1721 unsigned HOST_WIDE_INT idx
, pos
= 0;
1724 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1726 if (TREE_CODE (value
) == VECTOR_CST
)
1727 for (unsigned i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
1728 vec
[pos
++] = VECTOR_CST_ELT (value
, i
);
1732 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1733 vec
[pos
++] = build_zero_cst (TREE_TYPE (type
));
1735 return build_vector (type
, vec
);
1738 /* Build a vector of type VECTYPE where all the elements are SCs. */
1740 build_vector_from_val (tree vectype
, tree sc
)
1742 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1744 if (sc
== error_mark_node
)
1747 /* Verify that the vector type is suitable for SC. Note that there
1748 is some inconsistency in the type-system with respect to restrict
1749 qualifications of pointers. Vector types always have a main-variant
1750 element type and the qualification is applied to the vector-type.
1751 So TREE_TYPE (vector-type) does not return a properly qualified
1752 vector element-type. */
1753 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1754 TREE_TYPE (vectype
)));
1756 if (CONSTANT_CLASS_P (sc
))
1758 tree
*v
= XALLOCAVEC (tree
, nunits
);
1759 for (i
= 0; i
< nunits
; ++i
)
1761 return build_vector (vectype
, v
);
1765 vec
<constructor_elt
, va_gc
> *v
;
1766 vec_alloc (v
, nunits
);
1767 for (i
= 0; i
< nunits
; ++i
)
1768 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1769 return build_constructor (vectype
, v
);
1773 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1774 are in the vec pointed to by VALS. */
1776 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals
)
1778 tree c
= make_node (CONSTRUCTOR
);
1780 constructor_elt
*elt
;
1781 bool constant_p
= true;
1782 bool side_effects_p
= false;
1784 TREE_TYPE (c
) = type
;
1785 CONSTRUCTOR_ELTS (c
) = vals
;
1787 FOR_EACH_VEC_SAFE_ELT (vals
, i
, elt
)
1789 /* Mostly ctors will have elts that don't have side-effects, so
1790 the usual case is to scan all the elements. Hence a single
1791 loop for both const and side effects, rather than one loop
1792 each (with early outs). */
1793 if (!TREE_CONSTANT (elt
->value
))
1795 if (TREE_SIDE_EFFECTS (elt
->value
))
1796 side_effects_p
= true;
1799 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
1800 TREE_CONSTANT (c
) = constant_p
;
1805 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1808 build_constructor_single (tree type
, tree index
, tree value
)
1810 vec
<constructor_elt
, va_gc
> *v
;
1811 constructor_elt elt
= {index
, value
};
1814 v
->quick_push (elt
);
1816 return build_constructor (type
, v
);
1820 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1821 are in a list pointed to by VALS. */
1823 build_constructor_from_list (tree type
, tree vals
)
1826 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1830 vec_alloc (v
, list_length (vals
));
1831 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1832 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1835 return build_constructor (type
, v
);
1838 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1839 of elements, provided as index/value pairs. */
1842 build_constructor_va (tree type
, int nelts
, ...)
1844 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1847 va_start (p
, nelts
);
1848 vec_alloc (v
, nelts
);
1851 tree index
= va_arg (p
, tree
);
1852 tree value
= va_arg (p
, tree
);
1853 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
1856 return build_constructor (type
, v
);
1859 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1862 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1865 FIXED_VALUE_TYPE
*fp
;
1867 v
= make_node (FIXED_CST
);
1868 fp
= ggc_alloc
<fixed_value
> ();
1869 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1871 TREE_TYPE (v
) = type
;
1872 TREE_FIXED_CST_PTR (v
) = fp
;
1876 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1879 build_real (tree type
, REAL_VALUE_TYPE d
)
1882 REAL_VALUE_TYPE
*dp
;
1885 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1886 Consider doing it via real_convert now. */
1888 v
= make_node (REAL_CST
);
1889 dp
= ggc_alloc
<real_value
> ();
1890 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1892 TREE_TYPE (v
) = type
;
1893 TREE_REAL_CST_PTR (v
) = dp
;
1894 TREE_OVERFLOW (v
) = overflow
;
1898 /* Like build_real, but first truncate D to the type. */
1901 build_real_truncate (tree type
, REAL_VALUE_TYPE d
)
1903 return build_real (type
, real_value_truncate (TYPE_MODE (type
), d
));
1906 /* Return a new REAL_CST node whose type is TYPE
1907 and whose value is the integer value of the INTEGER_CST node I. */
1910 real_value_from_int_cst (const_tree type
, const_tree i
)
1914 /* Clear all bits of the real value type so that we can later do
1915 bitwise comparisons to see if two values are the same. */
1916 memset (&d
, 0, sizeof d
);
1918 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
, i
,
1919 TYPE_SIGN (TREE_TYPE (i
)));
1923 /* Given a tree representing an integer constant I, return a tree
1924 representing the same value as a floating-point constant of type TYPE. */
1927 build_real_from_int_cst (tree type
, const_tree i
)
1930 int overflow
= TREE_OVERFLOW (i
);
1932 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1934 TREE_OVERFLOW (v
) |= overflow
;
1938 /* Return a newly constructed STRING_CST node whose value is
1939 the LEN characters at STR.
1940 Note that for a C string literal, LEN should include the trailing NUL.
1941 The TREE_TYPE is not initialized. */
1944 build_string (int len
, const char *str
)
1949 /* Do not waste bytes provided by padding of struct tree_string. */
1950 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1952 record_node_allocation_statistics (STRING_CST
, length
);
1954 s
= (tree
) ggc_internal_alloc (length
);
1956 memset (s
, 0, sizeof (struct tree_typed
));
1957 TREE_SET_CODE (s
, STRING_CST
);
1958 TREE_CONSTANT (s
) = 1;
1959 TREE_STRING_LENGTH (s
) = len
;
1960 memcpy (s
->string
.str
, str
, len
);
1961 s
->string
.str
[len
] = '\0';
1966 /* Return a newly constructed COMPLEX_CST node whose value is
1967 specified by the real and imaginary parts REAL and IMAG.
1968 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1969 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1972 build_complex (tree type
, tree real
, tree imag
)
1974 tree t
= make_node (COMPLEX_CST
);
1976 TREE_REALPART (t
) = real
;
1977 TREE_IMAGPART (t
) = imag
;
1978 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1979 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1983 /* Build a complex (inf +- 0i), such as for the result of cproj.
1984 TYPE is the complex tree type of the result. If NEG is true, the
1985 imaginary zero is negative. */
1988 build_complex_inf (tree type
, bool neg
)
1990 REAL_VALUE_TYPE rinf
, rzero
= dconst0
;
1994 return build_complex (type
, build_real (TREE_TYPE (type
), rinf
),
1995 build_real (TREE_TYPE (type
), rzero
));
1998 /* Return the constant 1 in type TYPE. If TYPE has several elements, each
1999 element is set to 1. In particular, this is 1 + i for complex types. */
2002 build_each_one_cst (tree type
)
2004 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2006 tree scalar
= build_one_cst (TREE_TYPE (type
));
2007 return build_complex (type
, scalar
, scalar
);
2010 return build_one_cst (type
);
2013 /* Return a constant of arithmetic type TYPE which is the
2014 multiplicative identity of the set TYPE. */
2017 build_one_cst (tree type
)
2019 switch (TREE_CODE (type
))
2021 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2022 case POINTER_TYPE
: case REFERENCE_TYPE
:
2024 return build_int_cst (type
, 1);
2027 return build_real (type
, dconst1
);
2029 case FIXED_POINT_TYPE
:
2030 /* We can only generate 1 for accum types. */
2031 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
2032 return build_fixed (type
, FCONST1 (TYPE_MODE (type
)));
2036 tree scalar
= build_one_cst (TREE_TYPE (type
));
2038 return build_vector_from_val (type
, scalar
);
2042 return build_complex (type
,
2043 build_one_cst (TREE_TYPE (type
)),
2044 build_zero_cst (TREE_TYPE (type
)));
2051 /* Return an integer of type TYPE containing all 1's in as much precision as
2052 it contains, or a complex or vector whose subparts are such integers. */
2055 build_all_ones_cst (tree type
)
2057 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2059 tree scalar
= build_all_ones_cst (TREE_TYPE (type
));
2060 return build_complex (type
, scalar
, scalar
);
2063 return build_minus_one_cst (type
);
2066 /* Return a constant of arithmetic type TYPE which is the
2067 opposite of the multiplicative identity of the set TYPE. */
2070 build_minus_one_cst (tree type
)
2072 switch (TREE_CODE (type
))
2074 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2075 case POINTER_TYPE
: case REFERENCE_TYPE
:
2077 return build_int_cst (type
, -1);
2080 return build_real (type
, dconstm1
);
2082 case FIXED_POINT_TYPE
:
2083 /* We can only generate 1 for accum types. */
2084 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
2085 return build_fixed (type
, fixed_from_double_int (double_int_minus_one
,
2090 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
2092 return build_vector_from_val (type
, scalar
);
2096 return build_complex (type
,
2097 build_minus_one_cst (TREE_TYPE (type
)),
2098 build_zero_cst (TREE_TYPE (type
)));
2105 /* Build 0 constant of type TYPE. This is used by constructor folding
2106 and thus the constant should be represented in memory by
2110 build_zero_cst (tree type
)
2112 switch (TREE_CODE (type
))
2114 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2115 case POINTER_TYPE
: case REFERENCE_TYPE
:
2116 case OFFSET_TYPE
: case NULLPTR_TYPE
:
2117 return build_int_cst (type
, 0);
2120 return build_real (type
, dconst0
);
2122 case FIXED_POINT_TYPE
:
2123 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
2127 tree scalar
= build_zero_cst (TREE_TYPE (type
));
2129 return build_vector_from_val (type
, scalar
);
2134 tree zero
= build_zero_cst (TREE_TYPE (type
));
2136 return build_complex (type
, zero
, zero
);
2140 if (!AGGREGATE_TYPE_P (type
))
2141 return fold_convert (type
, integer_zero_node
);
2142 return build_constructor (type
, NULL
);
2147 /* Build a BINFO with LEN language slots. */
2150 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
2153 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
2154 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
2156 record_node_allocation_statistics (TREE_BINFO
, length
);
2158 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
2160 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
2162 TREE_SET_CODE (t
, TREE_BINFO
);
2164 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
2169 /* Create a CASE_LABEL_EXPR tree node and return it. */
2172 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
2174 tree t
= make_node (CASE_LABEL_EXPR
);
2176 TREE_TYPE (t
) = void_type_node
;
2177 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
2179 CASE_LOW (t
) = low_value
;
2180 CASE_HIGH (t
) = high_value
;
2181 CASE_LABEL (t
) = label_decl
;
2182 CASE_CHAIN (t
) = NULL_TREE
;
2187 /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2188 values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2189 The latter determines the length of the HOST_WIDE_INT vector. */
2192 make_int_cst_stat (int len
, int ext_len MEM_STAT_DECL
)
2195 int length
= ((ext_len
- 1) * sizeof (HOST_WIDE_INT
)
2196 + sizeof (struct tree_int_cst
));
2199 record_node_allocation_statistics (INTEGER_CST
, length
);
2201 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2203 TREE_SET_CODE (t
, INTEGER_CST
);
2204 TREE_INT_CST_NUNITS (t
) = len
;
2205 TREE_INT_CST_EXT_NUNITS (t
) = ext_len
;
2206 /* to_offset can only be applied to trees that are offset_int-sized
2207 or smaller. EXT_LEN is correct if it fits, otherwise the constant
2208 must be exactly the precision of offset_int and so LEN is correct. */
2209 if (ext_len
<= OFFSET_INT_ELTS
)
2210 TREE_INT_CST_OFFSET_NUNITS (t
) = ext_len
;
2212 TREE_INT_CST_OFFSET_NUNITS (t
) = len
;
2214 TREE_CONSTANT (t
) = 1;
2219 /* Build a newly constructed TREE_VEC node of length LEN. */
2222 make_tree_vec_stat (int len MEM_STAT_DECL
)
2225 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2227 record_node_allocation_statistics (TREE_VEC
, length
);
2229 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2231 TREE_SET_CODE (t
, TREE_VEC
);
2232 TREE_VEC_LENGTH (t
) = len
;
2237 /* Grow a TREE_VEC node to new length LEN. */
2240 grow_tree_vec_stat (tree v
, int len MEM_STAT_DECL
)
2242 gcc_assert (TREE_CODE (v
) == TREE_VEC
);
2244 int oldlen
= TREE_VEC_LENGTH (v
);
2245 gcc_assert (len
> oldlen
);
2247 int oldlength
= (oldlen
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2248 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2250 record_node_allocation_statistics (TREE_VEC
, length
- oldlength
);
2252 v
= (tree
) ggc_realloc (v
, length PASS_MEM_STAT
);
2254 TREE_VEC_LENGTH (v
) = len
;
2259 /* Return 1 if EXPR is the constant zero, whether it is integral, float or
2260 fixed, and scalar, complex or vector. */
2263 zerop (const_tree expr
)
2265 return (integer_zerop (expr
)
2266 || real_zerop (expr
)
2267 || fixed_zerop (expr
));
2270 /* Return 1 if EXPR is the integer constant zero or a complex constant
2274 integer_zerop (const_tree expr
)
2278 switch (TREE_CODE (expr
))
2281 return wi::eq_p (expr
, 0);
2283 return (integer_zerop (TREE_REALPART (expr
))
2284 && integer_zerop (TREE_IMAGPART (expr
)));
2288 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2289 if (!integer_zerop (VECTOR_CST_ELT (expr
, i
)))
2298 /* Return 1 if EXPR is the integer constant one or the corresponding
2299 complex constant. */
2302 integer_onep (const_tree expr
)
2306 switch (TREE_CODE (expr
))
2309 return wi::eq_p (wi::to_widest (expr
), 1);
2311 return (integer_onep (TREE_REALPART (expr
))
2312 && integer_zerop (TREE_IMAGPART (expr
)));
2316 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2317 if (!integer_onep (VECTOR_CST_ELT (expr
, i
)))
2326 /* Return 1 if EXPR is the integer constant one. For complex and vector,
2327 return 1 if every piece is the integer constant one. */
2330 integer_each_onep (const_tree expr
)
2334 if (TREE_CODE (expr
) == COMPLEX_CST
)
2335 return (integer_onep (TREE_REALPART (expr
))
2336 && integer_onep (TREE_IMAGPART (expr
)));
2338 return integer_onep (expr
);
2341 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
2342 it contains, or a complex or vector whose subparts are such integers. */
2345 integer_all_onesp (const_tree expr
)
2349 if (TREE_CODE (expr
) == COMPLEX_CST
2350 && integer_all_onesp (TREE_REALPART (expr
))
2351 && integer_all_onesp (TREE_IMAGPART (expr
)))
2354 else if (TREE_CODE (expr
) == VECTOR_CST
)
2357 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2358 if (!integer_all_onesp (VECTOR_CST_ELT (expr
, i
)))
2363 else if (TREE_CODE (expr
) != INTEGER_CST
)
2366 return wi::max_value (TYPE_PRECISION (TREE_TYPE (expr
)), UNSIGNED
) == expr
;
2369 /* Return 1 if EXPR is the integer constant minus one. */
2372 integer_minus_onep (const_tree expr
)
2376 if (TREE_CODE (expr
) == COMPLEX_CST
)
2377 return (integer_all_onesp (TREE_REALPART (expr
))
2378 && integer_zerop (TREE_IMAGPART (expr
)));
2380 return integer_all_onesp (expr
);
2383 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2387 integer_pow2p (const_tree expr
)
2391 if (TREE_CODE (expr
) == COMPLEX_CST
2392 && integer_pow2p (TREE_REALPART (expr
))
2393 && integer_zerop (TREE_IMAGPART (expr
)))
2396 if (TREE_CODE (expr
) != INTEGER_CST
)
2399 return wi::popcount (expr
) == 1;
2402 /* Return 1 if EXPR is an integer constant other than zero or a
2403 complex constant other than zero. */
2406 integer_nonzerop (const_tree expr
)
2410 return ((TREE_CODE (expr
) == INTEGER_CST
2411 && !wi::eq_p (expr
, 0))
2412 || (TREE_CODE (expr
) == COMPLEX_CST
2413 && (integer_nonzerop (TREE_REALPART (expr
))
2414 || integer_nonzerop (TREE_IMAGPART (expr
)))));
2417 /* Return 1 if EXPR is the integer constant one. For vector,
2418 return 1 if every piece is the integer constant minus one
2419 (representing the value TRUE). */
2422 integer_truep (const_tree expr
)
2426 if (TREE_CODE (expr
) == VECTOR_CST
)
2427 return integer_all_onesp (expr
);
2428 return integer_onep (expr
);
2431 /* Return 1 if EXPR is the fixed-point constant zero. */
2434 fixed_zerop (const_tree expr
)
2436 return (TREE_CODE (expr
) == FIXED_CST
2437 && TREE_FIXED_CST (expr
).data
.is_zero ());
2440 /* Return the power of two represented by a tree node known to be a
2444 tree_log2 (const_tree expr
)
2448 if (TREE_CODE (expr
) == COMPLEX_CST
)
2449 return tree_log2 (TREE_REALPART (expr
));
2451 return wi::exact_log2 (expr
);
2454 /* Similar, but return the largest integer Y such that 2 ** Y is less
2455 than or equal to EXPR. */
2458 tree_floor_log2 (const_tree expr
)
2462 if (TREE_CODE (expr
) == COMPLEX_CST
)
2463 return tree_log2 (TREE_REALPART (expr
));
2465 return wi::floor_log2 (expr
);
2468 /* Return number of known trailing zero bits in EXPR, or, if the value of
2469 EXPR is known to be zero, the precision of it's type. */
2472 tree_ctz (const_tree expr
)
2474 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
2475 && !POINTER_TYPE_P (TREE_TYPE (expr
)))
2478 unsigned int ret1
, ret2
, prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2479 switch (TREE_CODE (expr
))
2482 ret1
= wi::ctz (expr
);
2483 return MIN (ret1
, prec
);
2485 ret1
= wi::ctz (get_nonzero_bits (expr
));
2486 return MIN (ret1
, prec
);
2493 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2496 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2497 return MIN (ret1
, ret2
);
2498 case POINTER_PLUS_EXPR
:
2499 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2500 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2501 /* Second operand is sizetype, which could be in theory
2502 wider than pointer's precision. Make sure we never
2503 return more than prec. */
2504 ret2
= MIN (ret2
, prec
);
2505 return MIN (ret1
, ret2
);
2507 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2508 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2509 return MAX (ret1
, ret2
);
2511 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2512 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2513 return MIN (ret1
+ ret2
, prec
);
2515 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2516 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
2517 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
2519 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
2520 return MIN (ret1
+ ret2
, prec
);
2524 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
2525 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
2527 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2528 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
2533 case TRUNC_DIV_EXPR
:
2535 case FLOOR_DIV_EXPR
:
2536 case ROUND_DIV_EXPR
:
2537 case EXACT_DIV_EXPR
:
2538 if (TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
2539 && tree_int_cst_sgn (TREE_OPERAND (expr
, 1)) == 1)
2541 int l
= tree_log2 (TREE_OPERAND (expr
, 1));
2544 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2552 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2553 if (ret1
&& ret1
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2555 return MIN (ret1
, prec
);
2557 return tree_ctz (TREE_OPERAND (expr
, 0));
2559 ret1
= tree_ctz (TREE_OPERAND (expr
, 1));
2562 ret2
= tree_ctz (TREE_OPERAND (expr
, 2));
2563 return MIN (ret1
, ret2
);
2565 return tree_ctz (TREE_OPERAND (expr
, 1));
2567 ret1
= get_pointer_alignment (CONST_CAST_TREE (expr
));
2568 if (ret1
> BITS_PER_UNIT
)
2570 ret1
= ctz_hwi (ret1
/ BITS_PER_UNIT
);
2571 return MIN (ret1
, prec
);
2579 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2580 decimal float constants, so don't return 1 for them. */
2583 real_zerop (const_tree expr
)
2587 switch (TREE_CODE (expr
))
2590 return real_equal (&TREE_REAL_CST (expr
), &dconst0
)
2591 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2593 return real_zerop (TREE_REALPART (expr
))
2594 && real_zerop (TREE_IMAGPART (expr
));
2598 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2599 if (!real_zerop (VECTOR_CST_ELT (expr
, i
)))
2608 /* Return 1 if EXPR is the real constant one in real or complex form.
2609 Trailing zeroes matter for decimal float constants, so don't return
2613 real_onep (const_tree expr
)
2617 switch (TREE_CODE (expr
))
2620 return real_equal (&TREE_REAL_CST (expr
), &dconst1
)
2621 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2623 return real_onep (TREE_REALPART (expr
))
2624 && real_zerop (TREE_IMAGPART (expr
));
2628 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2629 if (!real_onep (VECTOR_CST_ELT (expr
, i
)))
2638 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2639 matter for decimal float constants, so don't return 1 for them. */
2642 real_minus_onep (const_tree expr
)
2646 switch (TREE_CODE (expr
))
2649 return real_equal (&TREE_REAL_CST (expr
), &dconstm1
)
2650 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2652 return real_minus_onep (TREE_REALPART (expr
))
2653 && real_zerop (TREE_IMAGPART (expr
));
2657 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2658 if (!real_minus_onep (VECTOR_CST_ELT (expr
, i
)))
2667 /* Nonzero if EXP is a constant or a cast of a constant. */
2670 really_constant_p (const_tree exp
)
2672 /* This is not quite the same as STRIP_NOPS. It does more. */
2673 while (CONVERT_EXPR_P (exp
)
2674 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2675 exp
= TREE_OPERAND (exp
, 0);
2676 return TREE_CONSTANT (exp
);
2679 /* Return first list element whose TREE_VALUE is ELEM.
2680 Return 0 if ELEM is not in LIST. */
2683 value_member (tree elem
, tree list
)
2687 if (elem
== TREE_VALUE (list
))
2689 list
= TREE_CHAIN (list
);
2694 /* Return first list element whose TREE_PURPOSE is ELEM.
2695 Return 0 if ELEM is not in LIST. */
2698 purpose_member (const_tree elem
, tree list
)
2702 if (elem
== TREE_PURPOSE (list
))
2704 list
= TREE_CHAIN (list
);
2709 /* Return true if ELEM is in V. */
2712 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
2716 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
2722 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2726 chain_index (int idx
, tree chain
)
2728 for (; chain
&& idx
> 0; --idx
)
2729 chain
= TREE_CHAIN (chain
);
2733 /* Return nonzero if ELEM is part of the chain CHAIN. */
2736 chain_member (const_tree elem
, const_tree chain
)
2742 chain
= DECL_CHAIN (chain
);
2748 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2749 We expect a null pointer to mark the end of the chain.
2750 This is the Lisp primitive `length'. */
2753 list_length (const_tree t
)
2756 #ifdef ENABLE_TREE_CHECKING
2764 #ifdef ENABLE_TREE_CHECKING
2767 gcc_assert (p
!= q
);
2775 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2776 UNION_TYPE TYPE, or NULL_TREE if none. */
2779 first_field (const_tree type
)
2781 tree t
= TYPE_FIELDS (type
);
2782 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2787 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2788 by modifying the last node in chain 1 to point to chain 2.
2789 This is the Lisp primitive `nconc'. */
2792 chainon (tree op1
, tree op2
)
2801 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2803 TREE_CHAIN (t1
) = op2
;
2805 #ifdef ENABLE_TREE_CHECKING
2808 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2809 gcc_assert (t2
!= t1
);
2816 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2819 tree_last (tree chain
)
2823 while ((next
= TREE_CHAIN (chain
)))
2828 /* Reverse the order of elements in the chain T,
2829 and return the new head of the chain (old last element). */
2834 tree prev
= 0, decl
, next
;
2835 for (decl
= t
; decl
; decl
= next
)
2837 /* We shouldn't be using this function to reverse BLOCK chains; we
2838 have blocks_nreverse for that. */
2839 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2840 next
= TREE_CHAIN (decl
);
2841 TREE_CHAIN (decl
) = prev
;
2847 /* Return a newly created TREE_LIST node whose
2848 purpose and value fields are PARM and VALUE. */
2851 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2853 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2854 TREE_PURPOSE (t
) = parm
;
2855 TREE_VALUE (t
) = value
;
2859 /* Build a chain of TREE_LIST nodes from a vector. */
2862 build_tree_list_vec_stat (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
2864 tree ret
= NULL_TREE
;
2868 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
2870 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2871 pp
= &TREE_CHAIN (*pp
);
2876 /* Return a newly created TREE_LIST node whose
2877 purpose and value fields are PURPOSE and VALUE
2878 and whose TREE_CHAIN is CHAIN. */
2881 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2885 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
2886 memset (node
, 0, sizeof (struct tree_common
));
2888 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2890 TREE_SET_CODE (node
, TREE_LIST
);
2891 TREE_CHAIN (node
) = chain
;
2892 TREE_PURPOSE (node
) = purpose
;
2893 TREE_VALUE (node
) = value
;
2897 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2901 ctor_to_vec (tree ctor
)
2903 vec
<tree
, va_gc
> *vec
;
2904 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
2908 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2909 vec
->quick_push (val
);
2914 /* Return the size nominally occupied by an object of type TYPE
2915 when it resides in memory. The value is measured in units of bytes,
2916 and its data type is that normally used for type sizes
2917 (which is the first type created by make_signed_type or
2918 make_unsigned_type). */
2921 size_in_bytes (const_tree type
)
2925 if (type
== error_mark_node
)
2926 return integer_zero_node
;
2928 type
= TYPE_MAIN_VARIANT (type
);
2929 t
= TYPE_SIZE_UNIT (type
);
2933 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2934 return size_zero_node
;
2940 /* Return the size of TYPE (in bytes) as a wide integer
2941 or return -1 if the size can vary or is larger than an integer. */
2944 int_size_in_bytes (const_tree type
)
2948 if (type
== error_mark_node
)
2951 type
= TYPE_MAIN_VARIANT (type
);
2952 t
= TYPE_SIZE_UNIT (type
);
2954 if (t
&& tree_fits_uhwi_p (t
))
2955 return TREE_INT_CST_LOW (t
);
2960 /* Return the maximum size of TYPE (in bytes) as a wide integer
2961 or return -1 if the size can vary or is larger than an integer. */
2964 max_int_size_in_bytes (const_tree type
)
2966 HOST_WIDE_INT size
= -1;
2969 /* If this is an array type, check for a possible MAX_SIZE attached. */
2971 if (TREE_CODE (type
) == ARRAY_TYPE
)
2973 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2975 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
2976 size
= tree_to_uhwi (size_tree
);
2979 /* If we still haven't been able to get a size, see if the language
2980 can compute a maximum size. */
2984 size_tree
= lang_hooks
.types
.max_size (type
);
2986 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
2987 size
= tree_to_uhwi (size_tree
);
2993 /* Return the bit position of FIELD, in bits from the start of the record.
2994 This is a tree of type bitsizetype. */
2997 bit_position (const_tree field
)
2999 return bit_from_pos (DECL_FIELD_OFFSET (field
),
3000 DECL_FIELD_BIT_OFFSET (field
));
3003 /* Return the byte position of FIELD, in bytes from the start of the record.
3004 This is a tree of type sizetype. */
3007 byte_position (const_tree field
)
3009 return byte_from_pos (DECL_FIELD_OFFSET (field
),
3010 DECL_FIELD_BIT_OFFSET (field
));
3013 /* Likewise, but return as an integer. It must be representable in
3014 that way (since it could be a signed value, we don't have the
3015 option of returning -1 like int_size_in_byte can. */
3018 int_byte_position (const_tree field
)
3020 return tree_to_shwi (byte_position (field
));
3023 /* Return the strictest alignment, in bits, that T is known to have. */
3026 expr_align (const_tree t
)
3028 unsigned int align0
, align1
;
3030 switch (TREE_CODE (t
))
3032 CASE_CONVERT
: case NON_LVALUE_EXPR
:
3033 /* If we have conversions, we know that the alignment of the
3034 object must meet each of the alignments of the types. */
3035 align0
= expr_align (TREE_OPERAND (t
, 0));
3036 align1
= TYPE_ALIGN (TREE_TYPE (t
));
3037 return MAX (align0
, align1
);
3039 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
3040 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
3041 case CLEANUP_POINT_EXPR
:
3042 /* These don't change the alignment of an object. */
3043 return expr_align (TREE_OPERAND (t
, 0));
3046 /* The best we can do is say that the alignment is the least aligned
3048 align0
= expr_align (TREE_OPERAND (t
, 1));
3049 align1
= expr_align (TREE_OPERAND (t
, 2));
3050 return MIN (align0
, align1
);
3052 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
3053 meaningfully, it's always 1. */
3054 case LABEL_DECL
: case CONST_DECL
:
3055 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
3057 gcc_assert (DECL_ALIGN (t
) != 0);
3058 return DECL_ALIGN (t
);
3064 /* Otherwise take the alignment from that of the type. */
3065 return TYPE_ALIGN (TREE_TYPE (t
));
3068 /* Return, as a tree node, the number of elements for TYPE (which is an
3069 ARRAY_TYPE) minus one. This counts only elements of the top array. */
3072 array_type_nelts (const_tree type
)
3074 tree index_type
, min
, max
;
3076 /* If they did it with unspecified bounds, then we should have already
3077 given an error about it before we got here. */
3078 if (! TYPE_DOMAIN (type
))
3079 return error_mark_node
;
3081 index_type
= TYPE_DOMAIN (type
);
3082 min
= TYPE_MIN_VALUE (index_type
);
3083 max
= TYPE_MAX_VALUE (index_type
);
3085 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3087 return error_mark_node
;
3089 return (integer_zerop (min
)
3091 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
3094 /* If arg is static -- a reference to an object in static storage -- then
3095 return the object. This is not the same as the C meaning of `static'.
3096 If arg isn't static, return NULL. */
3101 switch (TREE_CODE (arg
))
3104 /* Nested functions are static, even though taking their address will
3105 involve a trampoline as we unnest the nested function and create
3106 the trampoline on the tree level. */
3110 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3111 && ! DECL_THREAD_LOCAL_P (arg
)
3112 && ! DECL_DLLIMPORT_P (arg
)
3116 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3120 return TREE_STATIC (arg
) ? arg
: NULL
;
3127 /* If the thing being referenced is not a field, then it is
3128 something language specific. */
3129 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
3131 /* If we are referencing a bitfield, we can't evaluate an
3132 ADDR_EXPR at compile time and so it isn't a constant. */
3133 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
3136 return staticp (TREE_OPERAND (arg
, 0));
3142 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
3145 case ARRAY_RANGE_REF
:
3146 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
3147 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
3148 return staticp (TREE_OPERAND (arg
, 0));
3152 case COMPOUND_LITERAL_EXPR
:
3153 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
3163 /* Return whether OP is a DECL whose address is function-invariant. */
3166 decl_address_invariant_p (const_tree op
)
3168 /* The conditions below are slightly less strict than the one in
3171 switch (TREE_CODE (op
))
3180 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3181 || DECL_THREAD_LOCAL_P (op
)
3182 || DECL_CONTEXT (op
) == current_function_decl
3183 || decl_function_context (op
) == current_function_decl
)
3188 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3189 || decl_function_context (op
) == current_function_decl
)
3200 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3203 decl_address_ip_invariant_p (const_tree op
)
3205 /* The conditions below are slightly less strict than the one in
3208 switch (TREE_CODE (op
))
3216 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3217 && !DECL_DLLIMPORT_P (op
))
3218 || DECL_THREAD_LOCAL_P (op
))
3223 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
3235 /* Return true if T is function-invariant (internal function, does
3236 not handle arithmetic; that's handled in skip_simple_arithmetic and
3237 tree_invariant_p). */
3239 static bool tree_invariant_p (tree t
);
3242 tree_invariant_p_1 (tree t
)
3246 if (TREE_CONSTANT (t
)
3247 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
3250 switch (TREE_CODE (t
))
3256 op
= TREE_OPERAND (t
, 0);
3257 while (handled_component_p (op
))
3259 switch (TREE_CODE (op
))
3262 case ARRAY_RANGE_REF
:
3263 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
3264 || TREE_OPERAND (op
, 2) != NULL_TREE
3265 || TREE_OPERAND (op
, 3) != NULL_TREE
)
3270 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
3276 op
= TREE_OPERAND (op
, 0);
3279 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
3288 /* Return true if T is function-invariant. */
3291 tree_invariant_p (tree t
)
3293 tree inner
= skip_simple_arithmetic (t
);
3294 return tree_invariant_p_1 (inner
);
3297 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
3298 Do this to any expression which may be used in more than one place,
3299 but must be evaluated only once.
3301 Normally, expand_expr would reevaluate the expression each time.
3302 Calling save_expr produces something that is evaluated and recorded
3303 the first time expand_expr is called on it. Subsequent calls to
3304 expand_expr just reuse the recorded value.
3306 The call to expand_expr that generates code that actually computes
3307 the value is the first call *at compile time*. Subsequent calls
3308 *at compile time* generate code to use the saved value.
3309 This produces correct result provided that *at run time* control
3310 always flows through the insns made by the first expand_expr
3311 before reaching the other places where the save_expr was evaluated.
3312 You, the caller of save_expr, must make sure this is so.
3314 Constants, and certain read-only nodes, are returned with no
3315 SAVE_EXPR because that is safe. Expressions containing placeholders
3316 are not touched; see tree.def for an explanation of what these
3320 save_expr (tree expr
)
3322 tree t
= fold (expr
);
3325 /* If the tree evaluates to a constant, then we don't want to hide that
3326 fact (i.e. this allows further folding, and direct checks for constants).
3327 However, a read-only object that has side effects cannot be bypassed.
3328 Since it is no problem to reevaluate literals, we just return the
3330 inner
= skip_simple_arithmetic (t
);
3331 if (TREE_CODE (inner
) == ERROR_MARK
)
3334 if (tree_invariant_p_1 (inner
))
3337 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
3338 it means that the size or offset of some field of an object depends on
3339 the value within another field.
3341 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
3342 and some variable since it would then need to be both evaluated once and
3343 evaluated more than once. Front-ends must assure this case cannot
3344 happen by surrounding any such subexpressions in their own SAVE_EXPR
3345 and forcing evaluation at the proper time. */
3346 if (contains_placeholder_p (inner
))
3349 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
3350 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
3352 /* This expression might be placed ahead of a jump to ensure that the
3353 value was computed on both sides of the jump. So make sure it isn't
3354 eliminated as dead. */
3355 TREE_SIDE_EFFECTS (t
) = 1;
3359 /* Look inside EXPR into any simple arithmetic operations. Return the
3360 outermost non-arithmetic or non-invariant node. */
3363 skip_simple_arithmetic (tree expr
)
3365 /* We don't care about whether this can be used as an lvalue in this
3367 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3368 expr
= TREE_OPERAND (expr
, 0);
3370 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3371 a constant, it will be more efficient to not make another SAVE_EXPR since
3372 it will allow better simplification and GCSE will be able to merge the
3373 computations if they actually occur. */
3376 if (UNARY_CLASS_P (expr
))
3377 expr
= TREE_OPERAND (expr
, 0);
3378 else if (BINARY_CLASS_P (expr
))
3380 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
3381 expr
= TREE_OPERAND (expr
, 0);
3382 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
3383 expr
= TREE_OPERAND (expr
, 1);
3394 /* Look inside EXPR into simple arithmetic operations involving constants.
3395 Return the outermost non-arithmetic or non-constant node. */
3398 skip_simple_constant_arithmetic (tree expr
)
3400 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3401 expr
= TREE_OPERAND (expr
, 0);
3405 if (UNARY_CLASS_P (expr
))
3406 expr
= TREE_OPERAND (expr
, 0);
3407 else if (BINARY_CLASS_P (expr
))
3409 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
3410 expr
= TREE_OPERAND (expr
, 0);
3411 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3412 expr
= TREE_OPERAND (expr
, 1);
3423 /* Return which tree structure is used by T. */
3425 enum tree_node_structure_enum
3426 tree_node_structure (const_tree t
)
3428 const enum tree_code code
= TREE_CODE (t
);
3429 return tree_node_structure_for_code (code
);
3432 /* Set various status flags when building a CALL_EXPR object T. */
3435 process_call_operands (tree t
)
3437 bool side_effects
= TREE_SIDE_EFFECTS (t
);
3438 bool read_only
= false;
3439 int i
= call_expr_flags (t
);
3441 /* Calls have side-effects, except those to const or pure functions. */
3442 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
3443 side_effects
= true;
3444 /* Propagate TREE_READONLY of arguments for const functions. */
3448 if (!side_effects
|| read_only
)
3449 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3451 tree op
= TREE_OPERAND (t
, i
);
3452 if (op
&& TREE_SIDE_EFFECTS (op
))
3453 side_effects
= true;
3454 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3458 TREE_SIDE_EFFECTS (t
) = side_effects
;
3459 TREE_READONLY (t
) = read_only
;
3462 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3463 size or offset that depends on a field within a record. */
3466 contains_placeholder_p (const_tree exp
)
3468 enum tree_code code
;
3473 code
= TREE_CODE (exp
);
3474 if (code
== PLACEHOLDER_EXPR
)
3477 switch (TREE_CODE_CLASS (code
))
3480 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3481 position computations since they will be converted into a
3482 WITH_RECORD_EXPR involving the reference, which will assume
3483 here will be valid. */
3484 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3486 case tcc_exceptional
:
3487 if (code
== TREE_LIST
)
3488 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3489 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3494 case tcc_comparison
:
3495 case tcc_expression
:
3499 /* Ignoring the first operand isn't quite right, but works best. */
3500 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
3503 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3504 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
3505 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
3508 /* The save_expr function never wraps anything containing
3509 a PLACEHOLDER_EXPR. */
3516 switch (TREE_CODE_LENGTH (code
))
3519 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3521 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3522 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
3533 const_call_expr_arg_iterator iter
;
3534 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
3535 if (CONTAINS_PLACEHOLDER_P (arg
))
3549 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3550 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3554 type_contains_placeholder_1 (const_tree type
)
3556 /* If the size contains a placeholder or the parent type (component type in
3557 the case of arrays) type involves a placeholder, this type does. */
3558 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
3559 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
3560 || (!POINTER_TYPE_P (type
)
3562 && type_contains_placeholder_p (TREE_TYPE (type
))))
3565 /* Now do type-specific checks. Note that the last part of the check above
3566 greatly limits what we have to do below. */
3567 switch (TREE_CODE (type
))
3570 case POINTER_BOUNDS_TYPE
:
3576 case REFERENCE_TYPE
:
3585 case FIXED_POINT_TYPE
:
3586 /* Here we just check the bounds. */
3587 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
3588 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
3591 /* We have already checked the component type above, so just check the
3593 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
3597 case QUAL_UNION_TYPE
:
3601 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
3602 if (TREE_CODE (field
) == FIELD_DECL
3603 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
3604 || (TREE_CODE (type
) == QUAL_UNION_TYPE
3605 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
3606 || type_contains_placeholder_p (TREE_TYPE (field
))))
3617 /* Wrapper around above function used to cache its result. */
3620 type_contains_placeholder_p (tree type
)
3624 /* If the contains_placeholder_bits field has been initialized,
3625 then we know the answer. */
3626 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
3627 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
3629 /* Indicate that we've seen this type node, and the answer is false.
3630 This is what we want to return if we run into recursion via fields. */
3631 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
3633 /* Compute the real value. */
3634 result
= type_contains_placeholder_1 (type
);
3636 /* Store the real value. */
3637 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
3642 /* Push tree EXP onto vector QUEUE if it is not already present. */
3645 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
3650 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
3651 if (simple_cst_equal (iter
, exp
) == 1)
3655 queue
->safe_push (exp
);
3658 /* Given a tree EXP, find all occurrences of references to fields
3659 in a PLACEHOLDER_EXPR and place them in vector REFS without
3660 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3661 we assume here that EXP contains only arithmetic expressions
3662 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3666 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
3668 enum tree_code code
= TREE_CODE (exp
);
3672 /* We handle TREE_LIST and COMPONENT_REF separately. */
3673 if (code
== TREE_LIST
)
3675 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3676 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3678 else if (code
== COMPONENT_REF
)
3680 for (inner
= TREE_OPERAND (exp
, 0);
3681 REFERENCE_CLASS_P (inner
);
3682 inner
= TREE_OPERAND (inner
, 0))
3685 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3686 push_without_duplicates (exp
, refs
);
3688 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3691 switch (TREE_CODE_CLASS (code
))
3696 case tcc_declaration
:
3697 /* Variables allocated to static storage can stay. */
3698 if (!TREE_STATIC (exp
))
3699 push_without_duplicates (exp
, refs
);
3702 case tcc_expression
:
3703 /* This is the pattern built in ada/make_aligning_type. */
3704 if (code
== ADDR_EXPR
3705 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3707 push_without_duplicates (exp
, refs
);
3711 /* Fall through... */
3713 case tcc_exceptional
:
3716 case tcc_comparison
:
3718 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3719 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3723 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3724 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3732 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3733 return a tree with all occurrences of references to F in a
3734 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3735 CONST_DECLs. Note that we assume here that EXP contains only
3736 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3737 occurring only in their argument list. */
3740 substitute_in_expr (tree exp
, tree f
, tree r
)
3742 enum tree_code code
= TREE_CODE (exp
);
3743 tree op0
, op1
, op2
, op3
;
3746 /* We handle TREE_LIST and COMPONENT_REF separately. */
3747 if (code
== TREE_LIST
)
3749 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3750 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3751 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3754 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3756 else if (code
== COMPONENT_REF
)
3760 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3761 and it is the right field, replace it with R. */
3762 for (inner
= TREE_OPERAND (exp
, 0);
3763 REFERENCE_CLASS_P (inner
);
3764 inner
= TREE_OPERAND (inner
, 0))
3768 op1
= TREE_OPERAND (exp
, 1);
3770 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3773 /* If this expression hasn't been completed let, leave it alone. */
3774 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3777 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3778 if (op0
== TREE_OPERAND (exp
, 0))
3782 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3785 switch (TREE_CODE_CLASS (code
))
3790 case tcc_declaration
:
3796 case tcc_expression
:
3800 /* Fall through... */
3802 case tcc_exceptional
:
3805 case tcc_comparison
:
3807 switch (TREE_CODE_LENGTH (code
))
3813 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3814 if (op0
== TREE_OPERAND (exp
, 0))
3817 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3821 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3822 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3824 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3827 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3831 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3832 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3833 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3835 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3836 && op2
== TREE_OPERAND (exp
, 2))
3839 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3843 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3844 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3845 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3846 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3848 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3849 && op2
== TREE_OPERAND (exp
, 2)
3850 && op3
== TREE_OPERAND (exp
, 3))
3854 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3866 new_tree
= NULL_TREE
;
3868 /* If we are trying to replace F with a constant, inline back
3869 functions which do nothing else than computing a value from
3870 the arguments they are passed. This makes it possible to
3871 fold partially or entirely the replacement expression. */
3872 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3874 tree t
= maybe_inline_call_in_expr (exp
);
3876 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3879 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3881 tree op
= TREE_OPERAND (exp
, i
);
3882 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3886 new_tree
= copy_node (exp
);
3887 TREE_OPERAND (new_tree
, i
) = new_op
;
3893 new_tree
= fold (new_tree
);
3894 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3895 process_call_operands (new_tree
);
3906 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3908 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3909 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3914 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3915 for it within OBJ, a tree that is an object or a chain of references. */
3918 substitute_placeholder_in_expr (tree exp
, tree obj
)
3920 enum tree_code code
= TREE_CODE (exp
);
3921 tree op0
, op1
, op2
, op3
;
3924 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3925 in the chain of OBJ. */
3926 if (code
== PLACEHOLDER_EXPR
)
3928 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3931 for (elt
= obj
; elt
!= 0;
3932 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3933 || TREE_CODE (elt
) == COND_EXPR
)
3934 ? TREE_OPERAND (elt
, 1)
3935 : (REFERENCE_CLASS_P (elt
)
3936 || UNARY_CLASS_P (elt
)
3937 || BINARY_CLASS_P (elt
)
3938 || VL_EXP_CLASS_P (elt
)
3939 || EXPRESSION_CLASS_P (elt
))
3940 ? TREE_OPERAND (elt
, 0) : 0))
3941 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3944 for (elt
= obj
; elt
!= 0;
3945 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3946 || TREE_CODE (elt
) == COND_EXPR
)
3947 ? TREE_OPERAND (elt
, 1)
3948 : (REFERENCE_CLASS_P (elt
)
3949 || UNARY_CLASS_P (elt
)
3950 || BINARY_CLASS_P (elt
)
3951 || VL_EXP_CLASS_P (elt
)
3952 || EXPRESSION_CLASS_P (elt
))
3953 ? TREE_OPERAND (elt
, 0) : 0))
3954 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3955 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3957 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3959 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3960 survives until RTL generation, there will be an error. */
3964 /* TREE_LIST is special because we need to look at TREE_VALUE
3965 and TREE_CHAIN, not TREE_OPERANDS. */
3966 else if (code
== TREE_LIST
)
3968 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3969 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3970 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3973 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3976 switch (TREE_CODE_CLASS (code
))
3979 case tcc_declaration
:
3982 case tcc_exceptional
:
3985 case tcc_comparison
:
3986 case tcc_expression
:
3989 switch (TREE_CODE_LENGTH (code
))
3995 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3996 if (op0
== TREE_OPERAND (exp
, 0))
3999 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
4003 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4004 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4006 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
4009 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
4013 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4014 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4015 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
4017 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4018 && op2
== TREE_OPERAND (exp
, 2))
4021 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
4025 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4026 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4027 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
4028 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
4030 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4031 && op2
== TREE_OPERAND (exp
, 2)
4032 && op3
== TREE_OPERAND (exp
, 3))
4036 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
4048 new_tree
= NULL_TREE
;
4050 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4052 tree op
= TREE_OPERAND (exp
, i
);
4053 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
4057 new_tree
= copy_node (exp
);
4058 TREE_OPERAND (new_tree
, i
) = new_op
;
4064 new_tree
= fold (new_tree
);
4065 if (TREE_CODE (new_tree
) == CALL_EXPR
)
4066 process_call_operands (new_tree
);
4077 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
4079 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
4080 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
4086 /* Subroutine of stabilize_reference; this is called for subtrees of
4087 references. Any expression with side-effects must be put in a SAVE_EXPR
4088 to ensure that it is only evaluated once.
4090 We don't put SAVE_EXPR nodes around everything, because assigning very
4091 simple expressions to temporaries causes us to miss good opportunities
4092 for optimizations. Among other things, the opportunity to fold in the
4093 addition of a constant into an addressing mode often gets lost, e.g.
4094 "y[i+1] += x;". In general, we take the approach that we should not make
4095 an assignment unless we are forced into it - i.e., that any non-side effect
4096 operator should be allowed, and that cse should take care of coalescing
4097 multiple utterances of the same expression should that prove fruitful. */
4100 stabilize_reference_1 (tree e
)
4103 enum tree_code code
= TREE_CODE (e
);
4105 /* We cannot ignore const expressions because it might be a reference
4106 to a const array but whose index contains side-effects. But we can
4107 ignore things that are actual constant or that already have been
4108 handled by this function. */
4110 if (tree_invariant_p (e
))
4113 switch (TREE_CODE_CLASS (code
))
4115 case tcc_exceptional
:
4117 case tcc_declaration
:
4118 case tcc_comparison
:
4120 case tcc_expression
:
4123 /* If the expression has side-effects, then encase it in a SAVE_EXPR
4124 so that it will only be evaluated once. */
4125 /* The reference (r) and comparison (<) classes could be handled as
4126 below, but it is generally faster to only evaluate them once. */
4127 if (TREE_SIDE_EFFECTS (e
))
4128 return save_expr (e
);
4132 /* Constants need no processing. In fact, we should never reach
4137 /* Division is slow and tends to be compiled with jumps,
4138 especially the division by powers of 2 that is often
4139 found inside of an array reference. So do it just once. */
4140 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
4141 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
4142 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
4143 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
4144 return save_expr (e
);
4145 /* Recursively stabilize each operand. */
4146 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
4147 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
4151 /* Recursively stabilize each operand. */
4152 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
4159 TREE_TYPE (result
) = TREE_TYPE (e
);
4160 TREE_READONLY (result
) = TREE_READONLY (e
);
4161 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
4162 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
4167 /* Stabilize a reference so that we can use it any number of times
4168 without causing its operands to be evaluated more than once.
4169 Returns the stabilized reference. This works by means of save_expr,
4170 so see the caveats in the comments about save_expr.
4172 Also allows conversion expressions whose operands are references.
4173 Any other kind of expression is returned unchanged. */
4176 stabilize_reference (tree ref
)
4179 enum tree_code code
= TREE_CODE (ref
);
4186 /* No action is needed in this case. */
4191 case FIX_TRUNC_EXPR
:
4192 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
4196 result
= build_nt (INDIRECT_REF
,
4197 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
4201 result
= build_nt (COMPONENT_REF
,
4202 stabilize_reference (TREE_OPERAND (ref
, 0)),
4203 TREE_OPERAND (ref
, 1), NULL_TREE
);
4207 result
= build_nt (BIT_FIELD_REF
,
4208 stabilize_reference (TREE_OPERAND (ref
, 0)),
4209 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
4210 REF_REVERSE_STORAGE_ORDER (result
) = REF_REVERSE_STORAGE_ORDER (ref
);
4214 result
= build_nt (ARRAY_REF
,
4215 stabilize_reference (TREE_OPERAND (ref
, 0)),
4216 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4217 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4220 case ARRAY_RANGE_REF
:
4221 result
= build_nt (ARRAY_RANGE_REF
,
4222 stabilize_reference (TREE_OPERAND (ref
, 0)),
4223 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4224 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4228 /* We cannot wrap the first expression in a SAVE_EXPR, as then
4229 it wouldn't be ignored. This matters when dealing with
4231 return stabilize_reference_1 (ref
);
4233 /* If arg isn't a kind of lvalue we recognize, make no change.
4234 Caller should recognize the error for an invalid lvalue. */
4239 return error_mark_node
;
4242 TREE_TYPE (result
) = TREE_TYPE (ref
);
4243 TREE_READONLY (result
) = TREE_READONLY (ref
);
4244 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
4245 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
4250 /* Low-level constructors for expressions. */
4252 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
4253 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
4256 recompute_tree_invariant_for_addr_expr (tree t
)
4259 bool tc
= true, se
= false;
4261 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
);
4263 /* We started out assuming this address is both invariant and constant, but
4264 does not have side effects. Now go down any handled components and see if
4265 any of them involve offsets that are either non-constant or non-invariant.
4266 Also check for side-effects.
4268 ??? Note that this code makes no attempt to deal with the case where
4269 taking the address of something causes a copy due to misalignment. */
4271 #define UPDATE_FLAGS(NODE) \
4272 do { tree _node = (NODE); \
4273 if (_node && !TREE_CONSTANT (_node)) tc = false; \
4274 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
4276 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
4277 node
= TREE_OPERAND (node
, 0))
4279 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
4280 array reference (probably made temporarily by the G++ front end),
4281 so ignore all the operands. */
4282 if ((TREE_CODE (node
) == ARRAY_REF
4283 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
4284 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
4286 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
4287 if (TREE_OPERAND (node
, 2))
4288 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4289 if (TREE_OPERAND (node
, 3))
4290 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
4292 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
4293 FIELD_DECL, apparently. The G++ front end can put something else
4294 there, at least temporarily. */
4295 else if (TREE_CODE (node
) == COMPONENT_REF
4296 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
4298 if (TREE_OPERAND (node
, 2))
4299 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4303 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
4305 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
4306 the address, since &(*a)->b is a form of addition. If it's a constant, the
4307 address is constant too. If it's a decl, its address is constant if the
4308 decl is static. Everything else is not constant and, furthermore,
4309 taking the address of a volatile variable is not volatile. */
4310 if (TREE_CODE (node
) == INDIRECT_REF
4311 || TREE_CODE (node
) == MEM_REF
)
4312 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
4313 else if (CONSTANT_CLASS_P (node
))
4315 else if (DECL_P (node
))
4316 tc
&= (staticp (node
) != NULL_TREE
);
4320 se
|= TREE_SIDE_EFFECTS (node
);
4324 TREE_CONSTANT (t
) = tc
;
4325 TREE_SIDE_EFFECTS (t
) = se
;
4329 /* Build an expression of code CODE, data type TYPE, and operands as
4330 specified. Expressions and reference nodes can be created this way.
4331 Constants, decls, types and misc nodes cannot be.
4333 We define 5 non-variadic functions, from 0 to 4 arguments. This is
4334 enough for all extant tree codes. */
4337 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
4341 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
4343 t
= make_node_stat (code PASS_MEM_STAT
);
4350 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
4352 int length
= sizeof (struct tree_exp
);
4355 record_node_allocation_statistics (code
, length
);
4357 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
4359 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
4361 memset (t
, 0, sizeof (struct tree_common
));
4363 TREE_SET_CODE (t
, code
);
4365 TREE_TYPE (t
) = type
;
4366 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
4367 TREE_OPERAND (t
, 0) = node
;
4368 if (node
&& !TYPE_P (node
))
4370 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
4371 TREE_READONLY (t
) = TREE_READONLY (node
);
4374 if (TREE_CODE_CLASS (code
) == tcc_statement
)
4375 TREE_SIDE_EFFECTS (t
) = 1;
4379 /* All of these have side-effects, no matter what their
4381 TREE_SIDE_EFFECTS (t
) = 1;
4382 TREE_READONLY (t
) = 0;
4386 /* Whether a dereference is readonly has nothing to do with whether
4387 its operand is readonly. */
4388 TREE_READONLY (t
) = 0;
4393 recompute_tree_invariant_for_addr_expr (t
);
4397 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
4398 && node
&& !TYPE_P (node
)
4399 && TREE_CONSTANT (node
))
4400 TREE_CONSTANT (t
) = 1;
4401 if (TREE_CODE_CLASS (code
) == tcc_reference
4402 && node
&& TREE_THIS_VOLATILE (node
))
4403 TREE_THIS_VOLATILE (t
) = 1;
4410 #define PROCESS_ARG(N) \
4412 TREE_OPERAND (t, N) = arg##N; \
4413 if (arg##N &&!TYPE_P (arg##N)) \
4415 if (TREE_SIDE_EFFECTS (arg##N)) \
4417 if (!TREE_READONLY (arg##N) \
4418 && !CONSTANT_CLASS_P (arg##N)) \
4419 (void) (read_only = 0); \
4420 if (!TREE_CONSTANT (arg##N)) \
4421 (void) (constant = 0); \
4426 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
4428 bool constant
, read_only
, side_effects
;
4431 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
4433 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
4434 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
4435 /* When sizetype precision doesn't match that of pointers
4436 we need to be able to build explicit extensions or truncations
4437 of the offset argument. */
4438 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
4439 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
4440 && TREE_CODE (arg1
) == INTEGER_CST
);
4442 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4443 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4444 && ptrofftype_p (TREE_TYPE (arg1
)));
4446 t
= make_node_stat (code PASS_MEM_STAT
);
4449 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4450 result based on those same flags for the arguments. But if the
4451 arguments aren't really even `tree' expressions, we shouldn't be trying
4454 /* Expressions without side effects may be constant if their
4455 arguments are as well. */
4456 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4457 || TREE_CODE_CLASS (code
) == tcc_binary
);
4459 side_effects
= TREE_SIDE_EFFECTS (t
);
4464 TREE_SIDE_EFFECTS (t
) = side_effects
;
4465 if (code
== MEM_REF
)
4467 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
4469 tree o
= TREE_OPERAND (arg0
, 0);
4470 TREE_READONLY (t
) = TREE_READONLY (o
);
4471 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
4476 TREE_READONLY (t
) = read_only
;
4477 TREE_CONSTANT (t
) = constant
;
4478 TREE_THIS_VOLATILE (t
)
4479 = (TREE_CODE_CLASS (code
) == tcc_reference
4480 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4488 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4489 tree arg2 MEM_STAT_DECL
)
4491 bool constant
, read_only
, side_effects
;
4494 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
4495 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4497 t
= make_node_stat (code PASS_MEM_STAT
);
4502 /* As a special exception, if COND_EXPR has NULL branches, we
4503 assume that it is a gimple statement and always consider
4504 it to have side effects. */
4505 if (code
== COND_EXPR
4506 && tt
== void_type_node
4507 && arg1
== NULL_TREE
4508 && arg2
== NULL_TREE
)
4509 side_effects
= true;
4511 side_effects
= TREE_SIDE_EFFECTS (t
);
4517 if (code
== COND_EXPR
)
4518 TREE_READONLY (t
) = read_only
;
4520 TREE_SIDE_EFFECTS (t
) = side_effects
;
4521 TREE_THIS_VOLATILE (t
)
4522 = (TREE_CODE_CLASS (code
) == tcc_reference
4523 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4529 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4530 tree arg2
, tree arg3 MEM_STAT_DECL
)
4532 bool constant
, read_only
, side_effects
;
4535 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
4537 t
= make_node_stat (code PASS_MEM_STAT
);
4540 side_effects
= TREE_SIDE_EFFECTS (t
);
4547 TREE_SIDE_EFFECTS (t
) = side_effects
;
4548 TREE_THIS_VOLATILE (t
)
4549 = (TREE_CODE_CLASS (code
) == tcc_reference
4550 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4556 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4557 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
4559 bool constant
, read_only
, side_effects
;
4562 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
4564 t
= make_node_stat (code PASS_MEM_STAT
);
4567 side_effects
= TREE_SIDE_EFFECTS (t
);
4575 TREE_SIDE_EFFECTS (t
) = side_effects
;
4576 if (code
== TARGET_MEM_REF
)
4578 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
4580 tree o
= TREE_OPERAND (arg0
, 0);
4581 TREE_READONLY (t
) = TREE_READONLY (o
);
4582 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
4586 TREE_THIS_VOLATILE (t
)
4587 = (TREE_CODE_CLASS (code
) == tcc_reference
4588 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4593 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4594 on the pointer PTR. */
4597 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
4599 HOST_WIDE_INT offset
= 0;
4600 tree ptype
= TREE_TYPE (ptr
);
4602 /* For convenience allow addresses that collapse to a simple base
4604 if (TREE_CODE (ptr
) == ADDR_EXPR
4605 && (handled_component_p (TREE_OPERAND (ptr
, 0))
4606 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
4608 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
4610 ptr
= build_fold_addr_expr (ptr
);
4611 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
4613 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
4614 ptr
, build_int_cst (ptype
, offset
));
4615 SET_EXPR_LOCATION (tem
, loc
);
4619 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4622 mem_ref_offset (const_tree t
)
4624 return offset_int::from (TREE_OPERAND (t
, 1), SIGNED
);
4627 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4628 offsetted by OFFSET units. */
4631 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4633 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4634 build_fold_addr_expr (base
),
4635 build_int_cst (ptr_type_node
, offset
));
4636 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4637 recompute_tree_invariant_for_addr_expr (addr
);
4641 /* Similar except don't specify the TREE_TYPE
4642 and leave the TREE_SIDE_EFFECTS as 0.
4643 It is permissible for arguments to be null,
4644 or even garbage if their values do not matter. */
4647 build_nt (enum tree_code code
, ...)
4654 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4658 t
= make_node (code
);
4659 length
= TREE_CODE_LENGTH (code
);
4661 for (i
= 0; i
< length
; i
++)
4662 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4668 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4672 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
4677 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
4678 CALL_EXPR_FN (ret
) = fn
;
4679 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4680 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
4681 CALL_EXPR_ARG (ret
, ix
) = t
;
4685 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4686 We do NOT enter this node in any sort of symbol table.
4688 LOC is the location of the decl.
4690 layout_decl is used to set up the decl's storage layout.
4691 Other slots are initialized to 0 or null pointers. */
4694 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4695 tree type MEM_STAT_DECL
)
4699 t
= make_node_stat (code PASS_MEM_STAT
);
4700 DECL_SOURCE_LOCATION (t
) = loc
;
4702 /* if (type == error_mark_node)
4703 type = integer_type_node; */
4704 /* That is not done, deliberately, so that having error_mark_node
4705 as the type can suppress useless errors in the use of this variable. */
4707 DECL_NAME (t
) = name
;
4708 TREE_TYPE (t
) = type
;
4710 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4716 /* Builds and returns function declaration with NAME and TYPE. */
4719 build_fn_decl (const char *name
, tree type
)
4721 tree id
= get_identifier (name
);
4722 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4724 DECL_EXTERNAL (decl
) = 1;
4725 TREE_PUBLIC (decl
) = 1;
4726 DECL_ARTIFICIAL (decl
) = 1;
4727 TREE_NOTHROW (decl
) = 1;
4732 vec
<tree
, va_gc
> *all_translation_units
;
4734 /* Builds a new translation-unit decl with name NAME, queues it in the
4735 global list of translation-unit decls and returns it. */
4738 build_translation_unit_decl (tree name
)
4740 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4742 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4743 vec_safe_push (all_translation_units
, tu
);
4748 /* BLOCK nodes are used to represent the structure of binding contours
4749 and declarations, once those contours have been exited and their contents
4750 compiled. This information is used for outputting debugging info. */
4753 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4755 tree block
= make_node (BLOCK
);
4757 BLOCK_VARS (block
) = vars
;
4758 BLOCK_SUBBLOCKS (block
) = subblocks
;
4759 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4760 BLOCK_CHAIN (block
) = chain
;
4765 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4767 LOC is the location to use in tree T. */
4770 protected_set_expr_location (tree t
, location_t loc
)
4772 if (CAN_HAVE_LOCATION_P (t
))
4773 SET_EXPR_LOCATION (t
, loc
);
4776 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4780 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4782 DECL_ATTRIBUTES (ddecl
) = attribute
;
4786 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4787 is ATTRIBUTE and its qualifiers are QUALS.
4789 Record such modified types already made so we don't make duplicates. */
4792 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4794 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4796 inchash::hash hstate
;
4800 enum tree_code code
= TREE_CODE (ttype
);
4802 /* Building a distinct copy of a tagged type is inappropriate; it
4803 causes breakage in code that expects there to be a one-to-one
4804 relationship between a struct and its fields.
4805 build_duplicate_type is another solution (as used in
4806 handle_transparent_union_attribute), but that doesn't play well
4807 with the stronger C++ type identity model. */
4808 if (TREE_CODE (ttype
) == RECORD_TYPE
4809 || TREE_CODE (ttype
) == UNION_TYPE
4810 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4811 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4813 warning (OPT_Wattributes
,
4814 "ignoring attributes applied to %qT after definition",
4815 TYPE_MAIN_VARIANT (ttype
));
4816 return build_qualified_type (ttype
, quals
);
4819 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4820 ntype
= build_distinct_type_copy (ttype
);
4822 TYPE_ATTRIBUTES (ntype
) = attribute
;
4824 hstate
.add_int (code
);
4825 if (TREE_TYPE (ntype
))
4826 hstate
.add_object (TYPE_HASH (TREE_TYPE (ntype
)));
4827 attribute_hash_list (attribute
, hstate
);
4829 switch (TREE_CODE (ntype
))
4832 type_hash_list (TYPE_ARG_TYPES (ntype
), hstate
);
4835 if (TYPE_DOMAIN (ntype
))
4836 hstate
.add_object (TYPE_HASH (TYPE_DOMAIN (ntype
)));
4839 t
= TYPE_MAX_VALUE (ntype
);
4840 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
4841 hstate
.add_object (TREE_INT_CST_ELT (t
, i
));
4844 case FIXED_POINT_TYPE
:
4846 unsigned int precision
= TYPE_PRECISION (ntype
);
4847 hstate
.add_object (precision
);
4854 ntype
= type_hash_canon (hstate
.end(), ntype
);
4856 /* If the target-dependent attributes make NTYPE different from
4857 its canonical type, we will need to use structural equality
4858 checks for this type. */
4859 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4860 || !comp_type_attributes (ntype
, ttype
))
4861 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4862 else if (TYPE_CANONICAL (ntype
) == ntype
)
4863 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4865 ttype
= build_qualified_type (ntype
, quals
);
4867 else if (TYPE_QUALS (ttype
) != quals
)
4868 ttype
= build_qualified_type (ttype
, quals
);
4873 /* Check if "omp declare simd" attribute arguments, CLAUSES1 and CLAUSES2, are
4877 omp_declare_simd_clauses_equal (tree clauses1
, tree clauses2
)
4880 for (cl1
= clauses1
, cl2
= clauses2
;
4882 cl1
= OMP_CLAUSE_CHAIN (cl1
), cl2
= OMP_CLAUSE_CHAIN (cl2
))
4884 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_CODE (cl2
))
4886 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_SIMDLEN
)
4888 if (simple_cst_equal (OMP_CLAUSE_DECL (cl1
),
4889 OMP_CLAUSE_DECL (cl2
)) != 1)
4892 switch (OMP_CLAUSE_CODE (cl1
))
4894 case OMP_CLAUSE_ALIGNED
:
4895 if (simple_cst_equal (OMP_CLAUSE_ALIGNED_ALIGNMENT (cl1
),
4896 OMP_CLAUSE_ALIGNED_ALIGNMENT (cl2
)) != 1)
4899 case OMP_CLAUSE_LINEAR
:
4900 if (simple_cst_equal (OMP_CLAUSE_LINEAR_STEP (cl1
),
4901 OMP_CLAUSE_LINEAR_STEP (cl2
)) != 1)
4904 case OMP_CLAUSE_SIMDLEN
:
4905 if (simple_cst_equal (OMP_CLAUSE_SIMDLEN_EXPR (cl1
),
4906 OMP_CLAUSE_SIMDLEN_EXPR (cl2
)) != 1)
4915 /* Compare two constructor-element-type constants. Return 1 if the lists
4916 are known to be equal; otherwise return 0. */
4919 simple_cst_list_equal (const_tree l1
, const_tree l2
)
4921 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
4923 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
4926 l1
= TREE_CHAIN (l1
);
4927 l2
= TREE_CHAIN (l2
);
4933 /* Compare two identifier nodes representing attributes. Either one may
4934 be in wrapped __ATTR__ form. Return true if they are the same, false
4938 cmp_attrib_identifiers (const_tree attr1
, const_tree attr2
)
4940 /* Make sure we're dealing with IDENTIFIER_NODEs. */
4941 gcc_checking_assert (TREE_CODE (attr1
) == IDENTIFIER_NODE
4942 && TREE_CODE (attr2
) == IDENTIFIER_NODE
);
4944 /* Identifiers can be compared directly for equality. */
4948 /* If they are not equal, they may still be one in the form
4949 'text' while the other one is in the form '__text__'. TODO:
4950 If we were storing attributes in normalized 'text' form, then
4951 this could all go away and we could take full advantage of
4952 the fact that we're comparing identifiers. :-) */
4953 const size_t attr1_len
= IDENTIFIER_LENGTH (attr1
);
4954 const size_t attr2_len
= IDENTIFIER_LENGTH (attr2
);
4956 if (attr2_len
== attr1_len
+ 4)
4958 const char *p
= IDENTIFIER_POINTER (attr2
);
4959 const char *q
= IDENTIFIER_POINTER (attr1
);
4960 if (p
[0] == '_' && p
[1] == '_'
4961 && p
[attr2_len
- 2] == '_' && p
[attr2_len
- 1] == '_'
4962 && strncmp (q
, p
+ 2, attr1_len
) == 0)
4965 else if (attr2_len
+ 4 == attr1_len
)
4967 const char *p
= IDENTIFIER_POINTER (attr2
);
4968 const char *q
= IDENTIFIER_POINTER (attr1
);
4969 if (q
[0] == '_' && q
[1] == '_'
4970 && q
[attr1_len
- 2] == '_' && q
[attr1_len
- 1] == '_'
4971 && strncmp (q
+ 2, p
, attr2_len
) == 0)
4978 /* Compare two attributes for their value identity. Return true if the
4979 attribute values are known to be equal; otherwise return false. */
4982 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4984 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4987 if (TREE_VALUE (attr1
) != NULL_TREE
4988 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4989 && TREE_VALUE (attr2
) != NULL_TREE
4990 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4992 /* Handle attribute format. */
4993 if (is_attribute_p ("format", TREE_PURPOSE (attr1
)))
4995 attr1
= TREE_VALUE (attr1
);
4996 attr2
= TREE_VALUE (attr2
);
4997 /* Compare the archetypes (printf/scanf/strftime/...). */
4998 if (!cmp_attrib_identifiers (TREE_VALUE (attr1
),
4999 TREE_VALUE (attr2
)))
5001 /* Archetypes are the same. Compare the rest. */
5002 return (simple_cst_list_equal (TREE_CHAIN (attr1
),
5003 TREE_CHAIN (attr2
)) == 1);
5005 return (simple_cst_list_equal (TREE_VALUE (attr1
),
5006 TREE_VALUE (attr2
)) == 1);
5009 if ((flag_openmp
|| flag_openmp_simd
)
5010 && TREE_VALUE (attr1
) && TREE_VALUE (attr2
)
5011 && TREE_CODE (TREE_VALUE (attr1
)) == OMP_CLAUSE
5012 && TREE_CODE (TREE_VALUE (attr2
)) == OMP_CLAUSE
)
5013 return omp_declare_simd_clauses_equal (TREE_VALUE (attr1
),
5014 TREE_VALUE (attr2
));
5016 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
5019 /* Return 0 if the attributes for two types are incompatible, 1 if they
5020 are compatible, and 2 if they are nearly compatible (which causes a
5021 warning to be generated). */
5023 comp_type_attributes (const_tree type1
, const_tree type2
)
5025 const_tree a1
= TYPE_ATTRIBUTES (type1
);
5026 const_tree a2
= TYPE_ATTRIBUTES (type2
);
5031 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
5033 const struct attribute_spec
*as
;
5036 as
= lookup_attribute_spec (get_attribute_name (a
));
5037 if (!as
|| as
->affects_type_identity
== false)
5040 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
5041 if (!attr
|| !attribute_value_equal (a
, attr
))
5046 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
5048 const struct attribute_spec
*as
;
5050 as
= lookup_attribute_spec (get_attribute_name (a
));
5051 if (!as
|| as
->affects_type_identity
== false)
5054 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
5056 /* We don't need to compare trees again, as we did this
5057 already in first loop. */
5059 /* All types - affecting identity - are equal, so
5060 there is no need to call target hook for comparison. */
5064 if (lookup_attribute ("transaction_safe", CONST_CAST_TREE (a
)))
5066 /* As some type combinations - like default calling-convention - might
5067 be compatible, we have to call the target hook to get the final result. */
5068 return targetm
.comp_type_attributes (type1
, type2
);
5071 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
5074 Record such modified types already made so we don't make duplicates. */
5077 build_type_attribute_variant (tree ttype
, tree attribute
)
5079 return build_type_attribute_qual_variant (ttype
, attribute
,
5080 TYPE_QUALS (ttype
));
5084 /* Reset the expression *EXPR_P, a size or position.
5086 ??? We could reset all non-constant sizes or positions. But it's cheap
5087 enough to not do so and refrain from adding workarounds to dwarf2out.c.
5089 We need to reset self-referential sizes or positions because they cannot
5090 be gimplified and thus can contain a CALL_EXPR after the gimplification
5091 is finished, which will run afoul of LTO streaming. And they need to be
5092 reset to something essentially dummy but not constant, so as to preserve
5093 the properties of the object they are attached to. */
5096 free_lang_data_in_one_sizepos (tree
*expr_p
)
5098 tree expr
= *expr_p
;
5099 if (CONTAINS_PLACEHOLDER_P (expr
))
5100 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
5104 /* Reset all the fields in a binfo node BINFO. We only keep
5105 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
5108 free_lang_data_in_binfo (tree binfo
)
5113 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
5115 BINFO_VIRTUALS (binfo
) = NULL_TREE
;
5116 BINFO_BASE_ACCESSES (binfo
) = NULL
;
5117 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
5118 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
5120 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo
), i
, t
)
5121 free_lang_data_in_binfo (t
);
5125 /* Reset all language specific information still present in TYPE. */
5128 free_lang_data_in_type (tree type
)
5130 gcc_assert (TYPE_P (type
));
5132 /* Give the FE a chance to remove its own data first. */
5133 lang_hooks
.free_lang_data (type
);
5135 TREE_LANG_FLAG_0 (type
) = 0;
5136 TREE_LANG_FLAG_1 (type
) = 0;
5137 TREE_LANG_FLAG_2 (type
) = 0;
5138 TREE_LANG_FLAG_3 (type
) = 0;
5139 TREE_LANG_FLAG_4 (type
) = 0;
5140 TREE_LANG_FLAG_5 (type
) = 0;
5141 TREE_LANG_FLAG_6 (type
) = 0;
5143 if (TREE_CODE (type
) == FUNCTION_TYPE
)
5145 /* Remove the const and volatile qualifiers from arguments. The
5146 C++ front end removes them, but the C front end does not,
5147 leading to false ODR violation errors when merging two
5148 instances of the same function signature compiled by
5149 different front ends. */
5152 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
5154 tree arg_type
= TREE_VALUE (p
);
5156 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
5158 int quals
= TYPE_QUALS (arg_type
)
5160 & ~TYPE_QUAL_VOLATILE
;
5161 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
5162 free_lang_data_in_type (TREE_VALUE (p
));
5164 /* C++ FE uses TREE_PURPOSE to store initial values. */
5165 TREE_PURPOSE (p
) = NULL
;
5167 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
5168 TYPE_MINVAL (type
) = NULL
;
5170 if (TREE_CODE (type
) == METHOD_TYPE
)
5174 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
5176 /* C++ FE uses TREE_PURPOSE to store initial values. */
5177 TREE_PURPOSE (p
) = NULL
;
5179 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
5180 TYPE_MINVAL (type
) = NULL
;
5183 /* Remove members that are not actually FIELD_DECLs from the field
5184 list of an aggregate. These occur in C++. */
5185 if (RECORD_OR_UNION_TYPE_P (type
))
5189 /* Note that TYPE_FIELDS can be shared across distinct
5190 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
5191 to be removed, we cannot set its TREE_CHAIN to NULL.
5192 Otherwise, we would not be able to find all the other fields
5193 in the other instances of this TREE_TYPE.
5195 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
5197 member
= TYPE_FIELDS (type
);
5200 if (TREE_CODE (member
) == FIELD_DECL
5201 || TREE_CODE (member
) == TYPE_DECL
)
5204 TREE_CHAIN (prev
) = member
;
5206 TYPE_FIELDS (type
) = member
;
5210 member
= TREE_CHAIN (member
);
5214 TREE_CHAIN (prev
) = NULL_TREE
;
5216 TYPE_FIELDS (type
) = NULL_TREE
;
5218 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
5219 and danagle the pointer from time to time. */
5220 if (TYPE_VFIELD (type
) && TREE_CODE (TYPE_VFIELD (type
)) != FIELD_DECL
)
5221 TYPE_VFIELD (type
) = NULL_TREE
;
5223 /* Remove TYPE_METHODS list. While it would be nice to keep it
5224 to enable ODR warnings about different method lists, doing so
5225 seems to impractically increase size of LTO data streamed.
5226 Keep the infrmation if TYPE_METHODS was non-NULL. This is used
5227 by function.c and pretty printers. */
5228 if (TYPE_METHODS (type
))
5229 TYPE_METHODS (type
) = error_mark_node
;
5230 if (TYPE_BINFO (type
))
5232 free_lang_data_in_binfo (TYPE_BINFO (type
));
5233 /* We need to preserve link to bases and virtual table for all
5234 polymorphic types to make devirtualization machinery working.
5235 Debug output cares only about bases, but output also
5236 virtual table pointers so merging of -fdevirtualize and
5237 -fno-devirtualize units is easier. */
5238 if ((!BINFO_VTABLE (TYPE_BINFO (type
))
5239 || !flag_devirtualize
)
5240 && ((!BINFO_N_BASE_BINFOS (TYPE_BINFO (type
))
5241 && !BINFO_VTABLE (TYPE_BINFO (type
)))
5242 || debug_info_level
!= DINFO_LEVEL_NONE
))
5243 TYPE_BINFO (type
) = NULL
;
5248 /* For non-aggregate types, clear out the language slot (which
5249 overloads TYPE_BINFO). */
5250 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
5252 if (INTEGRAL_TYPE_P (type
)
5253 || SCALAR_FLOAT_TYPE_P (type
)
5254 || FIXED_POINT_TYPE_P (type
))
5256 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
5257 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
5261 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
5262 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
5264 if (TYPE_CONTEXT (type
)
5265 && TREE_CODE (TYPE_CONTEXT (type
)) == BLOCK
)
5267 tree ctx
= TYPE_CONTEXT (type
);
5270 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5272 while (ctx
&& TREE_CODE (ctx
) == BLOCK
);
5273 TYPE_CONTEXT (type
) = ctx
;
5278 /* Return true if DECL may need an assembler name to be set. */
5281 need_assembler_name_p (tree decl
)
5283 /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
5284 Rule merging. This makes type_odr_p to return true on those types during
5285 LTO and by comparing the mangled name, we can say what types are intended
5286 to be equivalent across compilation unit.
5288 We do not store names of type_in_anonymous_namespace_p.
5290 Record, union and enumeration type have linkage that allows use
5291 to check type_in_anonymous_namespace_p. We do not mangle compound types
5292 that always can be compared structurally.
5294 Similarly for builtin types, we compare properties of their main variant.
5295 A special case are integer types where mangling do make differences
5296 between char/signed char/unsigned char etc. Storing name for these makes
5297 e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
5298 See cp/mangle.c:write_builtin_type for details. */
5300 if (flag_lto_odr_type_mering
5301 && TREE_CODE (decl
) == TYPE_DECL
5303 && decl
== TYPE_NAME (TREE_TYPE (decl
))
5304 && !TYPE_ARTIFICIAL (TREE_TYPE (decl
))
5305 && (type_with_linkage_p (TREE_TYPE (decl
))
5306 || TREE_CODE (TREE_TYPE (decl
)) == INTEGER_TYPE
)
5307 && !variably_modified_type_p (TREE_TYPE (decl
), NULL_TREE
))
5308 return !DECL_ASSEMBLER_NAME_SET_P (decl
);
5309 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
5310 if (TREE_CODE (decl
) != FUNCTION_DECL
5311 && TREE_CODE (decl
) != VAR_DECL
)
5314 /* If DECL already has its assembler name set, it does not need a
5316 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
5317 || DECL_ASSEMBLER_NAME_SET_P (decl
))
5320 /* Abstract decls do not need an assembler name. */
5321 if (DECL_ABSTRACT_P (decl
))
5324 /* For VAR_DECLs, only static, public and external symbols need an
5326 if (TREE_CODE (decl
) == VAR_DECL
5327 && !TREE_STATIC (decl
)
5328 && !TREE_PUBLIC (decl
)
5329 && !DECL_EXTERNAL (decl
))
5332 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5334 /* Do not set assembler name on builtins. Allow RTL expansion to
5335 decide whether to expand inline or via a regular call. */
5336 if (DECL_BUILT_IN (decl
)
5337 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
5340 /* Functions represented in the callgraph need an assembler name. */
5341 if (cgraph_node::get (decl
) != NULL
)
5344 /* Unused and not public functions don't need an assembler name. */
5345 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
5353 /* Reset all language specific information still present in symbol
5357 free_lang_data_in_decl (tree decl
)
5359 gcc_assert (DECL_P (decl
));
5361 /* Give the FE a chance to remove its own data first. */
5362 lang_hooks
.free_lang_data (decl
);
5364 TREE_LANG_FLAG_0 (decl
) = 0;
5365 TREE_LANG_FLAG_1 (decl
) = 0;
5366 TREE_LANG_FLAG_2 (decl
) = 0;
5367 TREE_LANG_FLAG_3 (decl
) = 0;
5368 TREE_LANG_FLAG_4 (decl
) = 0;
5369 TREE_LANG_FLAG_5 (decl
) = 0;
5370 TREE_LANG_FLAG_6 (decl
) = 0;
5372 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
5373 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
5374 if (TREE_CODE (decl
) == FIELD_DECL
)
5376 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
5377 if (TREE_CODE (DECL_CONTEXT (decl
)) == QUAL_UNION_TYPE
)
5378 DECL_QUALIFIER (decl
) = NULL_TREE
;
5381 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5383 struct cgraph_node
*node
;
5384 if (!(node
= cgraph_node::get (decl
))
5385 || (!node
->definition
&& !node
->clones
))
5388 node
->release_body ();
5391 release_function_body (decl
);
5392 DECL_ARGUMENTS (decl
) = NULL
;
5393 DECL_RESULT (decl
) = NULL
;
5394 DECL_INITIAL (decl
) = error_mark_node
;
5397 if (gimple_has_body_p (decl
))
5401 /* If DECL has a gimple body, then the context for its
5402 arguments must be DECL. Otherwise, it doesn't really
5403 matter, as we will not be emitting any code for DECL. In
5404 general, there may be other instances of DECL created by
5405 the front end and since PARM_DECLs are generally shared,
5406 their DECL_CONTEXT changes as the replicas of DECL are
5407 created. The only time where DECL_CONTEXT is important
5408 is for the FUNCTION_DECLs that have a gimple body (since
5409 the PARM_DECL will be used in the function's body). */
5410 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
5411 DECL_CONTEXT (t
) = decl
;
5412 if (!DECL_FUNCTION_SPECIFIC_TARGET (decl
))
5413 DECL_FUNCTION_SPECIFIC_TARGET (decl
)
5414 = target_option_default_node
;
5415 if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl
))
5416 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl
)
5417 = optimization_default_node
;
5420 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
5421 At this point, it is not needed anymore. */
5422 DECL_SAVED_TREE (decl
) = NULL_TREE
;
5424 /* Clear the abstract origin if it refers to a method. Otherwise
5425 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
5426 origin will not be output correctly. */
5427 if (DECL_ABSTRACT_ORIGIN (decl
)
5428 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
5429 && RECORD_OR_UNION_TYPE_P
5430 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
5431 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
5433 /* Sometimes the C++ frontend doesn't manage to transform a temporary
5434 DECL_VINDEX referring to itself into a vtable slot number as it
5435 should. Happens with functions that are copied and then forgotten
5436 about. Just clear it, it won't matter anymore. */
5437 if (DECL_VINDEX (decl
) && !tree_fits_shwi_p (DECL_VINDEX (decl
)))
5438 DECL_VINDEX (decl
) = NULL_TREE
;
5440 else if (TREE_CODE (decl
) == VAR_DECL
)
5442 if ((DECL_EXTERNAL (decl
)
5443 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
5444 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
5445 DECL_INITIAL (decl
) = NULL_TREE
;
5447 else if (TREE_CODE (decl
) == TYPE_DECL
5448 || TREE_CODE (decl
) == FIELD_DECL
)
5449 DECL_INITIAL (decl
) = NULL_TREE
;
5450 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
5451 && DECL_INITIAL (decl
)
5452 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
5454 /* Strip builtins from the translation-unit BLOCK. We still have targets
5455 without builtin_decl_explicit support and also builtins are shared
5456 nodes and thus we can't use TREE_CHAIN in multiple lists. */
5457 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
5461 if (TREE_CODE (var
) == FUNCTION_DECL
5462 && DECL_BUILT_IN (var
))
5463 *nextp
= TREE_CHAIN (var
);
5465 nextp
= &TREE_CHAIN (var
);
5471 /* Data used when collecting DECLs and TYPEs for language data removal. */
5473 struct free_lang_data_d
5475 /* Worklist to avoid excessive recursion. */
5478 /* Set of traversed objects. Used to avoid duplicate visits. */
5479 hash_set
<tree
> *pset
;
5481 /* Array of symbols to process with free_lang_data_in_decl. */
5484 /* Array of types to process with free_lang_data_in_type. */
5489 /* Save all language fields needed to generate proper debug information
5490 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
5493 save_debug_info_for_decl (tree t
)
5495 /*struct saved_debug_info_d *sdi;*/
5497 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
5499 /* FIXME. Partial implementation for saving debug info removed. */
5503 /* Save all language fields needed to generate proper debug information
5504 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5507 save_debug_info_for_type (tree t
)
5509 /*struct saved_debug_info_d *sdi;*/
5511 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
5513 /* FIXME. Partial implementation for saving debug info removed. */
5517 /* Add type or decl T to one of the list of tree nodes that need their
5518 language data removed. The lists are held inside FLD. */
5521 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
5525 fld
->decls
.safe_push (t
);
5526 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5527 save_debug_info_for_decl (t
);
5529 else if (TYPE_P (t
))
5531 fld
->types
.safe_push (t
);
5532 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5533 save_debug_info_for_type (t
);
5539 /* Push tree node T into FLD->WORKLIST. */
5542 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
5544 if (t
&& !is_lang_specific (t
) && !fld
->pset
->contains (t
))
5545 fld
->worklist
.safe_push ((t
));
5549 /* Operand callback helper for free_lang_data_in_node. *TP is the
5550 subtree operand being considered. */
5553 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
5556 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
5558 if (TREE_CODE (t
) == TREE_LIST
)
5561 /* Language specific nodes will be removed, so there is no need
5562 to gather anything under them. */
5563 if (is_lang_specific (t
))
5571 /* Note that walk_tree does not traverse every possible field in
5572 decls, so we have to do our own traversals here. */
5573 add_tree_to_fld_list (t
, fld
);
5575 fld_worklist_push (DECL_NAME (t
), fld
);
5576 fld_worklist_push (DECL_CONTEXT (t
), fld
);
5577 fld_worklist_push (DECL_SIZE (t
), fld
);
5578 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
5580 /* We are going to remove everything under DECL_INITIAL for
5581 TYPE_DECLs. No point walking them. */
5582 if (TREE_CODE (t
) != TYPE_DECL
)
5583 fld_worklist_push (DECL_INITIAL (t
), fld
);
5585 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
5586 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
5588 if (TREE_CODE (t
) == FUNCTION_DECL
)
5590 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
5591 fld_worklist_push (DECL_RESULT (t
), fld
);
5593 else if (TREE_CODE (t
) == TYPE_DECL
)
5595 fld_worklist_push (DECL_ORIGINAL_TYPE (t
), fld
);
5597 else if (TREE_CODE (t
) == FIELD_DECL
)
5599 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
5600 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
5601 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
5602 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
5605 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
5606 && DECL_HAS_VALUE_EXPR_P (t
))
5607 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
5609 if (TREE_CODE (t
) != FIELD_DECL
5610 && TREE_CODE (t
) != TYPE_DECL
)
5611 fld_worklist_push (TREE_CHAIN (t
), fld
);
5614 else if (TYPE_P (t
))
5616 /* Note that walk_tree does not traverse every possible field in
5617 types, so we have to do our own traversals here. */
5618 add_tree_to_fld_list (t
, fld
);
5620 if (!RECORD_OR_UNION_TYPE_P (t
))
5621 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
5622 fld_worklist_push (TYPE_SIZE (t
), fld
);
5623 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
5624 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
5625 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
5626 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
5627 fld_worklist_push (TYPE_NAME (t
), fld
);
5628 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5629 them and thus do not and want not to reach unused pointer types
5631 if (!POINTER_TYPE_P (t
))
5632 fld_worklist_push (TYPE_MINVAL (t
), fld
);
5633 if (!RECORD_OR_UNION_TYPE_P (t
))
5634 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
5635 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
5636 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5637 do not and want not to reach unused variants this way. */
5638 if (TYPE_CONTEXT (t
))
5640 tree ctx
= TYPE_CONTEXT (t
);
5641 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5642 So push that instead. */
5643 while (ctx
&& TREE_CODE (ctx
) == BLOCK
)
5644 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5645 fld_worklist_push (ctx
, fld
);
5647 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5648 and want not to reach unused types this way. */
5650 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
5654 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t
)), i
, tem
)
5655 fld_worklist_push (TREE_TYPE (tem
), fld
);
5656 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
5658 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5659 && TREE_CODE (tem
) == TREE_LIST
)
5662 fld_worklist_push (TREE_VALUE (tem
), fld
);
5663 tem
= TREE_CHAIN (tem
);
5667 if (RECORD_OR_UNION_TYPE_P (t
))
5670 /* Push all TYPE_FIELDS - there can be interleaving interesting
5671 and non-interesting things. */
5672 tem
= TYPE_FIELDS (t
);
5675 if (TREE_CODE (tem
) == FIELD_DECL
5676 || TREE_CODE (tem
) == TYPE_DECL
)
5677 fld_worklist_push (tem
, fld
);
5678 tem
= TREE_CHAIN (tem
);
5682 fld_worklist_push (TYPE_STUB_DECL (t
), fld
);
5685 else if (TREE_CODE (t
) == BLOCK
)
5688 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
5689 fld_worklist_push (tem
, fld
);
5690 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
5691 fld_worklist_push (tem
, fld
);
5692 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
5695 if (TREE_CODE (t
) != IDENTIFIER_NODE
5696 && CODE_CONTAINS_STRUCT (TREE_CODE (t
), TS_TYPED
))
5697 fld_worklist_push (TREE_TYPE (t
), fld
);
5703 /* Find decls and types in T. */
5706 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
5710 if (!fld
->pset
->contains (t
))
5711 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
5712 if (fld
->worklist
.is_empty ())
5714 t
= fld
->worklist
.pop ();
5718 /* Translate all the types in LIST with the corresponding runtime
5722 get_eh_types_for_runtime (tree list
)
5726 if (list
== NULL_TREE
)
5729 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5731 list
= TREE_CHAIN (list
);
5734 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5735 TREE_CHAIN (prev
) = n
;
5736 prev
= TREE_CHAIN (prev
);
5737 list
= TREE_CHAIN (list
);
5744 /* Find decls and types referenced in EH region R and store them in
5745 FLD->DECLS and FLD->TYPES. */
5748 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
5759 /* The types referenced in each catch must first be changed to the
5760 EH types used at runtime. This removes references to FE types
5762 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
5764 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
5765 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
5770 case ERT_ALLOWED_EXCEPTIONS
:
5771 r
->u
.allowed
.type_list
5772 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
5773 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
5776 case ERT_MUST_NOT_THROW
:
5777 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
5778 find_decls_types_r
, fld
, fld
->pset
);
5784 /* Find decls and types referenced in cgraph node N and store them in
5785 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5786 look for *every* kind of DECL and TYPE node reachable from N,
5787 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5788 NAMESPACE_DECLs, etc). */
5791 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5794 struct function
*fn
;
5798 find_decls_types (n
->decl
, fld
);
5800 if (!gimple_has_body_p (n
->decl
))
5803 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5805 fn
= DECL_STRUCT_FUNCTION (n
->decl
);
5807 /* Traverse locals. */
5808 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5809 find_decls_types (t
, fld
);
5811 /* Traverse EH regions in FN. */
5814 FOR_ALL_EH_REGION_FN (r
, fn
)
5815 find_decls_types_in_eh_region (r
, fld
);
5818 /* Traverse every statement in FN. */
5819 FOR_EACH_BB_FN (bb
, fn
)
5822 gimple_stmt_iterator si
;
5825 for (psi
= gsi_start_phis (bb
); !gsi_end_p (psi
); gsi_next (&psi
))
5827 gphi
*phi
= psi
.phi ();
5829 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5831 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5832 find_decls_types (*arg_p
, fld
);
5836 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5838 gimple
*stmt
= gsi_stmt (si
);
5840 if (is_gimple_call (stmt
))
5841 find_decls_types (gimple_call_fntype (stmt
), fld
);
5843 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5845 tree arg
= gimple_op (stmt
, i
);
5846 find_decls_types (arg
, fld
);
5853 /* Find decls and types referenced in varpool node N and store them in
5854 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5855 look for *every* kind of DECL and TYPE node reachable from N,
5856 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5857 NAMESPACE_DECLs, etc). */
5860 find_decls_types_in_var (varpool_node
*v
, struct free_lang_data_d
*fld
)
5862 find_decls_types (v
->decl
, fld
);
5865 /* If T needs an assembler name, have one created for it. */
5868 assign_assembler_name_if_neeeded (tree t
)
5870 if (need_assembler_name_p (t
))
5872 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5873 diagnostics that use input_location to show locus
5874 information. The problem here is that, at this point,
5875 input_location is generally anchored to the end of the file
5876 (since the parser is long gone), so we don't have a good
5877 position to pin it to.
5879 To alleviate this problem, this uses the location of T's
5880 declaration. Examples of this are
5881 testsuite/g++.dg/template/cond2.C and
5882 testsuite/g++.dg/template/pr35240.C. */
5883 location_t saved_location
= input_location
;
5884 input_location
= DECL_SOURCE_LOCATION (t
);
5886 decl_assembler_name (t
);
5888 input_location
= saved_location
;
5893 /* Free language specific information for every operand and expression
5894 in every node of the call graph. This process operates in three stages:
5896 1- Every callgraph node and varpool node is traversed looking for
5897 decls and types embedded in them. This is a more exhaustive
5898 search than that done by find_referenced_vars, because it will
5899 also collect individual fields, decls embedded in types, etc.
5901 2- All the decls found are sent to free_lang_data_in_decl.
5903 3- All the types found are sent to free_lang_data_in_type.
5905 The ordering between decls and types is important because
5906 free_lang_data_in_decl sets assembler names, which includes
5907 mangling. So types cannot be freed up until assembler names have
5911 free_lang_data_in_cgraph (void)
5913 struct cgraph_node
*n
;
5915 struct free_lang_data_d fld
;
5920 /* Initialize sets and arrays to store referenced decls and types. */
5921 fld
.pset
= new hash_set
<tree
>;
5922 fld
.worklist
.create (0);
5923 fld
.decls
.create (100);
5924 fld
.types
.create (100);
5926 /* Find decls and types in the body of every function in the callgraph. */
5927 FOR_EACH_FUNCTION (n
)
5928 find_decls_types_in_node (n
, &fld
);
5930 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
5931 find_decls_types (p
->decl
, &fld
);
5933 /* Find decls and types in every varpool symbol. */
5934 FOR_EACH_VARIABLE (v
)
5935 find_decls_types_in_var (v
, &fld
);
5937 /* Set the assembler name on every decl found. We need to do this
5938 now because free_lang_data_in_decl will invalidate data needed
5939 for mangling. This breaks mangling on interdependent decls. */
5940 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5941 assign_assembler_name_if_neeeded (t
);
5943 /* Traverse every decl found freeing its language data. */
5944 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5945 free_lang_data_in_decl (t
);
5947 /* Traverse every type found freeing its language data. */
5948 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5949 free_lang_data_in_type (t
);
5952 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5957 fld
.worklist
.release ();
5958 fld
.decls
.release ();
5959 fld
.types
.release ();
5963 /* Free resources that are used by FE but are not needed once they are done. */
5966 free_lang_data (void)
5970 /* If we are the LTO frontend we have freed lang-specific data already. */
5972 || (!flag_generate_lto
&& !flag_generate_offload
))
5975 /* Allocate and assign alias sets to the standard integer types
5976 while the slots are still in the way the frontends generated them. */
5977 for (i
= 0; i
< itk_none
; ++i
)
5978 if (integer_types
[i
])
5979 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5981 /* Traverse the IL resetting language specific information for
5982 operands, expressions, etc. */
5983 free_lang_data_in_cgraph ();
5985 /* Create gimple variants for common types. */
5986 ptrdiff_type_node
= integer_type_node
;
5987 fileptr_type_node
= ptr_type_node
;
5989 /* Reset some langhooks. Do not reset types_compatible_p, it may
5990 still be used indirectly via the get_alias_set langhook. */
5991 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5992 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5993 lang_hooks
.gimplify_expr
= lhd_gimplify_expr
;
5995 /* We do not want the default decl_assembler_name implementation,
5996 rather if we have fixed everything we want a wrapper around it
5997 asserting that all non-local symbols already got their assembler
5998 name and only produce assembler names for local symbols. Or rather
5999 make sure we never call decl_assembler_name on local symbols and
6000 devise a separate, middle-end private scheme for it. */
6002 /* Reset diagnostic machinery. */
6003 tree_diagnostics_defaults (global_dc
);
6011 const pass_data pass_data_ipa_free_lang_data
=
6013 SIMPLE_IPA_PASS
, /* type */
6014 "*free_lang_data", /* name */
6015 OPTGROUP_NONE
, /* optinfo_flags */
6016 TV_IPA_FREE_LANG_DATA
, /* tv_id */
6017 0, /* properties_required */
6018 0, /* properties_provided */
6019 0, /* properties_destroyed */
6020 0, /* todo_flags_start */
6021 0, /* todo_flags_finish */
6024 class pass_ipa_free_lang_data
: public simple_ipa_opt_pass
6027 pass_ipa_free_lang_data (gcc::context
*ctxt
)
6028 : simple_ipa_opt_pass (pass_data_ipa_free_lang_data
, ctxt
)
6031 /* opt_pass methods: */
6032 virtual unsigned int execute (function
*) { return free_lang_data (); }
6034 }; // class pass_ipa_free_lang_data
6038 simple_ipa_opt_pass
*
6039 make_pass_ipa_free_lang_data (gcc::context
*ctxt
)
6041 return new pass_ipa_free_lang_data (ctxt
);
6044 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
6045 ATTR_NAME. Also used internally by remove_attribute(). */
6047 private_is_attribute_p (const char *attr_name
, size_t attr_len
, const_tree ident
)
6049 size_t ident_len
= IDENTIFIER_LENGTH (ident
);
6051 if (ident_len
== attr_len
)
6053 if (strcmp (attr_name
, IDENTIFIER_POINTER (ident
)) == 0)
6056 else if (ident_len
== attr_len
+ 4)
6058 /* There is the possibility that ATTR is 'text' and IDENT is
6060 const char *p
= IDENTIFIER_POINTER (ident
);
6061 if (p
[0] == '_' && p
[1] == '_'
6062 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
6063 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6070 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
6071 of ATTR_NAME, and LIST is not NULL_TREE. */
6073 private_lookup_attribute (const char *attr_name
, size_t attr_len
, tree list
)
6077 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
6079 if (ident_len
== attr_len
)
6081 if (!strcmp (attr_name
,
6082 IDENTIFIER_POINTER (get_attribute_name (list
))))
6085 /* TODO: If we made sure that attributes were stored in the
6086 canonical form without '__...__' (ie, as in 'text' as opposed
6087 to '__text__') then we could avoid the following case. */
6088 else if (ident_len
== attr_len
+ 4)
6090 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
6091 if (p
[0] == '_' && p
[1] == '_'
6092 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
6093 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6096 list
= TREE_CHAIN (list
);
6102 /* Given an attribute name ATTR_NAME and a list of attributes LIST,
6103 return a pointer to the attribute's list first element if the attribute
6104 starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
6108 private_lookup_attribute_by_prefix (const char *attr_name
, size_t attr_len
,
6113 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
6115 if (attr_len
> ident_len
)
6117 list
= TREE_CHAIN (list
);
6121 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
6123 if (strncmp (attr_name
, p
, attr_len
) == 0)
6126 /* TODO: If we made sure that attributes were stored in the
6127 canonical form without '__...__' (ie, as in 'text' as opposed
6128 to '__text__') then we could avoid the following case. */
6129 if (p
[0] == '_' && p
[1] == '_' &&
6130 strncmp (attr_name
, p
+ 2, attr_len
) == 0)
6133 list
= TREE_CHAIN (list
);
6140 /* A variant of lookup_attribute() that can be used with an identifier
6141 as the first argument, and where the identifier can be either
6142 'text' or '__text__'.
6144 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
6145 return a pointer to the attribute's list element if the attribute
6146 is part of the list, or NULL_TREE if not found. If the attribute
6147 appears more than once, this only returns the first occurrence; the
6148 TREE_CHAIN of the return value should be passed back in if further
6149 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
6150 can be in the form 'text' or '__text__'. */
6152 lookup_ident_attribute (tree attr_identifier
, tree list
)
6154 gcc_checking_assert (TREE_CODE (attr_identifier
) == IDENTIFIER_NODE
);
6158 gcc_checking_assert (TREE_CODE (get_attribute_name (list
))
6159 == IDENTIFIER_NODE
);
6161 if (cmp_attrib_identifiers (attr_identifier
,
6162 get_attribute_name (list
)))
6165 list
= TREE_CHAIN (list
);
6171 /* Remove any instances of attribute ATTR_NAME in LIST and return the
6175 remove_attribute (const char *attr_name
, tree list
)
6178 size_t attr_len
= strlen (attr_name
);
6180 gcc_checking_assert (attr_name
[0] != '_');
6182 for (p
= &list
; *p
; )
6185 /* TODO: If we were storing attributes in normalized form, here
6186 we could use a simple strcmp(). */
6187 if (private_is_attribute_p (attr_name
, attr_len
, get_attribute_name (l
)))
6188 *p
= TREE_CHAIN (l
);
6190 p
= &TREE_CHAIN (l
);
6196 /* Return an attribute list that is the union of a1 and a2. */
6199 merge_attributes (tree a1
, tree a2
)
6203 /* Either one unset? Take the set one. */
6205 if ((attributes
= a1
) == 0)
6208 /* One that completely contains the other? Take it. */
6210 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
6212 if (attribute_list_contained (a2
, a1
))
6216 /* Pick the longest list, and hang on the other list. */
6218 if (list_length (a1
) < list_length (a2
))
6219 attributes
= a2
, a2
= a1
;
6221 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
6224 for (a
= lookup_ident_attribute (get_attribute_name (a2
),
6226 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
6227 a
= lookup_ident_attribute (get_attribute_name (a2
),
6232 a1
= copy_node (a2
);
6233 TREE_CHAIN (a1
) = attributes
;
6242 /* Given types T1 and T2, merge their attributes and return
6246 merge_type_attributes (tree t1
, tree t2
)
6248 return merge_attributes (TYPE_ATTRIBUTES (t1
),
6249 TYPE_ATTRIBUTES (t2
));
6252 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
6256 merge_decl_attributes (tree olddecl
, tree newdecl
)
6258 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
6259 DECL_ATTRIBUTES (newdecl
));
6262 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
6264 /* Specialization of merge_decl_attributes for various Windows targets.
6266 This handles the following situation:
6268 __declspec (dllimport) int foo;
6271 The second instance of `foo' nullifies the dllimport. */
6274 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
6277 int delete_dllimport_p
= 1;
6279 /* What we need to do here is remove from `old' dllimport if it doesn't
6280 appear in `new'. dllimport behaves like extern: if a declaration is
6281 marked dllimport and a definition appears later, then the object
6282 is not dllimport'd. We also remove a `new' dllimport if the old list
6283 contains dllexport: dllexport always overrides dllimport, regardless
6284 of the order of declaration. */
6285 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
6286 delete_dllimport_p
= 0;
6287 else if (DECL_DLLIMPORT_P (new_tree
)
6288 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
6290 DECL_DLLIMPORT_P (new_tree
) = 0;
6291 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
6292 "dllimport ignored", new_tree
);
6294 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
6296 /* Warn about overriding a symbol that has already been used, e.g.:
6297 extern int __attribute__ ((dllimport)) foo;
6298 int* bar () {return &foo;}
6301 if (TREE_USED (old
))
6303 warning (0, "%q+D redeclared without dllimport attribute "
6304 "after being referenced with dll linkage", new_tree
);
6305 /* If we have used a variable's address with dllimport linkage,
6306 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
6307 decl may already have had TREE_CONSTANT computed.
6308 We still remove the attribute so that assembler code refers
6309 to '&foo rather than '_imp__foo'. */
6310 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
6311 DECL_DLLIMPORT_P (new_tree
) = 1;
6314 /* Let an inline definition silently override the external reference,
6315 but otherwise warn about attribute inconsistency. */
6316 else if (TREE_CODE (new_tree
) == VAR_DECL
6317 || !DECL_DECLARED_INLINE_P (new_tree
))
6318 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
6319 "previous dllimport ignored", new_tree
);
6322 delete_dllimport_p
= 0;
6324 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
6326 if (delete_dllimport_p
)
6327 a
= remove_attribute ("dllimport", a
);
6332 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
6333 struct attribute_spec.handler. */
6336 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
6342 /* These attributes may apply to structure and union types being created,
6343 but otherwise should pass to the declaration involved. */
6346 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
6347 | (int) ATTR_FLAG_ARRAY_NEXT
))
6349 *no_add_attrs
= true;
6350 return tree_cons (name
, args
, NULL_TREE
);
6352 if (TREE_CODE (node
) == RECORD_TYPE
6353 || TREE_CODE (node
) == UNION_TYPE
)
6355 node
= TYPE_NAME (node
);
6361 warning (OPT_Wattributes
, "%qE attribute ignored",
6363 *no_add_attrs
= true;
6368 if (TREE_CODE (node
) != FUNCTION_DECL
6369 && TREE_CODE (node
) != VAR_DECL
6370 && TREE_CODE (node
) != TYPE_DECL
)
6372 *no_add_attrs
= true;
6373 warning (OPT_Wattributes
, "%qE attribute ignored",
6378 if (TREE_CODE (node
) == TYPE_DECL
6379 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
6380 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
6382 *no_add_attrs
= true;
6383 warning (OPT_Wattributes
, "%qE attribute ignored",
6388 is_dllimport
= is_attribute_p ("dllimport", name
);
6390 /* Report error on dllimport ambiguities seen now before they cause
6394 /* Honor any target-specific overrides. */
6395 if (!targetm
.valid_dllimport_attribute_p (node
))
6396 *no_add_attrs
= true;
6398 else if (TREE_CODE (node
) == FUNCTION_DECL
6399 && DECL_DECLARED_INLINE_P (node
))
6401 warning (OPT_Wattributes
, "inline function %q+D declared as "
6402 " dllimport: attribute ignored", node
);
6403 *no_add_attrs
= true;
6405 /* Like MS, treat definition of dllimported variables and
6406 non-inlined functions on declaration as syntax errors. */
6407 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
6409 error ("function %q+D definition is marked dllimport", node
);
6410 *no_add_attrs
= true;
6413 else if (TREE_CODE (node
) == VAR_DECL
)
6415 if (DECL_INITIAL (node
))
6417 error ("variable %q+D definition is marked dllimport",
6419 *no_add_attrs
= true;
6422 /* `extern' needn't be specified with dllimport.
6423 Specify `extern' now and hope for the best. Sigh. */
6424 DECL_EXTERNAL (node
) = 1;
6425 /* Also, implicitly give dllimport'd variables declared within
6426 a function global scope, unless declared static. */
6427 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
6428 TREE_PUBLIC (node
) = 1;
6431 if (*no_add_attrs
== false)
6432 DECL_DLLIMPORT_P (node
) = 1;
6434 else if (TREE_CODE (node
) == FUNCTION_DECL
6435 && DECL_DECLARED_INLINE_P (node
)
6436 && flag_keep_inline_dllexport
)
6437 /* An exported function, even if inline, must be emitted. */
6438 DECL_EXTERNAL (node
) = 0;
6440 /* Report error if symbol is not accessible at global scope. */
6441 if (!TREE_PUBLIC (node
)
6442 && (TREE_CODE (node
) == VAR_DECL
6443 || TREE_CODE (node
) == FUNCTION_DECL
))
6445 error ("external linkage required for symbol %q+D because of "
6446 "%qE attribute", node
, name
);
6447 *no_add_attrs
= true;
6450 /* A dllexport'd entity must have default visibility so that other
6451 program units (shared libraries or the main executable) can see
6452 it. A dllimport'd entity must have default visibility so that
6453 the linker knows that undefined references within this program
6454 unit can be resolved by the dynamic linker. */
6457 if (DECL_VISIBILITY_SPECIFIED (node
)
6458 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
6459 error ("%qE implies default visibility, but %qD has already "
6460 "been declared with a different visibility",
6462 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
6463 DECL_VISIBILITY_SPECIFIED (node
) = 1;
6469 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
6471 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
6472 of the various TYPE_QUAL values. */
6475 set_type_quals (tree type
, int type_quals
)
6477 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
6478 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
6479 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
6480 TYPE_ATOMIC (type
) = (type_quals
& TYPE_QUAL_ATOMIC
) != 0;
6481 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
6484 /* Returns true iff unqualified CAND and BASE are equivalent. */
6487 check_base_type (const_tree cand
, const_tree base
)
6489 return (TYPE_NAME (cand
) == TYPE_NAME (base
)
6490 /* Apparently this is needed for Objective-C. */
6491 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6492 /* Check alignment. */
6493 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
6494 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6495 TYPE_ATTRIBUTES (base
)));
6498 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
6501 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
6503 return (TYPE_QUALS (cand
) == type_quals
6504 && check_base_type (cand
, base
));
6507 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
6510 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
6512 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
6513 && TYPE_NAME (cand
) == TYPE_NAME (base
)
6514 /* Apparently this is needed for Objective-C. */
6515 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6516 /* Check alignment. */
6517 && TYPE_ALIGN (cand
) == align
6518 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6519 TYPE_ATTRIBUTES (base
)));
6522 /* This function checks to see if TYPE matches the size one of the built-in
6523 atomic types, and returns that core atomic type. */
6526 find_atomic_core_type (tree type
)
6528 tree base_atomic_type
;
6530 /* Only handle complete types. */
6531 if (TYPE_SIZE (type
) == NULL_TREE
)
6534 HOST_WIDE_INT type_size
= tree_to_uhwi (TYPE_SIZE (type
));
6538 base_atomic_type
= atomicQI_type_node
;
6542 base_atomic_type
= atomicHI_type_node
;
6546 base_atomic_type
= atomicSI_type_node
;
6550 base_atomic_type
= atomicDI_type_node
;
6554 base_atomic_type
= atomicTI_type_node
;
6558 base_atomic_type
= NULL_TREE
;
6561 return base_atomic_type
;
6564 /* Return a version of the TYPE, qualified as indicated by the
6565 TYPE_QUALS, if one exists. If no qualified version exists yet,
6566 return NULL_TREE. */
6569 get_qualified_type (tree type
, int type_quals
)
6573 if (TYPE_QUALS (type
) == type_quals
)
6576 /* Search the chain of variants to see if there is already one there just
6577 like the one we need to have. If so, use that existing one. We must
6578 preserve the TYPE_NAME, since there is code that depends on this. */
6579 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6580 if (check_qualified_type (t
, type
, type_quals
))
6586 /* Like get_qualified_type, but creates the type if it does not
6587 exist. This function never returns NULL_TREE. */
6590 build_qualified_type (tree type
, int type_quals
)
6594 /* See if we already have the appropriate qualified variant. */
6595 t
= get_qualified_type (type
, type_quals
);
6597 /* If not, build it. */
6600 t
= build_variant_type_copy (type
);
6601 set_type_quals (t
, type_quals
);
6603 if (((type_quals
& TYPE_QUAL_ATOMIC
) == TYPE_QUAL_ATOMIC
))
6605 /* See if this object can map to a basic atomic type. */
6606 tree atomic_type
= find_atomic_core_type (type
);
6609 /* Ensure the alignment of this type is compatible with
6610 the required alignment of the atomic type. */
6611 if (TYPE_ALIGN (atomic_type
) > TYPE_ALIGN (t
))
6612 TYPE_ALIGN (t
) = TYPE_ALIGN (atomic_type
);
6616 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6617 /* Propagate structural equality. */
6618 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6619 else if (TYPE_CANONICAL (type
) != type
)
6620 /* Build the underlying canonical type, since it is different
6623 tree c
= build_qualified_type (TYPE_CANONICAL (type
), type_quals
);
6624 TYPE_CANONICAL (t
) = TYPE_CANONICAL (c
);
6627 /* T is its own canonical type. */
6628 TYPE_CANONICAL (t
) = t
;
6635 /* Create a variant of type T with alignment ALIGN. */
6638 build_aligned_type (tree type
, unsigned int align
)
6642 if (TYPE_PACKED (type
)
6643 || TYPE_ALIGN (type
) == align
)
6646 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6647 if (check_aligned_type (t
, type
, align
))
6650 t
= build_variant_type_copy (type
);
6651 TYPE_ALIGN (t
) = align
;
6656 /* Create a new distinct copy of TYPE. The new type is made its own
6657 MAIN_VARIANT. If TYPE requires structural equality checks, the
6658 resulting type requires structural equality checks; otherwise, its
6659 TYPE_CANONICAL points to itself. */
6662 build_distinct_type_copy (tree type
)
6664 tree t
= copy_node (type
);
6666 TYPE_POINTER_TO (t
) = 0;
6667 TYPE_REFERENCE_TO (t
) = 0;
6669 /* Set the canonical type either to a new equivalence class, or
6670 propagate the need for structural equality checks. */
6671 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6672 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6674 TYPE_CANONICAL (t
) = t
;
6676 /* Make it its own variant. */
6677 TYPE_MAIN_VARIANT (t
) = t
;
6678 TYPE_NEXT_VARIANT (t
) = 0;
6680 /* We do not record methods in type copies nor variants
6681 so we do not need to keep them up to date when new method
6683 if (RECORD_OR_UNION_TYPE_P (t
))
6684 TYPE_METHODS (t
) = NULL_TREE
;
6686 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6687 whose TREE_TYPE is not t. This can also happen in the Ada
6688 frontend when using subtypes. */
6693 /* Create a new variant of TYPE, equivalent but distinct. This is so
6694 the caller can modify it. TYPE_CANONICAL for the return type will
6695 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6696 are considered equal by the language itself (or that both types
6697 require structural equality checks). */
6700 build_variant_type_copy (tree type
)
6702 tree t
, m
= TYPE_MAIN_VARIANT (type
);
6704 t
= build_distinct_type_copy (type
);
6706 /* Since we're building a variant, assume that it is a non-semantic
6707 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6708 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
6710 /* Add the new type to the chain of variants of TYPE. */
6711 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
6712 TYPE_NEXT_VARIANT (m
) = t
;
6713 TYPE_MAIN_VARIANT (t
) = m
;
6718 /* Return true if the from tree in both tree maps are equal. */
6721 tree_map_base_eq (const void *va
, const void *vb
)
6723 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
6724 *const b
= (const struct tree_map_base
*) vb
;
6725 return (a
->from
== b
->from
);
6728 /* Hash a from tree in a tree_base_map. */
6731 tree_map_base_hash (const void *item
)
6733 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
6736 /* Return true if this tree map structure is marked for garbage collection
6737 purposes. We simply return true if the from tree is marked, so that this
6738 structure goes away when the from tree goes away. */
6741 tree_map_base_marked_p (const void *p
)
6743 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
6746 /* Hash a from tree in a tree_map. */
6749 tree_map_hash (const void *item
)
6751 return (((const struct tree_map
*) item
)->hash
);
6754 /* Hash a from tree in a tree_decl_map. */
6757 tree_decl_map_hash (const void *item
)
6759 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
6762 /* Return the initialization priority for DECL. */
6765 decl_init_priority_lookup (tree decl
)
6767 symtab_node
*snode
= symtab_node::get (decl
);
6770 return DEFAULT_INIT_PRIORITY
;
6772 snode
->get_init_priority ();
6775 /* Return the finalization priority for DECL. */
6778 decl_fini_priority_lookup (tree decl
)
6780 cgraph_node
*node
= cgraph_node::get (decl
);
6783 return DEFAULT_INIT_PRIORITY
;
6785 node
->get_fini_priority ();
6788 /* Set the initialization priority for DECL to PRIORITY. */
6791 decl_init_priority_insert (tree decl
, priority_type priority
)
6793 struct symtab_node
*snode
;
6795 if (priority
== DEFAULT_INIT_PRIORITY
)
6797 snode
= symtab_node::get (decl
);
6801 else if (TREE_CODE (decl
) == VAR_DECL
)
6802 snode
= varpool_node::get_create (decl
);
6804 snode
= cgraph_node::get_create (decl
);
6805 snode
->set_init_priority (priority
);
6808 /* Set the finalization priority for DECL to PRIORITY. */
6811 decl_fini_priority_insert (tree decl
, priority_type priority
)
6813 struct cgraph_node
*node
;
6815 if (priority
== DEFAULT_INIT_PRIORITY
)
6817 node
= cgraph_node::get (decl
);
6822 node
= cgraph_node::get_create (decl
);
6823 node
->set_fini_priority (priority
);
6826 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6829 print_debug_expr_statistics (void)
6831 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6832 (long) debug_expr_for_decl
->size (),
6833 (long) debug_expr_for_decl
->elements (),
6834 debug_expr_for_decl
->collisions ());
6837 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6840 print_value_expr_statistics (void)
6842 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6843 (long) value_expr_for_decl
->size (),
6844 (long) value_expr_for_decl
->elements (),
6845 value_expr_for_decl
->collisions ());
6848 /* Lookup a debug expression for FROM, and return it if we find one. */
6851 decl_debug_expr_lookup (tree from
)
6853 struct tree_decl_map
*h
, in
;
6854 in
.base
.from
= from
;
6856 h
= debug_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6862 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6865 decl_debug_expr_insert (tree from
, tree to
)
6867 struct tree_decl_map
*h
;
6869 h
= ggc_alloc
<tree_decl_map
> ();
6870 h
->base
.from
= from
;
6872 *debug_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
6875 /* Lookup a value expression for FROM, and return it if we find one. */
6878 decl_value_expr_lookup (tree from
)
6880 struct tree_decl_map
*h
, in
;
6881 in
.base
.from
= from
;
6883 h
= value_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6889 /* Insert a mapping FROM->TO in the value expression hashtable. */
6892 decl_value_expr_insert (tree from
, tree to
)
6894 struct tree_decl_map
*h
;
6896 h
= ggc_alloc
<tree_decl_map
> ();
6897 h
->base
.from
= from
;
6899 *value_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
6902 /* Lookup a vector of debug arguments for FROM, and return it if we
6906 decl_debug_args_lookup (tree from
)
6908 struct tree_vec_map
*h
, in
;
6910 if (!DECL_HAS_DEBUG_ARGS_P (from
))
6912 gcc_checking_assert (debug_args_for_decl
!= NULL
);
6913 in
.base
.from
= from
;
6914 h
= debug_args_for_decl
->find_with_hash (&in
, DECL_UID (from
));
6920 /* Insert a mapping FROM->empty vector of debug arguments in the value
6921 expression hashtable. */
6924 decl_debug_args_insert (tree from
)
6926 struct tree_vec_map
*h
;
6929 if (DECL_HAS_DEBUG_ARGS_P (from
))
6930 return decl_debug_args_lookup (from
);
6931 if (debug_args_for_decl
== NULL
)
6932 debug_args_for_decl
= hash_table
<tree_vec_map_cache_hasher
>::create_ggc (64);
6933 h
= ggc_alloc
<tree_vec_map
> ();
6934 h
->base
.from
= from
;
6936 loc
= debug_args_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
);
6938 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
6942 /* Hashing of types so that we don't make duplicates.
6943 The entry point is `type_hash_canon'. */
6945 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6946 with types in the TREE_VALUE slots), by adding the hash codes
6947 of the individual types. */
6950 type_hash_list (const_tree list
, inchash::hash
&hstate
)
6954 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6955 if (TREE_VALUE (tail
) != error_mark_node
)
6956 hstate
.add_object (TYPE_HASH (TREE_VALUE (tail
)));
6959 /* These are the Hashtable callback functions. */
6961 /* Returns true iff the types are equivalent. */
6964 type_cache_hasher::equal (type_hash
*a
, type_hash
*b
)
6966 /* First test the things that are the same for all types. */
6967 if (a
->hash
!= b
->hash
6968 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6969 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6970 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6971 TYPE_ATTRIBUTES (b
->type
))
6972 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6973 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6976 /* Be careful about comparing arrays before and after the element type
6977 has been completed; don't compare TYPE_ALIGN unless both types are
6979 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6980 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6981 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6984 switch (TREE_CODE (a
->type
))
6989 case REFERENCE_TYPE
:
6994 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6997 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6998 && !(TYPE_VALUES (a
->type
)
6999 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
7000 && TYPE_VALUES (b
->type
)
7001 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
7002 && type_list_equal (TYPE_VALUES (a
->type
),
7003 TYPE_VALUES (b
->type
))))
7006 /* ... fall through ... */
7011 if (TYPE_PRECISION (a
->type
) != TYPE_PRECISION (b
->type
))
7013 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
7014 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
7015 TYPE_MAX_VALUE (b
->type
)))
7016 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
7017 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
7018 TYPE_MIN_VALUE (b
->type
))));
7020 case FIXED_POINT_TYPE
:
7021 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
7024 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
7027 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
7028 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
7029 || (TYPE_ARG_TYPES (a
->type
)
7030 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
7031 && TYPE_ARG_TYPES (b
->type
)
7032 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
7033 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
7034 TYPE_ARG_TYPES (b
->type
)))))
7038 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
7042 case QUAL_UNION_TYPE
:
7043 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
7044 || (TYPE_FIELDS (a
->type
)
7045 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
7046 && TYPE_FIELDS (b
->type
)
7047 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
7048 && type_list_equal (TYPE_FIELDS (a
->type
),
7049 TYPE_FIELDS (b
->type
))));
7052 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
7053 || (TYPE_ARG_TYPES (a
->type
)
7054 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
7055 && TYPE_ARG_TYPES (b
->type
)
7056 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
7057 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
7058 TYPE_ARG_TYPES (b
->type
))))
7066 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
7067 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
7072 /* Given TYPE, and HASHCODE its hash code, return the canonical
7073 object for an identical type if one already exists.
7074 Otherwise, return TYPE, and record it as the canonical object.
7076 To use this function, first create a type of the sort you want.
7077 Then compute its hash code from the fields of the type that
7078 make it different from other similar types.
7079 Then call this function and use the value. */
7082 type_hash_canon (unsigned int hashcode
, tree type
)
7087 /* The hash table only contains main variants, so ensure that's what we're
7089 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
7091 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
7092 must call that routine before comparing TYPE_ALIGNs. */
7098 loc
= type_hash_table
->find_slot_with_hash (&in
, hashcode
, INSERT
);
7101 tree t1
= ((type_hash
*) *loc
)->type
;
7102 gcc_assert (TYPE_MAIN_VARIANT (t1
) == t1
);
7103 if (GATHER_STATISTICS
)
7105 tree_code_counts
[(int) TREE_CODE (type
)]--;
7106 tree_node_counts
[(int) t_kind
]--;
7107 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type_non_common
);
7113 struct type_hash
*h
;
7115 h
= ggc_alloc
<type_hash
> ();
7125 print_type_hash_statistics (void)
7127 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
7128 (long) type_hash_table
->size (),
7129 (long) type_hash_table
->elements (),
7130 type_hash_table
->collisions ());
7133 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
7134 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
7135 by adding the hash codes of the individual attributes. */
7138 attribute_hash_list (const_tree list
, inchash::hash
&hstate
)
7142 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
7143 /* ??? Do we want to add in TREE_VALUE too? */
7144 hstate
.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (tail
)));
7147 /* Given two lists of attributes, return true if list l2 is
7148 equivalent to l1. */
7151 attribute_list_equal (const_tree l1
, const_tree l2
)
7156 return attribute_list_contained (l1
, l2
)
7157 && attribute_list_contained (l2
, l1
);
7160 /* Given two lists of attributes, return true if list L2 is
7161 completely contained within L1. */
7162 /* ??? This would be faster if attribute names were stored in a canonicalized
7163 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
7164 must be used to show these elements are equivalent (which they are). */
7165 /* ??? It's not clear that attributes with arguments will always be handled
7169 attribute_list_contained (const_tree l1
, const_tree l2
)
7173 /* First check the obvious, maybe the lists are identical. */
7177 /* Maybe the lists are similar. */
7178 for (t1
= l1
, t2
= l2
;
7180 && get_attribute_name (t1
) == get_attribute_name (t2
)
7181 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
7182 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
7185 /* Maybe the lists are equal. */
7186 if (t1
== 0 && t2
== 0)
7189 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
7192 /* This CONST_CAST is okay because lookup_attribute does not
7193 modify its argument and the return value is assigned to a
7195 for (attr
= lookup_ident_attribute (get_attribute_name (t2
),
7196 CONST_CAST_TREE (l1
));
7197 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
7198 attr
= lookup_ident_attribute (get_attribute_name (t2
),
7202 if (attr
== NULL_TREE
)
7209 /* Given two lists of types
7210 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
7211 return 1 if the lists contain the same types in the same order.
7212 Also, the TREE_PURPOSEs must match. */
7215 type_list_equal (const_tree l1
, const_tree l2
)
7219 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
7220 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
7221 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
7222 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
7223 && (TREE_TYPE (TREE_PURPOSE (t1
))
7224 == TREE_TYPE (TREE_PURPOSE (t2
))))))
7230 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
7231 given by TYPE. If the argument list accepts variable arguments,
7232 then this function counts only the ordinary arguments. */
7235 type_num_arguments (const_tree type
)
7240 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
7241 /* If the function does not take a variable number of arguments,
7242 the last element in the list will have type `void'. */
7243 if (VOID_TYPE_P (TREE_VALUE (t
)))
7251 /* Nonzero if integer constants T1 and T2
7252 represent the same constant value. */
7255 tree_int_cst_equal (const_tree t1
, const_tree t2
)
7260 if (t1
== 0 || t2
== 0)
7263 if (TREE_CODE (t1
) == INTEGER_CST
7264 && TREE_CODE (t2
) == INTEGER_CST
7265 && wi::to_widest (t1
) == wi::to_widest (t2
))
7271 /* Return true if T is an INTEGER_CST whose numerical value (extended
7272 according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
7275 tree_fits_shwi_p (const_tree t
)
7277 return (t
!= NULL_TREE
7278 && TREE_CODE (t
) == INTEGER_CST
7279 && wi::fits_shwi_p (wi::to_widest (t
)));
7282 /* Return true if T is an INTEGER_CST whose numerical value (extended
7283 according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
7286 tree_fits_uhwi_p (const_tree t
)
7288 return (t
!= NULL_TREE
7289 && TREE_CODE (t
) == INTEGER_CST
7290 && wi::fits_uhwi_p (wi::to_widest (t
)));
7293 /* T is an INTEGER_CST whose numerical value (extended according to
7294 TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
7298 tree_to_shwi (const_tree t
)
7300 gcc_assert (tree_fits_shwi_p (t
));
7301 return TREE_INT_CST_LOW (t
);
7304 /* T is an INTEGER_CST whose numerical value (extended according to
7305 TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
7308 unsigned HOST_WIDE_INT
7309 tree_to_uhwi (const_tree t
)
7311 gcc_assert (tree_fits_uhwi_p (t
));
7312 return TREE_INT_CST_LOW (t
);
7315 /* Return the most significant (sign) bit of T. */
7318 tree_int_cst_sign_bit (const_tree t
)
7320 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
7322 return wi::extract_uhwi (t
, bitno
, 1);
7325 /* Return an indication of the sign of the integer constant T.
7326 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
7327 Note that -1 will never be returned if T's type is unsigned. */
7330 tree_int_cst_sgn (const_tree t
)
7332 if (wi::eq_p (t
, 0))
7334 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
7336 else if (wi::neg_p (t
))
7342 /* Return the minimum number of bits needed to represent VALUE in a
7343 signed or unsigned type, UNSIGNEDP says which. */
7346 tree_int_cst_min_precision (tree value
, signop sgn
)
7348 /* If the value is negative, compute its negative minus 1. The latter
7349 adjustment is because the absolute value of the largest negative value
7350 is one larger than the largest positive value. This is equivalent to
7351 a bit-wise negation, so use that operation instead. */
7353 if (tree_int_cst_sgn (value
) < 0)
7354 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
7356 /* Return the number of bits needed, taking into account the fact
7357 that we need one more bit for a signed than unsigned type.
7358 If value is 0 or -1, the minimum precision is 1 no matter
7359 whether unsignedp is true or false. */
7361 if (integer_zerop (value
))
7364 return tree_floor_log2 (value
) + 1 + (sgn
== SIGNED
? 1 : 0) ;
7367 /* Return truthvalue of whether T1 is the same tree structure as T2.
7368 Return 1 if they are the same.
7369 Return 0 if they are understandably different.
7370 Return -1 if either contains tree structure not understood by
7374 simple_cst_equal (const_tree t1
, const_tree t2
)
7376 enum tree_code code1
, code2
;
7382 if (t1
== 0 || t2
== 0)
7385 code1
= TREE_CODE (t1
);
7386 code2
= TREE_CODE (t2
);
7388 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
7390 if (CONVERT_EXPR_CODE_P (code2
)
7391 || code2
== NON_LVALUE_EXPR
)
7392 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7394 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
7397 else if (CONVERT_EXPR_CODE_P (code2
)
7398 || code2
== NON_LVALUE_EXPR
)
7399 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
7407 return wi::to_widest (t1
) == wi::to_widest (t2
);
7410 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
7413 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
7416 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
7417 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
7418 TREE_STRING_LENGTH (t1
)));
7422 unsigned HOST_WIDE_INT idx
;
7423 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
7424 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
7426 if (vec_safe_length (v1
) != vec_safe_length (v2
))
7429 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
7430 /* ??? Should we handle also fields here? */
7431 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
7437 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7440 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
7443 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
7446 const_tree arg1
, arg2
;
7447 const_call_expr_arg_iterator iter1
, iter2
;
7448 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
7449 arg2
= first_const_call_expr_arg (t2
, &iter2
);
7451 arg1
= next_const_call_expr_arg (&iter1
),
7452 arg2
= next_const_call_expr_arg (&iter2
))
7454 cmp
= simple_cst_equal (arg1
, arg2
);
7458 return arg1
== arg2
;
7462 /* Special case: if either target is an unallocated VAR_DECL,
7463 it means that it's going to be unified with whatever the
7464 TARGET_EXPR is really supposed to initialize, so treat it
7465 as being equivalent to anything. */
7466 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
7467 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
7468 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
7469 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
7470 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
7471 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
7474 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7479 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
7481 case WITH_CLEANUP_EXPR
:
7482 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7486 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
7489 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
7490 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7504 /* This general rule works for most tree codes. All exceptions should be
7505 handled above. If this is a language-specific tree code, we can't
7506 trust what might be in the operand, so say we don't know
7508 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
7511 switch (TREE_CODE_CLASS (code1
))
7515 case tcc_comparison
:
7516 case tcc_expression
:
7520 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
7522 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
7534 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7535 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7536 than U, respectively. */
7539 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
7541 if (tree_int_cst_sgn (t
) < 0)
7543 else if (!tree_fits_uhwi_p (t
))
7545 else if (TREE_INT_CST_LOW (t
) == u
)
7547 else if (TREE_INT_CST_LOW (t
) < u
)
7553 /* Return true if SIZE represents a constant size that is in bounds of
7554 what the middle-end and the backend accepts (covering not more than
7555 half of the address-space). */
7558 valid_constant_size_p (const_tree size
)
7560 if (! tree_fits_uhwi_p (size
)
7561 || TREE_OVERFLOW (size
)
7562 || tree_int_cst_sign_bit (size
) != 0)
7567 /* Return the precision of the type, or for a complex or vector type the
7568 precision of the type of its elements. */
7571 element_precision (const_tree type
)
7574 type
= TREE_TYPE (type
);
7575 enum tree_code code
= TREE_CODE (type
);
7576 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7577 type
= TREE_TYPE (type
);
7579 return TYPE_PRECISION (type
);
7582 /* Return true if CODE represents an associative tree code. Otherwise
7585 associative_tree_code (enum tree_code code
)
7604 /* Return true if CODE represents a commutative tree code. Otherwise
7607 commutative_tree_code (enum tree_code code
)
7613 case MULT_HIGHPART_EXPR
:
7621 case UNORDERED_EXPR
:
7625 case TRUTH_AND_EXPR
:
7626 case TRUTH_XOR_EXPR
:
7628 case WIDEN_MULT_EXPR
:
7629 case VEC_WIDEN_MULT_HI_EXPR
:
7630 case VEC_WIDEN_MULT_LO_EXPR
:
7631 case VEC_WIDEN_MULT_EVEN_EXPR
:
7632 case VEC_WIDEN_MULT_ODD_EXPR
:
7641 /* Return true if CODE represents a ternary tree code for which the
7642 first two operands are commutative. Otherwise return false. */
7644 commutative_ternary_tree_code (enum tree_code code
)
7648 case WIDEN_MULT_PLUS_EXPR
:
7649 case WIDEN_MULT_MINUS_EXPR
:
7660 /* Returns true if CODE can overflow. */
7663 operation_can_overflow (enum tree_code code
)
7671 /* Can overflow in various ways. */
7673 case TRUNC_DIV_EXPR
:
7674 case EXACT_DIV_EXPR
:
7675 case FLOOR_DIV_EXPR
:
7677 /* For INT_MIN / -1. */
7684 /* These operators cannot overflow. */
7689 /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7690 ftrapv doesn't generate trapping insns for CODE. */
7693 operation_no_trapping_overflow (tree type
, enum tree_code code
)
7695 gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type
));
7697 /* We don't generate instructions that trap on overflow for complex or vector
7699 if (!INTEGRAL_TYPE_P (type
))
7702 if (!TYPE_OVERFLOW_TRAPS (type
))
7712 /* These operators can overflow, and -ftrapv generates trapping code for
7715 case TRUNC_DIV_EXPR
:
7716 case EXACT_DIV_EXPR
:
7717 case FLOOR_DIV_EXPR
:
7720 /* These operators can overflow, but -ftrapv does not generate trapping
7724 /* These operators cannot overflow. */
7732 /* Generate a hash value for an expression. This can be used iteratively
7733 by passing a previous result as the HSTATE argument.
7735 This function is intended to produce the same hash for expressions which
7736 would compare equal using operand_equal_p. */
7738 add_expr (const_tree t
, inchash::hash
&hstate
)
7741 enum tree_code code
;
7742 enum tree_code_class tclass
;
7746 hstate
.merge_hash (0);
7750 code
= TREE_CODE (t
);
7754 /* Alas, constants aren't shared, so we can't rely on pointer
7757 hstate
.merge_hash (0);
7760 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
7761 hstate
.add_wide_int (TREE_INT_CST_ELT (t
, i
));
7765 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
7766 hstate
.merge_hash (val2
);
7771 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
7772 hstate
.merge_hash (val2
);
7776 hstate
.add ((const void *) TREE_STRING_POINTER (t
), TREE_STRING_LENGTH (t
));
7779 inchash::add_expr (TREE_REALPART (t
), hstate
);
7780 inchash::add_expr (TREE_IMAGPART (t
), hstate
);
7785 for (i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
7786 inchash::add_expr (VECTOR_CST_ELT (t
, i
), hstate
);
7790 /* We can just compare by pointer. */
7791 hstate
.add_wide_int (SSA_NAME_VERSION (t
));
7793 case PLACEHOLDER_EXPR
:
7794 /* The node itself doesn't matter. */
7797 /* A list of expressions, for a CALL_EXPR or as the elements of a
7799 for (; t
; t
= TREE_CHAIN (t
))
7800 inchash::add_expr (TREE_VALUE (t
), hstate
);
7804 unsigned HOST_WIDE_INT idx
;
7806 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
7808 inchash::add_expr (field
, hstate
);
7809 inchash::add_expr (value
, hstate
);
7814 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7815 Otherwise nodes that compare equal according to operand_equal_p might
7816 get different hash codes. However, don't do this for machine specific
7817 or front end builtins, since the function code is overloaded in those
7819 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
7820 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t
)))
7822 t
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
7823 code
= TREE_CODE (t
);
7827 tclass
= TREE_CODE_CLASS (code
);
7829 if (tclass
== tcc_declaration
)
7831 /* DECL's have a unique ID */
7832 hstate
.add_wide_int (DECL_UID (t
));
7836 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
7838 hstate
.add_object (code
);
7840 /* Don't hash the type, that can lead to having nodes which
7841 compare equal according to operand_equal_p, but which
7842 have different hash codes. */
7843 if (CONVERT_EXPR_CODE_P (code
)
7844 || code
== NON_LVALUE_EXPR
)
7846 /* Make sure to include signness in the hash computation. */
7847 hstate
.add_int (TYPE_UNSIGNED (TREE_TYPE (t
)));
7848 inchash::add_expr (TREE_OPERAND (t
, 0), hstate
);
7851 else if (commutative_tree_code (code
))
7853 /* It's a commutative expression. We want to hash it the same
7854 however it appears. We do this by first hashing both operands
7855 and then rehashing based on the order of their independent
7857 inchash::hash one
, two
;
7858 inchash::add_expr (TREE_OPERAND (t
, 0), one
);
7859 inchash::add_expr (TREE_OPERAND (t
, 1), two
);
7860 hstate
.add_commutative (one
, two
);
7863 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
7864 inchash::add_expr (TREE_OPERAND (t
, i
), hstate
);
7872 /* Constructors for pointer, array and function types.
7873 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7874 constructed by language-dependent code, not here.) */
7876 /* Construct, lay out and return the type of pointers to TO_TYPE with
7877 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7878 reference all of memory. If such a type has already been
7879 constructed, reuse it. */
7882 build_pointer_type_for_mode (tree to_type
, machine_mode mode
,
7886 bool could_alias
= can_alias_all
;
7888 if (to_type
== error_mark_node
)
7889 return error_mark_node
;
7891 /* If the pointed-to type has the may_alias attribute set, force
7892 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7893 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7894 can_alias_all
= true;
7896 /* In some cases, languages will have things that aren't a POINTER_TYPE
7897 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7898 In that case, return that type without regard to the rest of our
7901 ??? This is a kludge, but consistent with the way this function has
7902 always operated and there doesn't seem to be a good way to avoid this
7904 if (TYPE_POINTER_TO (to_type
) != 0
7905 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7906 return TYPE_POINTER_TO (to_type
);
7908 /* First, if we already have a type for pointers to TO_TYPE and it's
7909 the proper mode, use it. */
7910 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7911 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7914 t
= make_node (POINTER_TYPE
);
7916 TREE_TYPE (t
) = to_type
;
7917 SET_TYPE_MODE (t
, mode
);
7918 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7919 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7920 TYPE_POINTER_TO (to_type
) = t
;
7922 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7923 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7924 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
7926 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7929 /* Lay out the type. This function has many callers that are concerned
7930 with expression-construction, and this simplifies them all. */
7936 /* By default build pointers in ptr_mode. */
7939 build_pointer_type (tree to_type
)
7941 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7942 : TYPE_ADDR_SPACE (to_type
);
7943 machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7944 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7947 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7950 build_reference_type_for_mode (tree to_type
, machine_mode mode
,
7954 bool could_alias
= can_alias_all
;
7956 if (to_type
== error_mark_node
)
7957 return error_mark_node
;
7959 /* If the pointed-to type has the may_alias attribute set, force
7960 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7961 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7962 can_alias_all
= true;
7964 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7965 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7966 In that case, return that type without regard to the rest of our
7969 ??? This is a kludge, but consistent with the way this function has
7970 always operated and there doesn't seem to be a good way to avoid this
7972 if (TYPE_REFERENCE_TO (to_type
) != 0
7973 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7974 return TYPE_REFERENCE_TO (to_type
);
7976 /* First, if we already have a type for pointers to TO_TYPE and it's
7977 the proper mode, use it. */
7978 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7979 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7982 t
= make_node (REFERENCE_TYPE
);
7984 TREE_TYPE (t
) = to_type
;
7985 SET_TYPE_MODE (t
, mode
);
7986 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7987 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7988 TYPE_REFERENCE_TO (to_type
) = t
;
7990 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7991 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7992 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
7994 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
8003 /* Build the node for the type of references-to-TO_TYPE by default
8007 build_reference_type (tree to_type
)
8009 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
8010 : TYPE_ADDR_SPACE (to_type
);
8011 machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
8012 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
8015 #define MAX_INT_CACHED_PREC \
8016 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
8017 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
8019 /* Builds a signed or unsigned integer type of precision PRECISION.
8020 Used for C bitfields whose precision does not match that of
8021 built-in target types. */
8023 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
8029 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
8031 if (precision
<= MAX_INT_CACHED_PREC
)
8033 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
8038 itype
= make_node (INTEGER_TYPE
);
8039 TYPE_PRECISION (itype
) = precision
;
8042 fixup_unsigned_type (itype
);
8044 fixup_signed_type (itype
);
8047 if (tree_fits_uhwi_p (TYPE_MAX_VALUE (itype
)))
8048 ret
= type_hash_canon (tree_to_uhwi (TYPE_MAX_VALUE (itype
)), itype
);
8049 if (precision
<= MAX_INT_CACHED_PREC
)
8050 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
8055 #define MAX_BOOL_CACHED_PREC \
8056 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
8057 static GTY(()) tree nonstandard_boolean_type_cache
[MAX_BOOL_CACHED_PREC
+ 1];
8059 /* Builds a boolean type of precision PRECISION.
8060 Used for boolean vectors to choose proper vector element size. */
8062 build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision
)
8066 if (precision
<= MAX_BOOL_CACHED_PREC
)
8068 type
= nonstandard_boolean_type_cache
[precision
];
8073 type
= make_node (BOOLEAN_TYPE
);
8074 TYPE_PRECISION (type
) = precision
;
8075 fixup_signed_type (type
);
8077 if (precision
<= MAX_INT_CACHED_PREC
)
8078 nonstandard_boolean_type_cache
[precision
] = type
;
8083 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
8084 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
8085 is true, reuse such a type that has already been constructed. */
8088 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
8090 tree itype
= make_node (INTEGER_TYPE
);
8091 inchash::hash hstate
;
8093 TREE_TYPE (itype
) = type
;
8095 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
8096 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
8098 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
8099 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
8100 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
8101 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
8102 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
8103 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
8108 if ((TYPE_MIN_VALUE (itype
)
8109 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
8110 || (TYPE_MAX_VALUE (itype
)
8111 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
8113 /* Since we cannot reliably merge this type, we need to compare it using
8114 structural equality checks. */
8115 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
8119 inchash::add_expr (TYPE_MIN_VALUE (itype
), hstate
);
8120 inchash::add_expr (TYPE_MAX_VALUE (itype
), hstate
);
8121 hstate
.merge_hash (TYPE_HASH (type
));
8122 itype
= type_hash_canon (hstate
.end (), itype
);
8127 /* Wrapper around build_range_type_1 with SHARED set to true. */
8130 build_range_type (tree type
, tree lowval
, tree highval
)
8132 return build_range_type_1 (type
, lowval
, highval
, true);
8135 /* Wrapper around build_range_type_1 with SHARED set to false. */
8138 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
8140 return build_range_type_1 (type
, lowval
, highval
, false);
8143 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
8144 MAXVAL should be the maximum value in the domain
8145 (one less than the length of the array).
8147 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
8148 We don't enforce this limit, that is up to caller (e.g. language front end).
8149 The limit exists because the result is a signed type and we don't handle
8150 sizes that use more than one HOST_WIDE_INT. */
8153 build_index_type (tree maxval
)
8155 return build_range_type (sizetype
, size_zero_node
, maxval
);
8158 /* Return true if the debug information for TYPE, a subtype, should be emitted
8159 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
8160 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
8161 debug info and doesn't reflect the source code. */
8164 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
8166 tree base_type
= TREE_TYPE (type
), low
, high
;
8168 /* Subrange types have a base type which is an integral type. */
8169 if (!INTEGRAL_TYPE_P (base_type
))
8172 /* Get the real bounds of the subtype. */
8173 if (lang_hooks
.types
.get_subrange_bounds
)
8174 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
8177 low
= TYPE_MIN_VALUE (type
);
8178 high
= TYPE_MAX_VALUE (type
);
8181 /* If the type and its base type have the same representation and the same
8182 name, then the type is not a subrange but a copy of the base type. */
8183 if ((TREE_CODE (base_type
) == INTEGER_TYPE
8184 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
8185 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
8186 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
8187 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
))
8188 && TYPE_IDENTIFIER (type
) == TYPE_IDENTIFIER (base_type
))
8198 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
8199 and number of elements specified by the range of values of INDEX_TYPE.
8200 If SHARED is true, reuse such a type that has already been constructed. */
8203 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
8207 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
8209 error ("arrays of functions are not meaningful");
8210 elt_type
= integer_type_node
;
8213 t
= make_node (ARRAY_TYPE
);
8214 TREE_TYPE (t
) = elt_type
;
8215 TYPE_DOMAIN (t
) = index_type
;
8216 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
8219 /* If the element type is incomplete at this point we get marked for
8220 structural equality. Do not record these types in the canonical
8222 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
8227 inchash::hash hstate
;
8228 hstate
.add_object (TYPE_HASH (elt_type
));
8230 hstate
.add_object (TYPE_HASH (index_type
));
8231 t
= type_hash_canon (hstate
.end (), t
);
8234 if (TYPE_CANONICAL (t
) == t
)
8236 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
8237 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
8238 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8239 else if (TYPE_CANONICAL (elt_type
) != elt_type
8240 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
8242 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
8244 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
8251 /* Wrapper around build_array_type_1 with SHARED set to true. */
8254 build_array_type (tree elt_type
, tree index_type
)
8256 return build_array_type_1 (elt_type
, index_type
, true);
8259 /* Wrapper around build_array_type_1 with SHARED set to false. */
8262 build_nonshared_array_type (tree elt_type
, tree index_type
)
8264 return build_array_type_1 (elt_type
, index_type
, false);
8267 /* Return a representation of ELT_TYPE[NELTS], using indices of type
8271 build_array_type_nelts (tree elt_type
, unsigned HOST_WIDE_INT nelts
)
8273 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
8276 /* Recursively examines the array elements of TYPE, until a non-array
8277 element type is found. */
8280 strip_array_types (tree type
)
8282 while (TREE_CODE (type
) == ARRAY_TYPE
)
8283 type
= TREE_TYPE (type
);
8288 /* Computes the canonical argument types from the argument type list
8291 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
8292 on entry to this function, or if any of the ARGTYPES are
8295 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
8296 true on entry to this function, or if any of the ARGTYPES are
8299 Returns a canonical argument list, which may be ARGTYPES when the
8300 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
8301 true) or would not differ from ARGTYPES. */
8304 maybe_canonicalize_argtypes (tree argtypes
,
8305 bool *any_structural_p
,
8306 bool *any_noncanonical_p
)
8309 bool any_noncanonical_argtypes_p
= false;
8311 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
8313 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
8314 /* Fail gracefully by stating that the type is structural. */
8315 *any_structural_p
= true;
8316 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
8317 *any_structural_p
= true;
8318 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
8319 || TREE_PURPOSE (arg
))
8320 /* If the argument has a default argument, we consider it
8321 non-canonical even though the type itself is canonical.
8322 That way, different variants of function and method types
8323 with default arguments will all point to the variant with
8324 no defaults as their canonical type. */
8325 any_noncanonical_argtypes_p
= true;
8328 if (*any_structural_p
)
8331 if (any_noncanonical_argtypes_p
)
8333 /* Build the canonical list of argument types. */
8334 tree canon_argtypes
= NULL_TREE
;
8335 bool is_void
= false;
8337 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
8339 if (arg
== void_list_node
)
8342 canon_argtypes
= tree_cons (NULL_TREE
,
8343 TYPE_CANONICAL (TREE_VALUE (arg
)),
8347 canon_argtypes
= nreverse (canon_argtypes
);
8349 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
8351 /* There is a non-canonical type. */
8352 *any_noncanonical_p
= true;
8353 return canon_argtypes
;
8356 /* The canonical argument types are the same as ARGTYPES. */
8360 /* Construct, lay out and return
8361 the type of functions returning type VALUE_TYPE
8362 given arguments of types ARG_TYPES.
8363 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
8364 are data type nodes for the arguments of the function.
8365 If such a type has already been constructed, reuse it. */
8368 build_function_type (tree value_type
, tree arg_types
)
8371 inchash::hash hstate
;
8372 bool any_structural_p
, any_noncanonical_p
;
8373 tree canon_argtypes
;
8375 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
8377 error ("function return type cannot be function");
8378 value_type
= integer_type_node
;
8381 /* Make a node of the sort we want. */
8382 t
= make_node (FUNCTION_TYPE
);
8383 TREE_TYPE (t
) = value_type
;
8384 TYPE_ARG_TYPES (t
) = arg_types
;
8386 /* If we already have such a type, use the old one. */
8387 hstate
.add_object (TYPE_HASH (value_type
));
8388 type_hash_list (arg_types
, hstate
);
8389 t
= type_hash_canon (hstate
.end (), t
);
8391 /* Set up the canonical type. */
8392 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
8393 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
8394 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
8396 &any_noncanonical_p
);
8397 if (any_structural_p
)
8398 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8399 else if (any_noncanonical_p
)
8400 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
8403 if (!COMPLETE_TYPE_P (t
))
8408 /* Build a function type. The RETURN_TYPE is the type returned by the
8409 function. If VAARGS is set, no void_type_node is appended to the
8410 the list. ARGP must be always be terminated be a NULL_TREE. */
8413 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
8417 t
= va_arg (argp
, tree
);
8418 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
8419 args
= tree_cons (NULL_TREE
, t
, args
);
8424 if (args
!= NULL_TREE
)
8425 args
= nreverse (args
);
8426 gcc_assert (last
!= void_list_node
);
8428 else if (args
== NULL_TREE
)
8429 args
= void_list_node
;
8433 args
= nreverse (args
);
8434 TREE_CHAIN (last
) = void_list_node
;
8436 args
= build_function_type (return_type
, args
);
8441 /* Build a function type. The RETURN_TYPE is the type returned by the
8442 function. If additional arguments are provided, they are
8443 additional argument types. The list of argument types must always
8444 be terminated by NULL_TREE. */
8447 build_function_type_list (tree return_type
, ...)
8452 va_start (p
, return_type
);
8453 args
= build_function_type_list_1 (false, return_type
, p
);
8458 /* Build a variable argument function type. The RETURN_TYPE is the
8459 type returned by the function. If additional arguments are provided,
8460 they are additional argument types. The list of argument types must
8461 always be terminated by NULL_TREE. */
8464 build_varargs_function_type_list (tree return_type
, ...)
8469 va_start (p
, return_type
);
8470 args
= build_function_type_list_1 (true, return_type
, p
);
8476 /* Build a function type. RETURN_TYPE is the type returned by the
8477 function; VAARGS indicates whether the function takes varargs. The
8478 function takes N named arguments, the types of which are provided in
8482 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
8486 tree t
= vaargs
? NULL_TREE
: void_list_node
;
8488 for (i
= n
- 1; i
>= 0; i
--)
8489 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
8491 return build_function_type (return_type
, t
);
8494 /* Build a function type. RETURN_TYPE is the type returned by the
8495 function. The function takes N named arguments, the types of which
8496 are provided in ARG_TYPES. */
8499 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8501 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
8504 /* Build a variable argument function type. RETURN_TYPE is the type
8505 returned by the function. The function takes N named arguments, the
8506 types of which are provided in ARG_TYPES. */
8509 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8511 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
8514 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8515 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8516 for the method. An implicit additional parameter (of type
8517 pointer-to-BASETYPE) is added to the ARGTYPES. */
8520 build_method_type_directly (tree basetype
,
8526 inchash::hash hstate
;
8527 bool any_structural_p
, any_noncanonical_p
;
8528 tree canon_argtypes
;
8530 /* Make a node of the sort we want. */
8531 t
= make_node (METHOD_TYPE
);
8533 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8534 TREE_TYPE (t
) = rettype
;
8535 ptype
= build_pointer_type (basetype
);
8537 /* The actual arglist for this function includes a "hidden" argument
8538 which is "this". Put it into the list of argument types. */
8539 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
8540 TYPE_ARG_TYPES (t
) = argtypes
;
8542 /* If we already have such a type, use the old one. */
8543 hstate
.add_object (TYPE_HASH (basetype
));
8544 hstate
.add_object (TYPE_HASH (rettype
));
8545 type_hash_list (argtypes
, hstate
);
8546 t
= type_hash_canon (hstate
.end (), t
);
8548 /* Set up the canonical type. */
8550 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8551 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
8553 = (TYPE_CANONICAL (basetype
) != basetype
8554 || TYPE_CANONICAL (rettype
) != rettype
);
8555 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
8557 &any_noncanonical_p
);
8558 if (any_structural_p
)
8559 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8560 else if (any_noncanonical_p
)
8562 = build_method_type_directly (TYPE_CANONICAL (basetype
),
8563 TYPE_CANONICAL (rettype
),
8565 if (!COMPLETE_TYPE_P (t
))
8571 /* Construct, lay out and return the type of methods belonging to class
8572 BASETYPE and whose arguments and values are described by TYPE.
8573 If that type exists already, reuse it.
8574 TYPE must be a FUNCTION_TYPE node. */
8577 build_method_type (tree basetype
, tree type
)
8579 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
8581 return build_method_type_directly (basetype
,
8583 TYPE_ARG_TYPES (type
));
8586 /* Construct, lay out and return the type of offsets to a value
8587 of type TYPE, within an object of type BASETYPE.
8588 If a suitable offset type exists already, reuse it. */
8591 build_offset_type (tree basetype
, tree type
)
8594 inchash::hash hstate
;
8596 /* Make a node of the sort we want. */
8597 t
= make_node (OFFSET_TYPE
);
8599 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8600 TREE_TYPE (t
) = type
;
8602 /* If we already have such a type, use the old one. */
8603 hstate
.add_object (TYPE_HASH (basetype
));
8604 hstate
.add_object (TYPE_HASH (type
));
8605 t
= type_hash_canon (hstate
.end (), t
);
8607 if (!COMPLETE_TYPE_P (t
))
8610 if (TYPE_CANONICAL (t
) == t
)
8612 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8613 || TYPE_STRUCTURAL_EQUALITY_P (type
))
8614 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8615 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
8616 || TYPE_CANONICAL (type
) != type
)
8618 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
8619 TYPE_CANONICAL (type
));
8625 /* Create a complex type whose components are COMPONENT_TYPE. */
8628 build_complex_type (tree component_type
)
8631 inchash::hash hstate
;
8633 gcc_assert (INTEGRAL_TYPE_P (component_type
)
8634 || SCALAR_FLOAT_TYPE_P (component_type
)
8635 || FIXED_POINT_TYPE_P (component_type
));
8637 /* Make a node of the sort we want. */
8638 t
= make_node (COMPLEX_TYPE
);
8640 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
8642 /* If we already have such a type, use the old one. */
8643 hstate
.add_object (TYPE_HASH (component_type
));
8644 t
= type_hash_canon (hstate
.end (), t
);
8646 if (!COMPLETE_TYPE_P (t
))
8649 if (TYPE_CANONICAL (t
) == t
)
8651 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
8652 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8653 else if (TYPE_CANONICAL (component_type
) != component_type
)
8655 = build_complex_type (TYPE_CANONICAL (component_type
));
8658 /* We need to create a name, since complex is a fundamental type. */
8659 if (! TYPE_NAME (t
))
8662 if (component_type
== char_type_node
)
8663 name
= "complex char";
8664 else if (component_type
== signed_char_type_node
)
8665 name
= "complex signed char";
8666 else if (component_type
== unsigned_char_type_node
)
8667 name
= "complex unsigned char";
8668 else if (component_type
== short_integer_type_node
)
8669 name
= "complex short int";
8670 else if (component_type
== short_unsigned_type_node
)
8671 name
= "complex short unsigned int";
8672 else if (component_type
== integer_type_node
)
8673 name
= "complex int";
8674 else if (component_type
== unsigned_type_node
)
8675 name
= "complex unsigned int";
8676 else if (component_type
== long_integer_type_node
)
8677 name
= "complex long int";
8678 else if (component_type
== long_unsigned_type_node
)
8679 name
= "complex long unsigned int";
8680 else if (component_type
== long_long_integer_type_node
)
8681 name
= "complex long long int";
8682 else if (component_type
== long_long_unsigned_type_node
)
8683 name
= "complex long long unsigned int";
8688 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
8689 get_identifier (name
), t
);
8692 return build_qualified_type (t
, TYPE_QUALS (component_type
));
8695 /* If TYPE is a real or complex floating-point type and the target
8696 does not directly support arithmetic on TYPE then return the wider
8697 type to be used for arithmetic on TYPE. Otherwise, return
8701 excess_precision_type (tree type
)
8703 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
8705 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
8706 switch (TREE_CODE (type
))
8709 switch (flt_eval_method
)
8712 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
8713 return double_type_node
;
8716 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
8717 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
8718 return long_double_type_node
;
8725 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
8727 switch (flt_eval_method
)
8730 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
8731 return complex_double_type_node
;
8734 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
8735 || (TYPE_MODE (TREE_TYPE (type
))
8736 == TYPE_MODE (double_type_node
)))
8737 return complex_long_double_type_node
;
8750 /* Return OP, stripped of any conversions to wider types as much as is safe.
8751 Converting the value back to OP's type makes a value equivalent to OP.
8753 If FOR_TYPE is nonzero, we return a value which, if converted to
8754 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8756 OP must have integer, real or enumeral type. Pointers are not allowed!
8758 There are some cases where the obvious value we could return
8759 would regenerate to OP if converted to OP's type,
8760 but would not extend like OP to wider types.
8761 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8762 For example, if OP is (unsigned short)(signed char)-1,
8763 we avoid returning (signed char)-1 if FOR_TYPE is int,
8764 even though extending that to an unsigned short would regenerate OP,
8765 since the result of extending (signed char)-1 to (int)
8766 is different from (int) OP. */
8769 get_unwidened (tree op
, tree for_type
)
8771 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8772 tree type
= TREE_TYPE (op
);
8774 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
8776 = (for_type
!= 0 && for_type
!= type
8777 && final_prec
> TYPE_PRECISION (type
)
8778 && TYPE_UNSIGNED (type
));
8781 while (CONVERT_EXPR_P (op
))
8785 /* TYPE_PRECISION on vector types has different meaning
8786 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8787 so avoid them here. */
8788 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
8791 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
8792 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
8794 /* Truncations are many-one so cannot be removed.
8795 Unless we are later going to truncate down even farther. */
8797 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
8800 /* See what's inside this conversion. If we decide to strip it,
8802 op
= TREE_OPERAND (op
, 0);
8804 /* If we have not stripped any zero-extensions (uns is 0),
8805 we can strip any kind of extension.
8806 If we have previously stripped a zero-extension,
8807 only zero-extensions can safely be stripped.
8808 Any extension can be stripped if the bits it would produce
8809 are all going to be discarded later by truncating to FOR_TYPE. */
8813 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
8815 /* TYPE_UNSIGNED says whether this is a zero-extension.
8816 Let's avoid computing it if it does not affect WIN
8817 and if UNS will not be needed again. */
8819 || CONVERT_EXPR_P (op
))
8820 && TYPE_UNSIGNED (TREE_TYPE (op
)))
8828 /* If we finally reach a constant see if it fits in for_type and
8829 in that case convert it. */
8831 && TREE_CODE (win
) == INTEGER_CST
8832 && TREE_TYPE (win
) != for_type
8833 && int_fits_type_p (win
, for_type
))
8834 win
= fold_convert (for_type
, win
);
8839 /* Return OP or a simpler expression for a narrower value
8840 which can be sign-extended or zero-extended to give back OP.
8841 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8842 or 0 if the value should be sign-extended. */
8845 get_narrower (tree op
, int *unsignedp_ptr
)
8850 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8852 while (TREE_CODE (op
) == NOP_EXPR
)
8855 = (TYPE_PRECISION (TREE_TYPE (op
))
8856 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8858 /* Truncations are many-one so cannot be removed. */
8862 /* See what's inside this conversion. If we decide to strip it,
8867 op
= TREE_OPERAND (op
, 0);
8868 /* An extension: the outermost one can be stripped,
8869 but remember whether it is zero or sign extension. */
8871 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8872 /* Otherwise, if a sign extension has been stripped,
8873 only sign extensions can now be stripped;
8874 if a zero extension has been stripped, only zero-extensions. */
8875 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8879 else /* bitschange == 0 */
8881 /* A change in nominal type can always be stripped, but we must
8882 preserve the unsignedness. */
8884 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8886 op
= TREE_OPERAND (op
, 0);
8887 /* Keep trying to narrow, but don't assign op to win if it
8888 would turn an integral type into something else. */
8889 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8896 if (TREE_CODE (op
) == COMPONENT_REF
8897 /* Since type_for_size always gives an integer type. */
8898 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8899 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8900 /* Ensure field is laid out already. */
8901 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8902 && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op
, 1))))
8904 unsigned HOST_WIDE_INT innerprec
8905 = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op
, 1)));
8906 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8907 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8908 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8910 /* We can get this structure field in a narrower type that fits it,
8911 but the resulting extension to its nominal type (a fullword type)
8912 must satisfy the same conditions as for other extensions.
8914 Do this only for fields that are aligned (not bit-fields),
8915 because when bit-field insns will be used there is no
8916 advantage in doing this. */
8918 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8919 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8920 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8924 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8925 win
= fold_convert (type
, op
);
8929 *unsignedp_ptr
= uns
;
8933 /* Returns true if integer constant C has a value that is permissible
8934 for type TYPE (an INTEGER_TYPE). */
8937 int_fits_type_p (const_tree c
, const_tree type
)
8939 tree type_low_bound
, type_high_bound
;
8940 bool ok_for_low_bound
, ok_for_high_bound
;
8941 signop sgn_c
= TYPE_SIGN (TREE_TYPE (c
));
8944 type_low_bound
= TYPE_MIN_VALUE (type
);
8945 type_high_bound
= TYPE_MAX_VALUE (type
);
8947 /* If at least one bound of the type is a constant integer, we can check
8948 ourselves and maybe make a decision. If no such decision is possible, but
8949 this type is a subtype, try checking against that. Otherwise, use
8950 fits_to_tree_p, which checks against the precision.
8952 Compute the status for each possibly constant bound, and return if we see
8953 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8954 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8955 for "constant known to fit". */
8957 /* Check if c >= type_low_bound. */
8958 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8960 if (tree_int_cst_lt (c
, type_low_bound
))
8962 ok_for_low_bound
= true;
8965 ok_for_low_bound
= false;
8967 /* Check if c <= type_high_bound. */
8968 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8970 if (tree_int_cst_lt (type_high_bound
, c
))
8972 ok_for_high_bound
= true;
8975 ok_for_high_bound
= false;
8977 /* If the constant fits both bounds, the result is known. */
8978 if (ok_for_low_bound
&& ok_for_high_bound
)
8981 /* Perform some generic filtering which may allow making a decision
8982 even if the bounds are not constant. First, negative integers
8983 never fit in unsigned types, */
8984 if (TYPE_UNSIGNED (type
) && sgn_c
== SIGNED
&& wi::neg_p (c
))
8987 /* Second, narrower types always fit in wider ones. */
8988 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8991 /* Third, unsigned integers with top bit set never fit signed types. */
8992 if (!TYPE_UNSIGNED (type
) && sgn_c
== UNSIGNED
)
8994 int prec
= GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (c
))) - 1;
8995 if (prec
< TYPE_PRECISION (TREE_TYPE (c
)))
8997 /* When a tree_cst is converted to a wide-int, the precision
8998 is taken from the type. However, if the precision of the
8999 mode underneath the type is smaller than that, it is
9000 possible that the value will not fit. The test below
9001 fails if any bit is set between the sign bit of the
9002 underlying mode and the top bit of the type. */
9003 if (wi::ne_p (wi::zext (c
, prec
- 1), c
))
9006 else if (wi::neg_p (c
))
9010 /* If we haven't been able to decide at this point, there nothing more we
9011 can check ourselves here. Look at the base type if we have one and it
9012 has the same precision. */
9013 if (TREE_CODE (type
) == INTEGER_TYPE
9014 && TREE_TYPE (type
) != 0
9015 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
9017 type
= TREE_TYPE (type
);
9021 /* Or to fits_to_tree_p, if nothing else. */
9022 return wi::fits_to_tree_p (c
, type
);
9025 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
9026 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
9027 represented (assuming two's-complement arithmetic) within the bit
9028 precision of the type are returned instead. */
9031 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
9033 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
9034 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
9035 wi::to_mpz (TYPE_MIN_VALUE (type
), min
, TYPE_SIGN (type
));
9038 if (TYPE_UNSIGNED (type
))
9039 mpz_set_ui (min
, 0);
9042 wide_int mn
= wi::min_value (TYPE_PRECISION (type
), SIGNED
);
9043 wi::to_mpz (mn
, min
, SIGNED
);
9047 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
9048 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
9049 wi::to_mpz (TYPE_MAX_VALUE (type
), max
, TYPE_SIGN (type
));
9052 wide_int mn
= wi::max_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
9053 wi::to_mpz (mn
, max
, TYPE_SIGN (type
));
9057 /* Return true if VAR is an automatic variable defined in function FN. */
9060 auto_var_in_fn_p (const_tree var
, const_tree fn
)
9062 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
9063 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
9064 || TREE_CODE (var
) == PARM_DECL
)
9065 && ! TREE_STATIC (var
))
9066 || TREE_CODE (var
) == LABEL_DECL
9067 || TREE_CODE (var
) == RESULT_DECL
));
9070 /* Subprogram of following function. Called by walk_tree.
9072 Return *TP if it is an automatic variable or parameter of the
9073 function passed in as DATA. */
9076 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
9078 tree fn
= (tree
) data
;
9083 else if (DECL_P (*tp
)
9084 && auto_var_in_fn_p (*tp
, fn
))
9090 /* Returns true if T is, contains, or refers to a type with variable
9091 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
9092 arguments, but not the return type. If FN is nonzero, only return
9093 true if a modifier of the type or position of FN is a variable or
9094 parameter inside FN.
9096 This concept is more general than that of C99 'variably modified types':
9097 in C99, a struct type is never variably modified because a VLA may not
9098 appear as a structure member. However, in GNU C code like:
9100 struct S { int i[f()]; };
9102 is valid, and other languages may define similar constructs. */
9105 variably_modified_type_p (tree type
, tree fn
)
9109 /* Test if T is either variable (if FN is zero) or an expression containing
9110 a variable in FN. If TYPE isn't gimplified, return true also if
9111 gimplify_one_sizepos would gimplify the expression into a local
9113 #define RETURN_TRUE_IF_VAR(T) \
9114 do { tree _t = (T); \
9115 if (_t != NULL_TREE \
9116 && _t != error_mark_node \
9117 && TREE_CODE (_t) != INTEGER_CST \
9118 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
9120 || (!TYPE_SIZES_GIMPLIFIED (type) \
9121 && !is_gimple_sizepos (_t)) \
9122 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
9123 return true; } while (0)
9125 if (type
== error_mark_node
)
9128 /* If TYPE itself has variable size, it is variably modified. */
9129 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
9130 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
9132 switch (TREE_CODE (type
))
9135 case REFERENCE_TYPE
:
9137 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
9143 /* If TYPE is a function type, it is variably modified if the
9144 return type is variably modified. */
9145 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
9151 case FIXED_POINT_TYPE
:
9154 /* Scalar types are variably modified if their end points
9156 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
9157 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
9162 case QUAL_UNION_TYPE
:
9163 /* We can't see if any of the fields are variably-modified by the
9164 definition we normally use, since that would produce infinite
9165 recursion via pointers. */
9166 /* This is variably modified if some field's type is. */
9167 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
9168 if (TREE_CODE (t
) == FIELD_DECL
)
9170 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
9171 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
9172 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
9174 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
9175 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
9180 /* Do not call ourselves to avoid infinite recursion. This is
9181 variably modified if the element type is. */
9182 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
9183 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
9190 /* The current language may have other cases to check, but in general,
9191 all other types are not variably modified. */
9192 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
9194 #undef RETURN_TRUE_IF_VAR
9197 /* Given a DECL or TYPE, return the scope in which it was declared, or
9198 NULL_TREE if there is no containing scope. */
9201 get_containing_scope (const_tree t
)
9203 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
9206 /* Return the innermost context enclosing DECL that is
9207 a FUNCTION_DECL, or zero if none. */
9210 decl_function_context (const_tree decl
)
9214 if (TREE_CODE (decl
) == ERROR_MARK
)
9217 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
9218 where we look up the function at runtime. Such functions always take
9219 a first argument of type 'pointer to real context'.
9221 C++ should really be fixed to use DECL_CONTEXT for the real context,
9222 and use something else for the "virtual context". */
9223 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
9226 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
9228 context
= DECL_CONTEXT (decl
);
9230 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
9232 if (TREE_CODE (context
) == BLOCK
)
9233 context
= BLOCK_SUPERCONTEXT (context
);
9235 context
= get_containing_scope (context
);
9241 /* Return the innermost context enclosing DECL that is
9242 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
9243 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
9246 decl_type_context (const_tree decl
)
9248 tree context
= DECL_CONTEXT (decl
);
9251 switch (TREE_CODE (context
))
9253 case NAMESPACE_DECL
:
9254 case TRANSLATION_UNIT_DECL
:
9259 case QUAL_UNION_TYPE
:
9264 context
= DECL_CONTEXT (context
);
9268 context
= BLOCK_SUPERCONTEXT (context
);
9278 /* CALL is a CALL_EXPR. Return the declaration for the function
9279 called, or NULL_TREE if the called function cannot be
9283 get_callee_fndecl (const_tree call
)
9287 if (call
== error_mark_node
)
9288 return error_mark_node
;
9290 /* It's invalid to call this function with anything but a
9292 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
9294 /* The first operand to the CALL is the address of the function
9296 addr
= CALL_EXPR_FN (call
);
9298 /* If there is no function, return early. */
9299 if (addr
== NULL_TREE
)
9304 /* If this is a readonly function pointer, extract its initial value. */
9305 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
9306 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
9307 && DECL_INITIAL (addr
))
9308 addr
= DECL_INITIAL (addr
);
9310 /* If the address is just `&f' for some function `f', then we know
9311 that `f' is being called. */
9312 if (TREE_CODE (addr
) == ADDR_EXPR
9313 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
9314 return TREE_OPERAND (addr
, 0);
9316 /* We couldn't figure out what was being called. */
9320 #define TREE_MEM_USAGE_SPACES 40
9322 /* Print debugging information about tree nodes generated during the compile,
9323 and any language-specific information. */
9326 dump_tree_statistics (void)
9328 if (GATHER_STATISTICS
)
9331 int total_nodes
, total_bytes
;
9332 fprintf (stderr
, "\nKind Nodes Bytes\n");
9333 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9334 total_nodes
= total_bytes
= 0;
9335 for (i
= 0; i
< (int) all_kinds
; i
++)
9337 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
9338 tree_node_counts
[i
], tree_node_sizes
[i
]);
9339 total_nodes
+= tree_node_counts
[i
];
9340 total_bytes
+= tree_node_sizes
[i
];
9342 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9343 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
9344 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9345 fprintf (stderr
, "Code Nodes\n");
9346 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9347 for (i
= 0; i
< (int) MAX_TREE_CODES
; i
++)
9348 fprintf (stderr
, "%-32s %7d\n", get_tree_code_name ((enum tree_code
) i
),
9349 tree_code_counts
[i
]);
9350 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
9351 fprintf (stderr
, "\n");
9352 ssanames_print_statistics ();
9353 fprintf (stderr
, "\n");
9354 phinodes_print_statistics ();
9355 fprintf (stderr
, "\n");
9358 fprintf (stderr
, "(No per-node statistics)\n");
9360 print_type_hash_statistics ();
9361 print_debug_expr_statistics ();
9362 print_value_expr_statistics ();
9363 lang_hooks
.print_statistics ();
9366 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9368 /* Generate a crc32 of a byte. */
9371 crc32_unsigned_bits (unsigned chksum
, unsigned value
, unsigned bits
)
9375 for (ix
= bits
; ix
--; value
<<= 1)
9379 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
9386 /* Generate a crc32 of a 32-bit unsigned. */
9389 crc32_unsigned (unsigned chksum
, unsigned value
)
9391 return crc32_unsigned_bits (chksum
, value
, 32);
9394 /* Generate a crc32 of a byte. */
9397 crc32_byte (unsigned chksum
, char byte
)
9399 return crc32_unsigned_bits (chksum
, (unsigned) byte
<< 24, 8);
9402 /* Generate a crc32 of a string. */
9405 crc32_string (unsigned chksum
, const char *string
)
9409 chksum
= crc32_byte (chksum
, *string
);
9415 /* P is a string that will be used in a symbol. Mask out any characters
9416 that are not valid in that context. */
9419 clean_symbol_name (char *p
)
9423 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9426 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9433 /* For anonymous aggregate types, we need some sort of name to
9434 hold on to. In practice, this should not appear, but it should
9435 not be harmful if it does. */
9437 anon_aggrname_p(const_tree id_node
)
9439 #ifndef NO_DOT_IN_LABEL
9440 return (IDENTIFIER_POINTER (id_node
)[0] == '.'
9441 && IDENTIFIER_POINTER (id_node
)[1] == '_');
9442 #else /* NO_DOT_IN_LABEL */
9443 #ifndef NO_DOLLAR_IN_LABEL
9444 return (IDENTIFIER_POINTER (id_node
)[0] == '$' \
9445 && IDENTIFIER_POINTER (id_node
)[1] == '_');
9446 #else /* NO_DOLLAR_IN_LABEL */
9447 #define ANON_AGGRNAME_PREFIX "__anon_"
9448 return (!strncmp (IDENTIFIER_POINTER (id_node
), ANON_AGGRNAME_PREFIX
,
9449 sizeof (ANON_AGGRNAME_PREFIX
) - 1));
9450 #endif /* NO_DOLLAR_IN_LABEL */
9451 #endif /* NO_DOT_IN_LABEL */
9454 /* Return a format for an anonymous aggregate name. */
9456 anon_aggrname_format()
9458 #ifndef NO_DOT_IN_LABEL
9460 #else /* NO_DOT_IN_LABEL */
9461 #ifndef NO_DOLLAR_IN_LABEL
9463 #else /* NO_DOLLAR_IN_LABEL */
9465 #endif /* NO_DOLLAR_IN_LABEL */
9466 #endif /* NO_DOT_IN_LABEL */
9469 /* Generate a name for a special-purpose function.
9470 The generated name may need to be unique across the whole link.
9471 Changes to this function may also require corresponding changes to
9472 xstrdup_mask_random.
9473 TYPE is some string to identify the purpose of this function to the
9474 linker or collect2; it must start with an uppercase letter,
9476 I - for constructors
9478 N - for C++ anonymous namespaces
9479 F - for DWARF unwind frame information. */
9482 get_file_function_name (const char *type
)
9488 /* If we already have a name we know to be unique, just use that. */
9489 if (first_global_object_name
)
9490 p
= q
= ASTRDUP (first_global_object_name
);
9491 /* If the target is handling the constructors/destructors, they
9492 will be local to this file and the name is only necessary for
9494 We also assign sub_I and sub_D sufixes to constructors called from
9495 the global static constructors. These are always local. */
9496 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
9497 || (strncmp (type
, "sub_", 4) == 0
9498 && (type
[4] == 'I' || type
[4] == 'D')))
9500 const char *file
= main_input_filename
;
9502 file
= LOCATION_FILE (input_location
);
9503 /* Just use the file's basename, because the full pathname
9504 might be quite long. */
9505 p
= q
= ASTRDUP (lbasename (file
));
9509 /* Otherwise, the name must be unique across the entire link.
9510 We don't have anything that we know to be unique to this translation
9511 unit, so use what we do have and throw in some randomness. */
9513 const char *name
= weak_global_object_name
;
9514 const char *file
= main_input_filename
;
9519 file
= LOCATION_FILE (input_location
);
9521 len
= strlen (file
);
9522 q
= (char *) alloca (9 + 17 + len
+ 1);
9523 memcpy (q
, file
, len
+ 1);
9525 snprintf (q
+ len
, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
9526 crc32_string (0, name
), get_random_seed (false));
9531 clean_symbol_name (q
);
9532 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
9535 /* Set up the name of the file-level functions we may need.
9536 Use a global object (which is already required to be unique over
9537 the program) rather than the file name (which imposes extra
9539 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
9541 return get_identifier (buf
);
9544 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9546 /* Complain that the tree code of NODE does not match the expected 0
9547 terminated list of trailing codes. The trailing code list can be
9548 empty, for a more vague error message. FILE, LINE, and FUNCTION
9549 are of the caller. */
9552 tree_check_failed (const_tree node
, const char *file
,
9553 int line
, const char *function
, ...)
9557 unsigned length
= 0;
9558 enum tree_code code
;
9560 va_start (args
, function
);
9561 while ((code
= (enum tree_code
) va_arg (args
, int)))
9562 length
+= 4 + strlen (get_tree_code_name (code
));
9567 va_start (args
, function
);
9568 length
+= strlen ("expected ");
9569 buffer
= tmp
= (char *) alloca (length
);
9571 while ((code
= (enum tree_code
) va_arg (args
, int)))
9573 const char *prefix
= length
? " or " : "expected ";
9575 strcpy (tmp
+ length
, prefix
);
9576 length
+= strlen (prefix
);
9577 strcpy (tmp
+ length
, get_tree_code_name (code
));
9578 length
+= strlen (get_tree_code_name (code
));
9583 buffer
= "unexpected node";
9585 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9586 buffer
, get_tree_code_name (TREE_CODE (node
)),
9587 function
, trim_filename (file
), line
);
9590 /* Complain that the tree code of NODE does match the expected 0
9591 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9595 tree_not_check_failed (const_tree node
, const char *file
,
9596 int line
, const char *function
, ...)
9600 unsigned length
= 0;
9601 enum tree_code code
;
9603 va_start (args
, function
);
9604 while ((code
= (enum tree_code
) va_arg (args
, int)))
9605 length
+= 4 + strlen (get_tree_code_name (code
));
9607 va_start (args
, function
);
9608 buffer
= (char *) alloca (length
);
9610 while ((code
= (enum tree_code
) va_arg (args
, int)))
9614 strcpy (buffer
+ length
, " or ");
9617 strcpy (buffer
+ length
, get_tree_code_name (code
));
9618 length
+= strlen (get_tree_code_name (code
));
9622 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9623 buffer
, get_tree_code_name (TREE_CODE (node
)),
9624 function
, trim_filename (file
), line
);
9627 /* Similar to tree_check_failed, except that we check for a class of tree
9628 code, given in CL. */
9631 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9632 const char *file
, int line
, const char *function
)
9635 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9636 TREE_CODE_CLASS_STRING (cl
),
9637 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9638 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9641 /* Similar to tree_check_failed, except that instead of specifying a
9642 dozen codes, use the knowledge that they're all sequential. */
9645 tree_range_check_failed (const_tree node
, const char *file
, int line
,
9646 const char *function
, enum tree_code c1
,
9650 unsigned length
= 0;
9653 for (c
= c1
; c
<= c2
; ++c
)
9654 length
+= 4 + strlen (get_tree_code_name ((enum tree_code
) c
));
9656 length
+= strlen ("expected ");
9657 buffer
= (char *) alloca (length
);
9660 for (c
= c1
; c
<= c2
; ++c
)
9662 const char *prefix
= length
? " or " : "expected ";
9664 strcpy (buffer
+ length
, prefix
);
9665 length
+= strlen (prefix
);
9666 strcpy (buffer
+ length
, get_tree_code_name ((enum tree_code
) c
));
9667 length
+= strlen (get_tree_code_name ((enum tree_code
) c
));
9670 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9671 buffer
, get_tree_code_name (TREE_CODE (node
)),
9672 function
, trim_filename (file
), line
);
9676 /* Similar to tree_check_failed, except that we check that a tree does
9677 not have the specified code, given in CL. */
9680 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9681 const char *file
, int line
, const char *function
)
9684 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9685 TREE_CODE_CLASS_STRING (cl
),
9686 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9687 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9691 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9694 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
9695 const char *function
, enum omp_clause_code code
)
9697 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9698 omp_clause_code_name
[code
], get_tree_code_name (TREE_CODE (node
)),
9699 function
, trim_filename (file
), line
);
9703 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9706 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
9707 const char *function
, enum omp_clause_code c1
,
9708 enum omp_clause_code c2
)
9711 unsigned length
= 0;
9714 for (c
= c1
; c
<= c2
; ++c
)
9715 length
+= 4 + strlen (omp_clause_code_name
[c
]);
9717 length
+= strlen ("expected ");
9718 buffer
= (char *) alloca (length
);
9721 for (c
= c1
; c
<= c2
; ++c
)
9723 const char *prefix
= length
? " or " : "expected ";
9725 strcpy (buffer
+ length
, prefix
);
9726 length
+= strlen (prefix
);
9727 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
9728 length
+= strlen (omp_clause_code_name
[c
]);
9731 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9732 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
9733 function
, trim_filename (file
), line
);
9737 #undef DEFTREESTRUCT
9738 #define DEFTREESTRUCT(VAL, NAME) NAME,
9740 static const char *ts_enum_names
[] = {
9741 #include "treestruct.def"
9743 #undef DEFTREESTRUCT
9745 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9747 /* Similar to tree_class_check_failed, except that we check for
9748 whether CODE contains the tree structure identified by EN. */
9751 tree_contains_struct_check_failed (const_tree node
,
9752 const enum tree_node_structure_enum en
,
9753 const char *file
, int line
,
9754 const char *function
)
9757 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9759 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9763 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9764 (dynamically sized) vector. */
9767 tree_int_cst_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9768 const char *function
)
9771 ("tree check: accessed elt %d of tree_int_cst with %d elts in %s, at %s:%d",
9772 idx
+ 1, len
, function
, trim_filename (file
), line
);
9775 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9776 (dynamically sized) vector. */
9779 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9780 const char *function
)
9783 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9784 idx
+ 1, len
, function
, trim_filename (file
), line
);
9787 /* Similar to above, except that the check is for the bounds of the operand
9788 vector of an expression node EXP. */
9791 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
9792 int line
, const char *function
)
9794 enum tree_code code
= TREE_CODE (exp
);
9796 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9797 idx
+ 1, get_tree_code_name (code
), TREE_OPERAND_LENGTH (exp
),
9798 function
, trim_filename (file
), line
);
9801 /* Similar to above, except that the check is for the number of
9802 operands of an OMP_CLAUSE node. */
9805 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
9806 int line
, const char *function
)
9809 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9810 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
9811 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
9812 trim_filename (file
), line
);
9814 #endif /* ENABLE_TREE_CHECKING */
9816 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9817 and mapped to the machine mode MODE. Initialize its fields and build
9818 the information necessary for debugging output. */
9821 make_vector_type (tree innertype
, int nunits
, machine_mode mode
)
9824 inchash::hash hstate
;
9826 t
= make_node (VECTOR_TYPE
);
9827 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
9828 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
9829 SET_TYPE_MODE (t
, mode
);
9831 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
9832 SET_TYPE_STRUCTURAL_EQUALITY (t
);
9833 else if ((TYPE_CANONICAL (innertype
) != innertype
9834 || mode
!= VOIDmode
)
9835 && !VECTOR_BOOLEAN_TYPE_P (t
))
9837 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
9841 hstate
.add_wide_int (VECTOR_TYPE
);
9842 hstate
.add_wide_int (nunits
);
9843 hstate
.add_wide_int (mode
);
9844 hstate
.add_object (TYPE_HASH (TREE_TYPE (t
)));
9845 t
= type_hash_canon (hstate
.end (), t
);
9847 /* We have built a main variant, based on the main variant of the
9848 inner type. Use it to build the variant we return. */
9849 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
9850 && TREE_TYPE (t
) != innertype
)
9851 return build_type_attribute_qual_variant (t
,
9852 TYPE_ATTRIBUTES (innertype
),
9853 TYPE_QUALS (innertype
));
9859 make_or_reuse_type (unsigned size
, int unsignedp
)
9863 if (size
== INT_TYPE_SIZE
)
9864 return unsignedp
? unsigned_type_node
: integer_type_node
;
9865 if (size
== CHAR_TYPE_SIZE
)
9866 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
9867 if (size
== SHORT_TYPE_SIZE
)
9868 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
9869 if (size
== LONG_TYPE_SIZE
)
9870 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
9871 if (size
== LONG_LONG_TYPE_SIZE
)
9872 return (unsignedp
? long_long_unsigned_type_node
9873 : long_long_integer_type_node
);
9875 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9876 if (size
== int_n_data
[i
].bitsize
9877 && int_n_enabled_p
[i
])
9878 return (unsignedp
? int_n_trees
[i
].unsigned_type
9879 : int_n_trees
[i
].signed_type
);
9882 return make_unsigned_type (size
);
9884 return make_signed_type (size
);
9887 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9890 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
9894 if (size
== SHORT_FRACT_TYPE_SIZE
)
9895 return unsignedp
? sat_unsigned_short_fract_type_node
9896 : sat_short_fract_type_node
;
9897 if (size
== FRACT_TYPE_SIZE
)
9898 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9899 if (size
== LONG_FRACT_TYPE_SIZE
)
9900 return unsignedp
? sat_unsigned_long_fract_type_node
9901 : sat_long_fract_type_node
;
9902 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9903 return unsignedp
? sat_unsigned_long_long_fract_type_node
9904 : sat_long_long_fract_type_node
;
9908 if (size
== SHORT_FRACT_TYPE_SIZE
)
9909 return unsignedp
? unsigned_short_fract_type_node
9910 : short_fract_type_node
;
9911 if (size
== FRACT_TYPE_SIZE
)
9912 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9913 if (size
== LONG_FRACT_TYPE_SIZE
)
9914 return unsignedp
? unsigned_long_fract_type_node
9915 : long_fract_type_node
;
9916 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9917 return unsignedp
? unsigned_long_long_fract_type_node
9918 : long_long_fract_type_node
;
9921 return make_fract_type (size
, unsignedp
, satp
);
9924 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9927 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9931 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9932 return unsignedp
? sat_unsigned_short_accum_type_node
9933 : sat_short_accum_type_node
;
9934 if (size
== ACCUM_TYPE_SIZE
)
9935 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9936 if (size
== LONG_ACCUM_TYPE_SIZE
)
9937 return unsignedp
? sat_unsigned_long_accum_type_node
9938 : sat_long_accum_type_node
;
9939 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9940 return unsignedp
? sat_unsigned_long_long_accum_type_node
9941 : sat_long_long_accum_type_node
;
9945 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9946 return unsignedp
? unsigned_short_accum_type_node
9947 : short_accum_type_node
;
9948 if (size
== ACCUM_TYPE_SIZE
)
9949 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9950 if (size
== LONG_ACCUM_TYPE_SIZE
)
9951 return unsignedp
? unsigned_long_accum_type_node
9952 : long_accum_type_node
;
9953 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9954 return unsignedp
? unsigned_long_long_accum_type_node
9955 : long_long_accum_type_node
;
9958 return make_accum_type (size
, unsignedp
, satp
);
9962 /* Create an atomic variant node for TYPE. This routine is called
9963 during initialization of data types to create the 5 basic atomic
9964 types. The generic build_variant_type function requires these to
9965 already be set up in order to function properly, so cannot be
9966 called from there. If ALIGN is non-zero, then ensure alignment is
9967 overridden to this value. */
9970 build_atomic_base (tree type
, unsigned int align
)
9974 /* Make sure its not already registered. */
9975 if ((t
= get_qualified_type (type
, TYPE_QUAL_ATOMIC
)))
9978 t
= build_variant_type_copy (type
);
9979 set_type_quals (t
, TYPE_QUAL_ATOMIC
);
9982 TYPE_ALIGN (t
) = align
;
9987 /* Create nodes for all integer types (and error_mark_node) using the sizes
9988 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9989 SHORT_DOUBLE specifies whether double should be of the same precision
9993 build_common_tree_nodes (bool signed_char
, bool short_double
)
9997 error_mark_node
= make_node (ERROR_MARK
);
9998 TREE_TYPE (error_mark_node
) = error_mark_node
;
10000 initialize_sizetypes ();
10002 /* Define both `signed char' and `unsigned char'. */
10003 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
10004 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
10005 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
10006 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
10008 /* Define `char', which is like either `signed char' or `unsigned char'
10009 but not the same as either. */
10012 ? make_signed_type (CHAR_TYPE_SIZE
)
10013 : make_unsigned_type (CHAR_TYPE_SIZE
));
10014 TYPE_STRING_FLAG (char_type_node
) = 1;
10016 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
10017 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
10018 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
10019 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
10020 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
10021 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
10022 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
10023 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
10025 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
10027 int_n_trees
[i
].signed_type
= make_signed_type (int_n_data
[i
].bitsize
);
10028 int_n_trees
[i
].unsigned_type
= make_unsigned_type (int_n_data
[i
].bitsize
);
10029 TYPE_SIZE (int_n_trees
[i
].signed_type
) = bitsize_int (int_n_data
[i
].bitsize
);
10030 TYPE_SIZE (int_n_trees
[i
].unsigned_type
) = bitsize_int (int_n_data
[i
].bitsize
);
10032 if (int_n_data
[i
].bitsize
> LONG_LONG_TYPE_SIZE
10033 && int_n_enabled_p
[i
])
10035 integer_types
[itk_intN_0
+ i
* 2] = int_n_trees
[i
].signed_type
;
10036 integer_types
[itk_unsigned_intN_0
+ i
* 2] = int_n_trees
[i
].unsigned_type
;
10040 /* Define a boolean type. This type only represents boolean values but
10041 may be larger than char depending on the value of BOOL_TYPE_SIZE. */
10042 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
10043 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
10044 TYPE_PRECISION (boolean_type_node
) = 1;
10045 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
10047 /* Define what type to use for size_t. */
10048 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
10049 size_type_node
= unsigned_type_node
;
10050 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
10051 size_type_node
= long_unsigned_type_node
;
10052 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
10053 size_type_node
= long_long_unsigned_type_node
;
10054 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
10055 size_type_node
= short_unsigned_type_node
;
10060 size_type_node
= NULL_TREE
;
10061 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
10062 if (int_n_enabled_p
[i
])
10065 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
10067 if (strcmp (name
, SIZE_TYPE
) == 0)
10069 size_type_node
= int_n_trees
[i
].unsigned_type
;
10072 if (size_type_node
== NULL_TREE
)
10073 gcc_unreachable ();
10076 /* Fill in the rest of the sized types. Reuse existing type nodes
10078 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
10079 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
10080 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
10081 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
10082 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
10084 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
10085 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
10086 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
10087 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
10088 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
10090 /* Don't call build_qualified type for atomics. That routine does
10091 special processing for atomics, and until they are initialized
10092 it's better not to make that call.
10094 Check to see if there is a target override for atomic types. */
10096 atomicQI_type_node
= build_atomic_base (unsigned_intQI_type_node
,
10097 targetm
.atomic_align_for_mode (QImode
));
10098 atomicHI_type_node
= build_atomic_base (unsigned_intHI_type_node
,
10099 targetm
.atomic_align_for_mode (HImode
));
10100 atomicSI_type_node
= build_atomic_base (unsigned_intSI_type_node
,
10101 targetm
.atomic_align_for_mode (SImode
));
10102 atomicDI_type_node
= build_atomic_base (unsigned_intDI_type_node
,
10103 targetm
.atomic_align_for_mode (DImode
));
10104 atomicTI_type_node
= build_atomic_base (unsigned_intTI_type_node
,
10105 targetm
.atomic_align_for_mode (TImode
));
10107 access_public_node
= get_identifier ("public");
10108 access_protected_node
= get_identifier ("protected");
10109 access_private_node
= get_identifier ("private");
10111 /* Define these next since types below may used them. */
10112 integer_zero_node
= build_int_cst (integer_type_node
, 0);
10113 integer_one_node
= build_int_cst (integer_type_node
, 1);
10114 integer_three_node
= build_int_cst (integer_type_node
, 3);
10115 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
10117 size_zero_node
= size_int (0);
10118 size_one_node
= size_int (1);
10119 bitsize_zero_node
= bitsize_int (0);
10120 bitsize_one_node
= bitsize_int (1);
10121 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
10123 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
10124 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
10126 void_type_node
= make_node (VOID_TYPE
);
10127 layout_type (void_type_node
);
10129 pointer_bounds_type_node
= targetm
.chkp_bound_type ();
10131 /* We are not going to have real types in C with less than byte alignment,
10132 so we might as well not have any types that claim to have it. */
10133 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
10134 TYPE_USER_ALIGN (void_type_node
) = 0;
10136 void_node
= make_node (VOID_CST
);
10137 TREE_TYPE (void_node
) = void_type_node
;
10139 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
10140 layout_type (TREE_TYPE (null_pointer_node
));
10142 ptr_type_node
= build_pointer_type (void_type_node
);
10143 const_ptr_type_node
10144 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
10145 fileptr_type_node
= ptr_type_node
;
10147 pointer_sized_int_node
= build_nonstandard_integer_type (POINTER_SIZE
, 1);
10149 float_type_node
= make_node (REAL_TYPE
);
10150 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
10151 layout_type (float_type_node
);
10153 double_type_node
= make_node (REAL_TYPE
);
10155 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
10157 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
10158 layout_type (double_type_node
);
10160 long_double_type_node
= make_node (REAL_TYPE
);
10161 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
10162 layout_type (long_double_type_node
);
10164 float_ptr_type_node
= build_pointer_type (float_type_node
);
10165 double_ptr_type_node
= build_pointer_type (double_type_node
);
10166 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
10167 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
10169 /* Fixed size integer types. */
10170 uint16_type_node
= make_or_reuse_type (16, 1);
10171 uint32_type_node
= make_or_reuse_type (32, 1);
10172 uint64_type_node
= make_or_reuse_type (64, 1);
10174 /* Decimal float types. */
10175 dfloat32_type_node
= make_node (REAL_TYPE
);
10176 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
10177 layout_type (dfloat32_type_node
);
10178 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
10179 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
10181 dfloat64_type_node
= make_node (REAL_TYPE
);
10182 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
10183 layout_type (dfloat64_type_node
);
10184 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
10185 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
10187 dfloat128_type_node
= make_node (REAL_TYPE
);
10188 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
10189 layout_type (dfloat128_type_node
);
10190 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
10191 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
10193 complex_integer_type_node
= build_complex_type (integer_type_node
);
10194 complex_float_type_node
= build_complex_type (float_type_node
);
10195 complex_double_type_node
= build_complex_type (double_type_node
);
10196 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
10198 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
10199 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
10200 sat_ ## KIND ## _type_node = \
10201 make_sat_signed_ ## KIND ## _type (SIZE); \
10202 sat_unsigned_ ## KIND ## _type_node = \
10203 make_sat_unsigned_ ## KIND ## _type (SIZE); \
10204 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
10205 unsigned_ ## KIND ## _type_node = \
10206 make_unsigned_ ## KIND ## _type (SIZE);
10208 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
10209 sat_ ## WIDTH ## KIND ## _type_node = \
10210 make_sat_signed_ ## KIND ## _type (SIZE); \
10211 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
10212 make_sat_unsigned_ ## KIND ## _type (SIZE); \
10213 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
10214 unsigned_ ## WIDTH ## KIND ## _type_node = \
10215 make_unsigned_ ## KIND ## _type (SIZE);
10217 /* Make fixed-point type nodes based on four different widths. */
10218 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
10219 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
10220 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
10221 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
10222 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
10224 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
10225 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
10226 NAME ## _type_node = \
10227 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
10228 u ## NAME ## _type_node = \
10229 make_or_reuse_unsigned_ ## KIND ## _type \
10230 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
10231 sat_ ## NAME ## _type_node = \
10232 make_or_reuse_sat_signed_ ## KIND ## _type \
10233 (GET_MODE_BITSIZE (MODE ## mode)); \
10234 sat_u ## NAME ## _type_node = \
10235 make_or_reuse_sat_unsigned_ ## KIND ## _type \
10236 (GET_MODE_BITSIZE (U ## MODE ## mode));
10238 /* Fixed-point type and mode nodes. */
10239 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
10240 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
10241 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
10242 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
10243 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
10244 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
10245 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
10246 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
10247 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
10248 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
10249 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
10252 tree t
= targetm
.build_builtin_va_list ();
10254 /* Many back-ends define record types without setting TYPE_NAME.
10255 If we copied the record type here, we'd keep the original
10256 record type without a name. This breaks name mangling. So,
10257 don't copy record types and let c_common_nodes_and_builtins()
10258 declare the type to be __builtin_va_list. */
10259 if (TREE_CODE (t
) != RECORD_TYPE
)
10260 t
= build_variant_type_copy (t
);
10262 va_list_type_node
= t
;
10266 /* Modify DECL for given flags.
10267 TM_PURE attribute is set only on types, so the function will modify
10268 DECL's type when ECF_TM_PURE is used. */
10271 set_call_expr_flags (tree decl
, int flags
)
10273 if (flags
& ECF_NOTHROW
)
10274 TREE_NOTHROW (decl
) = 1;
10275 if (flags
& ECF_CONST
)
10276 TREE_READONLY (decl
) = 1;
10277 if (flags
& ECF_PURE
)
10278 DECL_PURE_P (decl
) = 1;
10279 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
10280 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
10281 if (flags
& ECF_NOVOPS
)
10282 DECL_IS_NOVOPS (decl
) = 1;
10283 if (flags
& ECF_NORETURN
)
10284 TREE_THIS_VOLATILE (decl
) = 1;
10285 if (flags
& ECF_MALLOC
)
10286 DECL_IS_MALLOC (decl
) = 1;
10287 if (flags
& ECF_RETURNS_TWICE
)
10288 DECL_IS_RETURNS_TWICE (decl
) = 1;
10289 if (flags
& ECF_LEAF
)
10290 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
10291 NULL
, DECL_ATTRIBUTES (decl
));
10292 if ((flags
& ECF_TM_PURE
) && flag_tm
)
10293 apply_tm_attr (decl
, get_identifier ("transaction_pure"));
10294 /* Looping const or pure is implied by noreturn.
10295 There is currently no way to declare looping const or looping pure alone. */
10296 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
10297 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
10301 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10304 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
10305 const char *library_name
, int ecf_flags
)
10309 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
10310 library_name
, NULL_TREE
);
10311 set_call_expr_flags (decl
, ecf_flags
);
10313 set_builtin_decl (code
, decl
, true);
10316 /* Call this function after instantiating all builtins that the language
10317 front end cares about. This will build the rest of the builtins
10318 and internal functions that are relied upon by the tree optimizers and
10322 build_common_builtin_nodes (void)
10327 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
10329 ftype
= build_function_type (void_type_node
, void_list_node
);
10330 local_define_builtin ("__builtin_unreachable", ftype
, BUILT_IN_UNREACHABLE
,
10331 "__builtin_unreachable",
10332 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
10336 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
10337 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
10339 ftype
= build_function_type_list (ptr_type_node
,
10340 ptr_type_node
, const_ptr_type_node
,
10341 size_type_node
, NULL_TREE
);
10343 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
10344 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
10345 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
10346 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
10347 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
10348 "memmove", ECF_NOTHROW
| ECF_LEAF
);
10351 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
10353 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
10354 const_ptr_type_node
, size_type_node
,
10356 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
10357 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10360 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
10362 ftype
= build_function_type_list (ptr_type_node
,
10363 ptr_type_node
, integer_type_node
,
10364 size_type_node
, NULL_TREE
);
10365 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
10366 "memset", ECF_NOTHROW
| ECF_LEAF
);
10369 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
10371 ftype
= build_function_type_list (ptr_type_node
,
10372 size_type_node
, NULL_TREE
);
10373 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
10374 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10377 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
10378 size_type_node
, NULL_TREE
);
10379 local_define_builtin ("__builtin_alloca_with_align", ftype
,
10380 BUILT_IN_ALLOCA_WITH_ALIGN
,
10381 "__builtin_alloca_with_align",
10382 ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10384 /* If we're checking the stack, `alloca' can throw. */
10385 if (flag_stack_check
)
10387 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA
)) = 0;
10388 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
)) = 0;
10391 ftype
= build_function_type_list (void_type_node
,
10392 ptr_type_node
, ptr_type_node
,
10393 ptr_type_node
, NULL_TREE
);
10394 local_define_builtin ("__builtin_init_trampoline", ftype
,
10395 BUILT_IN_INIT_TRAMPOLINE
,
10396 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
10397 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
10398 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
10399 "__builtin_init_heap_trampoline",
10400 ECF_NOTHROW
| ECF_LEAF
);
10402 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
10403 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
10404 BUILT_IN_ADJUST_TRAMPOLINE
,
10405 "__builtin_adjust_trampoline",
10406 ECF_CONST
| ECF_NOTHROW
);
10408 ftype
= build_function_type_list (void_type_node
,
10409 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10410 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
10411 BUILT_IN_NONLOCAL_GOTO
,
10412 "__builtin_nonlocal_goto",
10413 ECF_NORETURN
| ECF_NOTHROW
);
10415 ftype
= build_function_type_list (void_type_node
,
10416 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10417 local_define_builtin ("__builtin_setjmp_setup", ftype
,
10418 BUILT_IN_SETJMP_SETUP
,
10419 "__builtin_setjmp_setup", ECF_NOTHROW
);
10421 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10422 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
10423 BUILT_IN_SETJMP_RECEIVER
,
10424 "__builtin_setjmp_receiver", ECF_NOTHROW
| ECF_LEAF
);
10426 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
10427 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
10428 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
10430 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10431 local_define_builtin ("__builtin_stack_restore", ftype
,
10432 BUILT_IN_STACK_RESTORE
,
10433 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
10435 /* If there's a possibility that we might use the ARM EABI, build the
10436 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
10437 if (targetm
.arm_eabi_unwinder
)
10439 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
10440 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
10441 BUILT_IN_CXA_END_CLEANUP
,
10442 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
10445 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10446 local_define_builtin ("__builtin_unwind_resume", ftype
,
10447 BUILT_IN_UNWIND_RESUME
,
10448 ((targetm_common
.except_unwind_info (&global_options
)
10450 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10453 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
10455 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
10457 local_define_builtin ("__builtin_return_address", ftype
,
10458 BUILT_IN_RETURN_ADDRESS
,
10459 "__builtin_return_address",
10463 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
10464 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10466 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
10467 ptr_type_node
, NULL_TREE
);
10468 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
10469 local_define_builtin ("__cyg_profile_func_enter", ftype
,
10470 BUILT_IN_PROFILE_FUNC_ENTER
,
10471 "__cyg_profile_func_enter", 0);
10472 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10473 local_define_builtin ("__cyg_profile_func_exit", ftype
,
10474 BUILT_IN_PROFILE_FUNC_EXIT
,
10475 "__cyg_profile_func_exit", 0);
10478 /* The exception object and filter values from the runtime. The argument
10479 must be zero before exception lowering, i.e. from the front end. After
10480 exception lowering, it will be the region number for the exception
10481 landing pad. These functions are PURE instead of CONST to prevent
10482 them from being hoisted past the exception edge that will initialize
10483 its value in the landing pad. */
10484 ftype
= build_function_type_list (ptr_type_node
,
10485 integer_type_node
, NULL_TREE
);
10486 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
10487 /* Only use TM_PURE if we have TM language support. */
10488 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
10489 ecf_flags
|= ECF_TM_PURE
;
10490 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
10491 "__builtin_eh_pointer", ecf_flags
);
10493 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
10494 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
10495 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
10496 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10498 ftype
= build_function_type_list (void_type_node
,
10499 integer_type_node
, integer_type_node
,
10501 local_define_builtin ("__builtin_eh_copy_values", ftype
,
10502 BUILT_IN_EH_COPY_VALUES
,
10503 "__builtin_eh_copy_values", ECF_NOTHROW
);
10505 /* Complex multiplication and division. These are handled as builtins
10506 rather than optabs because emit_library_call_value doesn't support
10507 complex. Further, we can do slightly better with folding these
10508 beasties if the real and complex parts of the arguments are separate. */
10512 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
10514 char mode_name_buf
[4], *q
;
10516 enum built_in_function mcode
, dcode
;
10517 tree type
, inner_type
;
10518 const char *prefix
= "__";
10520 if (targetm
.libfunc_gnu_prefix
)
10523 type
= lang_hooks
.types
.type_for_mode ((machine_mode
) mode
, 0);
10526 inner_type
= TREE_TYPE (type
);
10528 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
10529 inner_type
, inner_type
, NULL_TREE
);
10531 mcode
= ((enum built_in_function
)
10532 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10533 dcode
= ((enum built_in_function
)
10534 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10536 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
10540 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
10542 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
10543 built_in_names
[mcode
],
10544 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10546 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
10548 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
10549 built_in_names
[dcode
],
10550 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10554 init_internal_fns ();
10557 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10560 If we requested a pointer to a vector, build up the pointers that
10561 we stripped off while looking for the inner type. Similarly for
10562 return values from functions.
10564 The argument TYPE is the top of the chain, and BOTTOM is the
10565 new type which we will point to. */
10568 reconstruct_complex_type (tree type
, tree bottom
)
10572 if (TREE_CODE (type
) == POINTER_TYPE
)
10574 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10575 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
10576 TYPE_REF_CAN_ALIAS_ALL (type
));
10578 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
10580 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10581 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
10582 TYPE_REF_CAN_ALIAS_ALL (type
));
10584 else if (TREE_CODE (type
) == ARRAY_TYPE
)
10586 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10587 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
10589 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
10591 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10592 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
10594 else if (TREE_CODE (type
) == METHOD_TYPE
)
10596 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10597 /* The build_method_type_directly() routine prepends 'this' to argument list,
10598 so we must compensate by getting rid of it. */
10600 = build_method_type_directly
10601 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
10603 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
10605 else if (TREE_CODE (type
) == OFFSET_TYPE
)
10607 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10608 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
10613 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
10614 TYPE_QUALS (type
));
10617 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10620 build_vector_type_for_mode (tree innertype
, machine_mode mode
)
10624 switch (GET_MODE_CLASS (mode
))
10626 case MODE_VECTOR_INT
:
10627 case MODE_VECTOR_FLOAT
:
10628 case MODE_VECTOR_FRACT
:
10629 case MODE_VECTOR_UFRACT
:
10630 case MODE_VECTOR_ACCUM
:
10631 case MODE_VECTOR_UACCUM
:
10632 nunits
= GET_MODE_NUNITS (mode
);
10636 /* Check that there are no leftover bits. */
10637 gcc_assert (GET_MODE_BITSIZE (mode
)
10638 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
10640 nunits
= GET_MODE_BITSIZE (mode
)
10641 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
10645 gcc_unreachable ();
10648 return make_vector_type (innertype
, nunits
, mode
);
10651 /* Similarly, but takes the inner type and number of units, which must be
10655 build_vector_type (tree innertype
, int nunits
)
10657 return make_vector_type (innertype
, nunits
, VOIDmode
);
10660 /* Build truth vector with specified length and number of units. */
10663 build_truth_vector_type (unsigned nunits
, unsigned vector_size
)
10665 machine_mode mask_mode
= targetm
.vectorize
.get_mask_mode (nunits
,
10668 gcc_assert (mask_mode
!= VOIDmode
);
10670 unsigned HOST_WIDE_INT vsize
;
10671 if (mask_mode
== BLKmode
)
10672 vsize
= vector_size
* BITS_PER_UNIT
;
10674 vsize
= GET_MODE_BITSIZE (mask_mode
);
10676 unsigned HOST_WIDE_INT esize
= vsize
/ nunits
;
10677 gcc_assert (esize
* nunits
== vsize
);
10679 tree bool_type
= build_nonstandard_boolean_type (esize
);
10681 return make_vector_type (bool_type
, nunits
, mask_mode
);
10684 /* Returns a vector type corresponding to a comparison of VECTYPE. */
10687 build_same_sized_truth_vector_type (tree vectype
)
10689 if (VECTOR_BOOLEAN_TYPE_P (vectype
))
10692 unsigned HOST_WIDE_INT size
= GET_MODE_SIZE (TYPE_MODE (vectype
));
10695 size
= tree_to_uhwi (TYPE_SIZE_UNIT (vectype
));
10697 return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (vectype
), size
);
10700 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10703 build_opaque_vector_type (tree innertype
, int nunits
)
10705 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
10707 /* We always build the non-opaque variant before the opaque one,
10708 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10709 cand
= TYPE_NEXT_VARIANT (t
);
10711 && TYPE_VECTOR_OPAQUE (cand
)
10712 && check_qualified_type (cand
, t
, TYPE_QUALS (t
)))
10714 /* Othewise build a variant type and make sure to queue it after
10715 the non-opaque type. */
10716 cand
= build_distinct_type_copy (t
);
10717 TYPE_VECTOR_OPAQUE (cand
) = true;
10718 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
10719 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
10720 TYPE_NEXT_VARIANT (t
) = cand
;
10721 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
10726 /* Given an initializer INIT, return TRUE if INIT is zero or some
10727 aggregate of zeros. Otherwise return FALSE. */
10729 initializer_zerop (const_tree init
)
10735 switch (TREE_CODE (init
))
10738 return integer_zerop (init
);
10741 /* ??? Note that this is not correct for C4X float formats. There,
10742 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10743 negative exponent. */
10744 return real_zerop (init
)
10745 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
10748 return fixed_zerop (init
);
10751 return integer_zerop (init
)
10752 || (real_zerop (init
)
10753 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10754 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
10759 for (i
= 0; i
< VECTOR_CST_NELTS (init
); ++i
)
10760 if (!initializer_zerop (VECTOR_CST_ELT (init
, i
)))
10767 unsigned HOST_WIDE_INT idx
;
10769 if (TREE_CLOBBER_P (init
))
10771 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10772 if (!initializer_zerop (elt
))
10781 /* We need to loop through all elements to handle cases like
10782 "\0" and "\0foobar". */
10783 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
10784 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10795 /* Check if vector VEC consists of all the equal elements and
10796 that the number of elements corresponds to the type of VEC.
10797 The function returns first element of the vector
10798 or NULL_TREE if the vector is not uniform. */
10800 uniform_vector_p (const_tree vec
)
10805 if (vec
== NULL_TREE
)
10808 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10810 if (TREE_CODE (vec
) == VECTOR_CST
)
10812 first
= VECTOR_CST_ELT (vec
, 0);
10813 for (i
= 1; i
< VECTOR_CST_NELTS (vec
); ++i
)
10814 if (!operand_equal_p (first
, VECTOR_CST_ELT (vec
, i
), 0))
10820 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
10822 first
= error_mark_node
;
10824 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10831 if (!operand_equal_p (first
, t
, 0))
10834 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
10843 /* Build an empty statement at location LOC. */
10846 build_empty_stmt (location_t loc
)
10848 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10849 SET_EXPR_LOCATION (t
, loc
);
10854 /* Build an OpenMP clause with code CODE. LOC is the location of the
10858 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10863 length
= omp_clause_num_ops
[code
];
10864 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10866 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10868 t
= (tree
) ggc_internal_alloc (size
);
10869 memset (t
, 0, size
);
10870 TREE_SET_CODE (t
, OMP_CLAUSE
);
10871 OMP_CLAUSE_SET_CODE (t
, code
);
10872 OMP_CLAUSE_LOCATION (t
) = loc
;
10877 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10878 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10879 Except for the CODE and operand count field, other storage for the
10880 object is initialized to zeros. */
10883 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
10886 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10888 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10889 gcc_assert (len
>= 1);
10891 record_node_allocation_statistics (code
, length
);
10893 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10895 TREE_SET_CODE (t
, code
);
10897 /* Can't use TREE_OPERAND to store the length because if checking is
10898 enabled, it will try to check the length before we store it. :-P */
10899 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10904 /* Helper function for build_call_* functions; build a CALL_EXPR with
10905 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10906 the argument slots. */
10909 build_call_1 (tree return_type
, tree fn
, int nargs
)
10913 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10914 TREE_TYPE (t
) = return_type
;
10915 CALL_EXPR_FN (t
) = fn
;
10916 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10921 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10922 FN and a null static chain slot. NARGS is the number of call arguments
10923 which are specified as "..." arguments. */
10926 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10930 va_start (args
, nargs
);
10931 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10936 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10937 FN and a null static chain slot. NARGS is the number of call arguments
10938 which are specified as a va_list ARGS. */
10941 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10946 t
= build_call_1 (return_type
, fn
, nargs
);
10947 for (i
= 0; i
< nargs
; i
++)
10948 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10949 process_call_operands (t
);
10953 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10954 FN and a null static chain slot. NARGS is the number of call arguments
10955 which are specified as a tree array ARGS. */
10958 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10959 int nargs
, const tree
*args
)
10964 t
= build_call_1 (return_type
, fn
, nargs
);
10965 for (i
= 0; i
< nargs
; i
++)
10966 CALL_EXPR_ARG (t
, i
) = args
[i
];
10967 process_call_operands (t
);
10968 SET_EXPR_LOCATION (t
, loc
);
10972 /* Like build_call_array, but takes a vec. */
10975 build_call_vec (tree return_type
, tree fn
, vec
<tree
, va_gc
> *args
)
10980 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10981 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10982 CALL_EXPR_ARG (ret
, ix
) = t
;
10983 process_call_operands (ret
);
10987 /* Conveniently construct a function call expression. FNDECL names the
10988 function to be called and N arguments are passed in the array
10992 build_call_expr_loc_array (location_t loc
, tree fndecl
, int n
, tree
*argarray
)
10994 tree fntype
= TREE_TYPE (fndecl
);
10995 tree fn
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), fndecl
);
10997 return fold_build_call_array_loc (loc
, TREE_TYPE (fntype
), fn
, n
, argarray
);
11000 /* Conveniently construct a function call expression. FNDECL names the
11001 function to be called and the arguments are passed in the vector
11005 build_call_expr_loc_vec (location_t loc
, tree fndecl
, vec
<tree
, va_gc
> *vec
)
11007 return build_call_expr_loc_array (loc
, fndecl
, vec_safe_length (vec
),
11008 vec_safe_address (vec
));
11012 /* Conveniently construct a function call expression. FNDECL names the
11013 function to be called, N is the number of arguments, and the "..."
11014 parameters are the argument expressions. */
11017 build_call_expr_loc (location_t loc
, tree fndecl
, int n
, ...)
11020 tree
*argarray
= XALLOCAVEC (tree
, n
);
11024 for (i
= 0; i
< n
; i
++)
11025 argarray
[i
] = va_arg (ap
, tree
);
11027 return build_call_expr_loc_array (loc
, fndecl
, n
, argarray
);
11030 /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11031 varargs macros aren't supported by all bootstrap compilers. */
11034 build_call_expr (tree fndecl
, int n
, ...)
11037 tree
*argarray
= XALLOCAVEC (tree
, n
);
11041 for (i
= 0; i
< n
; i
++)
11042 argarray
[i
] = va_arg (ap
, tree
);
11044 return build_call_expr_loc_array (UNKNOWN_LOCATION
, fndecl
, n
, argarray
);
11047 /* Build internal call expression. This is just like CALL_EXPR, except
11048 its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11049 internal function. */
11052 build_call_expr_internal_loc (location_t loc
, enum internal_fn ifn
,
11053 tree type
, int n
, ...)
11058 tree fn
= build_call_1 (type
, NULL_TREE
, n
);
11060 for (i
= 0; i
< n
; i
++)
11061 CALL_EXPR_ARG (fn
, i
) = va_arg (ap
, tree
);
11063 SET_EXPR_LOCATION (fn
, loc
);
11064 CALL_EXPR_IFN (fn
) = ifn
;
11068 /* Create a new constant string literal and return a char* pointer to it.
11069 The STRING_CST value is the LEN characters at STR. */
11071 build_string_literal (int len
, const char *str
)
11073 tree t
, elem
, index
, type
;
11075 t
= build_string (len
, str
);
11076 elem
= build_type_variant (char_type_node
, 1, 0);
11077 index
= build_index_type (size_int (len
- 1));
11078 type
= build_array_type (elem
, index
);
11079 TREE_TYPE (t
) = type
;
11080 TREE_CONSTANT (t
) = 1;
11081 TREE_READONLY (t
) = 1;
11082 TREE_STATIC (t
) = 1;
11084 type
= build_pointer_type (elem
);
11085 t
= build1 (ADDR_EXPR
, type
,
11086 build4 (ARRAY_REF
, elem
,
11087 t
, integer_zero_node
, NULL_TREE
, NULL_TREE
));
11093 /* Return true if T (assumed to be a DECL) must be assigned a memory
11097 needs_to_live_in_memory (const_tree t
)
11099 return (TREE_ADDRESSABLE (t
)
11100 || is_global_var (t
)
11101 || (TREE_CODE (t
) == RESULT_DECL
11102 && !DECL_BY_REFERENCE (t
)
11103 && aggregate_value_p (t
, current_function_decl
)));
11106 /* Return value of a constant X and sign-extend it. */
11109 int_cst_value (const_tree x
)
11111 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
11112 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
11114 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11115 gcc_assert (cst_and_fits_in_hwi (x
));
11117 if (bits
< HOST_BITS_PER_WIDE_INT
)
11119 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
11121 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
11123 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
11129 /* If TYPE is an integral or pointer type, return an integer type with
11130 the same precision which is unsigned iff UNSIGNEDP is true, or itself
11131 if TYPE is already an integer type of signedness UNSIGNEDP. */
11134 signed_or_unsigned_type_for (int unsignedp
, tree type
)
11136 if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
) == unsignedp
)
11139 if (TREE_CODE (type
) == VECTOR_TYPE
)
11141 tree inner
= TREE_TYPE (type
);
11142 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
11145 if (inner
== inner2
)
11147 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
11150 if (!INTEGRAL_TYPE_P (type
)
11151 && !POINTER_TYPE_P (type
)
11152 && TREE_CODE (type
) != OFFSET_TYPE
)
11155 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
11158 /* If TYPE is an integral or pointer type, return an integer type with
11159 the same precision which is unsigned, or itself if TYPE is already an
11160 unsigned integer type. */
11163 unsigned_type_for (tree type
)
11165 return signed_or_unsigned_type_for (1, type
);
11168 /* If TYPE is an integral or pointer type, return an integer type with
11169 the same precision which is signed, or itself if TYPE is already a
11170 signed integer type. */
11173 signed_type_for (tree type
)
11175 return signed_or_unsigned_type_for (0, type
);
11178 /* If TYPE is a vector type, return a signed integer vector type with the
11179 same width and number of subparts. Otherwise return boolean_type_node. */
11182 truth_type_for (tree type
)
11184 if (TREE_CODE (type
) == VECTOR_TYPE
)
11186 if (VECTOR_BOOLEAN_TYPE_P (type
))
11188 return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (type
),
11189 GET_MODE_SIZE (TYPE_MODE (type
)));
11192 return boolean_type_node
;
11195 /* Returns the largest value obtainable by casting something in INNER type to
11199 upper_bound_in_type (tree outer
, tree inner
)
11201 unsigned int det
= 0;
11202 unsigned oprec
= TYPE_PRECISION (outer
);
11203 unsigned iprec
= TYPE_PRECISION (inner
);
11206 /* Compute a unique number for every combination. */
11207 det
|= (oprec
> iprec
) ? 4 : 0;
11208 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
11209 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
11211 /* Determine the exponent to use. */
11216 /* oprec <= iprec, outer: signed, inner: don't care. */
11221 /* oprec <= iprec, outer: unsigned, inner: don't care. */
11225 /* oprec > iprec, outer: signed, inner: signed. */
11229 /* oprec > iprec, outer: signed, inner: unsigned. */
11233 /* oprec > iprec, outer: unsigned, inner: signed. */
11237 /* oprec > iprec, outer: unsigned, inner: unsigned. */
11241 gcc_unreachable ();
11244 return wide_int_to_tree (outer
,
11245 wi::mask (prec
, false, TYPE_PRECISION (outer
)));
11248 /* Returns the smallest value obtainable by casting something in INNER type to
11252 lower_bound_in_type (tree outer
, tree inner
)
11254 unsigned oprec
= TYPE_PRECISION (outer
);
11255 unsigned iprec
= TYPE_PRECISION (inner
);
11257 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11259 if (TYPE_UNSIGNED (outer
)
11260 /* If we are widening something of an unsigned type, OUTER type
11261 contains all values of INNER type. In particular, both INNER
11262 and OUTER types have zero in common. */
11263 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
11264 return build_int_cst (outer
, 0);
11267 /* If we are widening a signed type to another signed type, we
11268 want to obtain -2^^(iprec-1). If we are keeping the
11269 precision or narrowing to a signed type, we want to obtain
11271 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
11272 return wide_int_to_tree (outer
,
11273 wi::mask (prec
- 1, true,
11274 TYPE_PRECISION (outer
)));
11278 /* Return nonzero if two operands that are suitable for PHI nodes are
11279 necessarily equal. Specifically, both ARG0 and ARG1 must be either
11280 SSA_NAME or invariant. Note that this is strictly an optimization.
11281 That is, callers of this function can directly call operand_equal_p
11282 and get the same result, only slower. */
11285 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
11289 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
11291 return operand_equal_p (arg0
, arg1
, 0);
11294 /* Returns number of zeros at the end of binary representation of X. */
11297 num_ending_zeros (const_tree x
)
11299 return build_int_cst (TREE_TYPE (x
), wi::ctz (x
));
11303 #define WALK_SUBTREE(NODE) \
11306 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11312 /* This is a subroutine of walk_tree that walks field of TYPE that are to
11313 be walked whenever a type is seen in the tree. Rest of operands and return
11314 value are as for walk_tree. */
11317 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
11318 hash_set
<tree
> *pset
, walk_tree_lh lh
)
11320 tree result
= NULL_TREE
;
11322 switch (TREE_CODE (type
))
11325 case REFERENCE_TYPE
:
11327 /* We have to worry about mutually recursive pointers. These can't
11328 be written in C. They can in Ada. It's pathological, but
11329 there's an ACATS test (c38102a) that checks it. Deal with this
11330 by checking if we're pointing to another pointer, that one
11331 points to another pointer, that one does too, and we have no htab.
11332 If so, get a hash table. We check three levels deep to avoid
11333 the cost of the hash table if we don't need one. */
11334 if (POINTER_TYPE_P (TREE_TYPE (type
))
11335 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
11336 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
11339 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
11347 /* ... fall through ... */
11350 WALK_SUBTREE (TREE_TYPE (type
));
11354 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
11356 /* Fall through. */
11358 case FUNCTION_TYPE
:
11359 WALK_SUBTREE (TREE_TYPE (type
));
11363 /* We never want to walk into default arguments. */
11364 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
11365 WALK_SUBTREE (TREE_VALUE (arg
));
11370 /* Don't follow this nodes's type if a pointer for fear that
11371 we'll have infinite recursion. If we have a PSET, then we
11374 || (!POINTER_TYPE_P (TREE_TYPE (type
))
11375 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
11376 WALK_SUBTREE (TREE_TYPE (type
));
11377 WALK_SUBTREE (TYPE_DOMAIN (type
));
11381 WALK_SUBTREE (TREE_TYPE (type
));
11382 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
11392 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11393 called with the DATA and the address of each sub-tree. If FUNC returns a
11394 non-NULL value, the traversal is stopped, and the value returned by FUNC
11395 is returned. If PSET is non-NULL it is used to record the nodes visited,
11396 and to avoid visiting a node more than once. */
11399 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11400 hash_set
<tree
> *pset
, walk_tree_lh lh
)
11402 enum tree_code code
;
11406 #define WALK_SUBTREE_TAIL(NODE) \
11410 goto tail_recurse; \
11415 /* Skip empty subtrees. */
11419 /* Don't walk the same tree twice, if the user has requested
11420 that we avoid doing so. */
11421 if (pset
&& pset
->add (*tp
))
11424 /* Call the function. */
11426 result
= (*func
) (tp
, &walk_subtrees
, data
);
11428 /* If we found something, return it. */
11432 code
= TREE_CODE (*tp
);
11434 /* Even if we didn't, FUNC may have decided that there was nothing
11435 interesting below this point in the tree. */
11436 if (!walk_subtrees
)
11438 /* But we still need to check our siblings. */
11439 if (code
== TREE_LIST
)
11440 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11441 else if (code
== OMP_CLAUSE
)
11442 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11449 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
11450 if (result
|| !walk_subtrees
)
11457 case IDENTIFIER_NODE
:
11464 case PLACEHOLDER_EXPR
:
11468 /* None of these have subtrees other than those already walked
11473 WALK_SUBTREE (TREE_VALUE (*tp
));
11474 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11479 int len
= TREE_VEC_LENGTH (*tp
);
11484 /* Walk all elements but the first. */
11486 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
11488 /* Now walk the first one as a tail call. */
11489 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
11493 WALK_SUBTREE (TREE_REALPART (*tp
));
11494 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
11498 unsigned HOST_WIDE_INT idx
;
11499 constructor_elt
*ce
;
11501 for (idx
= 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*tp
), idx
, &ce
);
11503 WALK_SUBTREE (ce
->value
);
11508 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
11513 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
11515 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11516 into declarations that are just mentioned, rather than
11517 declared; they don't really belong to this part of the tree.
11518 And, we can see cycles: the initializer for a declaration
11519 can refer to the declaration itself. */
11520 WALK_SUBTREE (DECL_INITIAL (decl
));
11521 WALK_SUBTREE (DECL_SIZE (decl
));
11522 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
11524 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
11527 case STATEMENT_LIST
:
11529 tree_stmt_iterator i
;
11530 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
11531 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11536 switch (OMP_CLAUSE_CODE (*tp
))
11538 case OMP_CLAUSE_GANG
:
11539 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 1));
11542 case OMP_CLAUSE_DEVICE_RESIDENT
:
11543 case OMP_CLAUSE_USE_DEVICE
:
11544 case OMP_CLAUSE_ASYNC
:
11545 case OMP_CLAUSE_WAIT
:
11546 case OMP_CLAUSE_WORKER
:
11547 case OMP_CLAUSE_VECTOR
:
11548 case OMP_CLAUSE_NUM_GANGS
:
11549 case OMP_CLAUSE_NUM_WORKERS
:
11550 case OMP_CLAUSE_VECTOR_LENGTH
:
11551 case OMP_CLAUSE_PRIVATE
:
11552 case OMP_CLAUSE_SHARED
:
11553 case OMP_CLAUSE_FIRSTPRIVATE
:
11554 case OMP_CLAUSE_COPYIN
:
11555 case OMP_CLAUSE_COPYPRIVATE
:
11556 case OMP_CLAUSE_FINAL
:
11557 case OMP_CLAUSE_IF
:
11558 case OMP_CLAUSE_NUM_THREADS
:
11559 case OMP_CLAUSE_SCHEDULE
:
11560 case OMP_CLAUSE_UNIFORM
:
11561 case OMP_CLAUSE_DEPEND
:
11562 case OMP_CLAUSE_NUM_TEAMS
:
11563 case OMP_CLAUSE_THREAD_LIMIT
:
11564 case OMP_CLAUSE_DEVICE
:
11565 case OMP_CLAUSE_DIST_SCHEDULE
:
11566 case OMP_CLAUSE_SAFELEN
:
11567 case OMP_CLAUSE_SIMDLEN
:
11568 case OMP_CLAUSE_ORDERED
:
11569 case OMP_CLAUSE_PRIORITY
:
11570 case OMP_CLAUSE_GRAINSIZE
:
11571 case OMP_CLAUSE_NUM_TASKS
:
11572 case OMP_CLAUSE_HINT
:
11573 case OMP_CLAUSE_TO_DECLARE
:
11574 case OMP_CLAUSE_LINK
:
11575 case OMP_CLAUSE_USE_DEVICE_PTR
:
11576 case OMP_CLAUSE_IS_DEVICE_PTR
:
11577 case OMP_CLAUSE__LOOPTEMP_
:
11578 case OMP_CLAUSE__SIMDUID_
:
11579 case OMP_CLAUSE__CILK_FOR_COUNT_
:
11580 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
11583 case OMP_CLAUSE_INDEPENDENT
:
11584 case OMP_CLAUSE_NOWAIT
:
11585 case OMP_CLAUSE_DEFAULT
:
11586 case OMP_CLAUSE_UNTIED
:
11587 case OMP_CLAUSE_MERGEABLE
:
11588 case OMP_CLAUSE_PROC_BIND
:
11589 case OMP_CLAUSE_INBRANCH
:
11590 case OMP_CLAUSE_NOTINBRANCH
:
11591 case OMP_CLAUSE_FOR
:
11592 case OMP_CLAUSE_PARALLEL
:
11593 case OMP_CLAUSE_SECTIONS
:
11594 case OMP_CLAUSE_TASKGROUP
:
11595 case OMP_CLAUSE_NOGROUP
:
11596 case OMP_CLAUSE_THREADS
:
11597 case OMP_CLAUSE_SIMD
:
11598 case OMP_CLAUSE_DEFAULTMAP
:
11599 case OMP_CLAUSE_AUTO
:
11600 case OMP_CLAUSE_SEQ
:
11601 case OMP_CLAUSE_TILE
:
11602 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11604 case OMP_CLAUSE_LASTPRIVATE
:
11605 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11606 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
11607 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11609 case OMP_CLAUSE_COLLAPSE
:
11612 for (i
= 0; i
< 3; i
++)
11613 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11614 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11617 case OMP_CLAUSE_LINEAR
:
11618 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11619 WALK_SUBTREE (OMP_CLAUSE_LINEAR_STEP (*tp
));
11620 WALK_SUBTREE (OMP_CLAUSE_LINEAR_STMT (*tp
));
11621 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11623 case OMP_CLAUSE_ALIGNED
:
11624 case OMP_CLAUSE_FROM
:
11625 case OMP_CLAUSE_TO
:
11626 case OMP_CLAUSE_MAP
:
11627 case OMP_CLAUSE__CACHE_
:
11628 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11629 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 1));
11630 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11632 case OMP_CLAUSE_REDUCTION
:
11635 for (i
= 0; i
< 5; i
++)
11636 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11637 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11641 gcc_unreachable ();
11649 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11650 But, we only want to walk once. */
11651 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11652 for (i
= 0; i
< len
; ++i
)
11653 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11654 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11658 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11659 defining. We only want to walk into these fields of a type in this
11660 case and not in the general case of a mere reference to the type.
11662 The criterion is as follows: if the field can be an expression, it
11663 must be walked only here. This should be in keeping with the fields
11664 that are directly gimplified in gimplify_type_sizes in order for the
11665 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11666 variable-sized types.
11668 Note that DECLs get walked as part of processing the BIND_EXPR. */
11669 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11671 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11672 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11675 /* Call the function for the type. See if it returns anything or
11676 doesn't want us to continue. If we are to continue, walk both
11677 the normal fields and those for the declaration case. */
11678 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11679 if (result
|| !walk_subtrees
)
11682 /* But do not walk a pointed-to type since it may itself need to
11683 be walked in the declaration case if it isn't anonymous. */
11684 if (!POINTER_TYPE_P (*type_p
))
11686 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11691 /* If this is a record type, also walk the fields. */
11692 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11696 for (field
= TYPE_FIELDS (*type_p
); field
;
11697 field
= DECL_CHAIN (field
))
11699 /* We'd like to look at the type of the field, but we can
11700 easily get infinite recursion. So assume it's pointed
11701 to elsewhere in the tree. Also, ignore things that
11703 if (TREE_CODE (field
) != FIELD_DECL
)
11706 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11707 WALK_SUBTREE (DECL_SIZE (field
));
11708 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11709 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11710 WALK_SUBTREE (DECL_QUALIFIER (field
));
11714 /* Same for scalar types. */
11715 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11716 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11717 || TREE_CODE (*type_p
) == INTEGER_TYPE
11718 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11719 || TREE_CODE (*type_p
) == REAL_TYPE
)
11721 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11722 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11725 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11726 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11731 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11735 /* Walk over all the sub-trees of this operand. */
11736 len
= TREE_OPERAND_LENGTH (*tp
);
11738 /* Go through the subtrees. We need to do this in forward order so
11739 that the scope of a FOR_EXPR is handled properly. */
11742 for (i
= 0; i
< len
- 1; ++i
)
11743 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11744 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11747 /* If this is a type, walk the needed fields in the type. */
11748 else if (TYPE_P (*tp
))
11749 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11753 /* We didn't find what we were looking for. */
11756 #undef WALK_SUBTREE_TAIL
11758 #undef WALK_SUBTREE
11760 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11763 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11768 hash_set
<tree
> pset
;
11769 result
= walk_tree_1 (tp
, func
, data
, &pset
, lh
);
11775 tree_block (tree t
)
11777 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11779 if (IS_EXPR_CODE_CLASS (c
))
11780 return LOCATION_BLOCK (t
->exp
.locus
);
11781 gcc_unreachable ();
11786 tree_set_block (tree t
, tree b
)
11788 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11790 if (IS_EXPR_CODE_CLASS (c
))
11793 t
->exp
.locus
= COMBINE_LOCATION_DATA (line_table
, t
->exp
.locus
, b
);
11795 t
->exp
.locus
= LOCATION_LOCUS (t
->exp
.locus
);
11798 gcc_unreachable ();
11801 /* Create a nameless artificial label and put it in the current
11802 function context. The label has a location of LOC. Returns the
11803 newly created label. */
11806 create_artificial_label (location_t loc
)
11808 tree lab
= build_decl (loc
,
11809 LABEL_DECL
, NULL_TREE
, void_type_node
);
11811 DECL_ARTIFICIAL (lab
) = 1;
11812 DECL_IGNORED_P (lab
) = 1;
11813 DECL_CONTEXT (lab
) = current_function_decl
;
11817 /* Given a tree, try to return a useful variable name that we can use
11818 to prefix a temporary that is being assigned the value of the tree.
11819 I.E. given <temp> = &A, return A. */
11824 tree stripped_decl
;
11827 STRIP_NOPS (stripped_decl
);
11828 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11829 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11830 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11832 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11835 return IDENTIFIER_POINTER (name
);
11839 switch (TREE_CODE (stripped_decl
))
11842 return get_name (TREE_OPERAND (stripped_decl
, 0));
11849 /* Return true if TYPE has a variable argument list. */
11852 stdarg_p (const_tree fntype
)
11854 function_args_iterator args_iter
;
11855 tree n
= NULL_TREE
, t
;
11860 FOREACH_FUNCTION_ARGS (fntype
, t
, args_iter
)
11865 return n
!= NULL_TREE
&& n
!= void_type_node
;
11868 /* Return true if TYPE has a prototype. */
11871 prototype_p (const_tree fntype
)
11875 gcc_assert (fntype
!= NULL_TREE
);
11877 t
= TYPE_ARG_TYPES (fntype
);
11878 return (t
!= NULL_TREE
);
11881 /* If BLOCK is inlined from an __attribute__((__artificial__))
11882 routine, return pointer to location from where it has been
11885 block_nonartificial_location (tree block
)
11887 location_t
*ret
= NULL
;
11889 while (block
&& TREE_CODE (block
) == BLOCK
11890 && BLOCK_ABSTRACT_ORIGIN (block
))
11892 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11894 while (TREE_CODE (ao
) == BLOCK
11895 && BLOCK_ABSTRACT_ORIGIN (ao
)
11896 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
11897 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
11899 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11901 /* If AO is an artificial inline, point RET to the
11902 call site locus at which it has been inlined and continue
11903 the loop, in case AO's caller is also an artificial
11905 if (DECL_DECLARED_INLINE_P (ao
)
11906 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11907 ret
= &BLOCK_SOURCE_LOCATION (block
);
11911 else if (TREE_CODE (ao
) != BLOCK
)
11914 block
= BLOCK_SUPERCONTEXT (block
);
11920 /* If EXP is inlined from an __attribute__((__artificial__))
11921 function, return the location of the original call expression. */
11924 tree_nonartificial_location (tree exp
)
11926 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11931 return EXPR_LOCATION (exp
);
11935 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11938 /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11941 cl_option_hasher::hash (tree x
)
11943 const_tree
const t
= x
;
11947 hashval_t hash
= 0;
11949 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11951 p
= (const char *)TREE_OPTIMIZATION (t
);
11952 len
= sizeof (struct cl_optimization
);
11955 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11956 return cl_target_option_hash (TREE_TARGET_OPTION (t
));
11959 gcc_unreachable ();
11961 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11963 for (i
= 0; i
< len
; i
++)
11965 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
11970 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11971 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11975 cl_option_hasher::equal (tree x
, tree y
)
11977 const_tree
const xt
= x
;
11978 const_tree
const yt
= y
;
11983 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11986 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11988 xp
= (const char *)TREE_OPTIMIZATION (xt
);
11989 yp
= (const char *)TREE_OPTIMIZATION (yt
);
11990 len
= sizeof (struct cl_optimization
);
11993 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11995 return cl_target_option_eq (TREE_TARGET_OPTION (xt
),
11996 TREE_TARGET_OPTION (yt
));
12000 gcc_unreachable ();
12002 return (memcmp (xp
, yp
, len
) == 0);
12005 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */
12008 build_optimization_node (struct gcc_options
*opts
)
12012 /* Use the cache of optimization nodes. */
12014 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
12017 tree
*slot
= cl_option_hash_table
->find_slot (cl_optimization_node
, INSERT
);
12021 /* Insert this one into the hash table. */
12022 t
= cl_optimization_node
;
12025 /* Make a new node for next time round. */
12026 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
12032 /* Build a TARGET_OPTION_NODE based on the options in OPTS. */
12035 build_target_option_node (struct gcc_options
*opts
)
12039 /* Use the cache of optimization nodes. */
12041 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
12044 tree
*slot
= cl_option_hash_table
->find_slot (cl_target_option_node
, INSERT
);
12048 /* Insert this one into the hash table. */
12049 t
= cl_target_option_node
;
12052 /* Make a new node for next time round. */
12053 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
12059 /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12060 so that they aren't saved during PCH writing. */
12063 prepare_target_option_nodes_for_pch (void)
12065 hash_table
<cl_option_hasher
>::iterator iter
= cl_option_hash_table
->begin ();
12066 for (; iter
!= cl_option_hash_table
->end (); ++iter
)
12067 if (TREE_CODE (*iter
) == TARGET_OPTION_NODE
)
12068 TREE_TARGET_GLOBALS (*iter
) = NULL
;
12071 /* Determine the "ultimate origin" of a block. The block may be an inlined
12072 instance of an inlined instance of a block which is local to an inline
12073 function, so we have to trace all of the way back through the origin chain
12074 to find out what sort of node actually served as the original seed for the
12078 block_ultimate_origin (const_tree block
)
12080 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
12082 /* BLOCK_ABSTRACT_ORIGIN can point to itself; ignore that if
12083 we're trying to output the abstract instance of this function. */
12084 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
12087 if (immediate_origin
== NULL_TREE
)
12092 tree lookahead
= immediate_origin
;
12096 ret_val
= lookahead
;
12097 lookahead
= (TREE_CODE (ret_val
) == BLOCK
12098 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
12100 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
12102 /* The block's abstract origin chain may not be the *ultimate* origin of
12103 the block. It could lead to a DECL that has an abstract origin set.
12104 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
12105 will give us if it has one). Note that DECL's abstract origins are
12106 supposed to be the most distant ancestor (or so decl_ultimate_origin
12107 claims), so we don't need to loop following the DECL origins. */
12108 if (DECL_P (ret_val
))
12109 return DECL_ORIGIN (ret_val
);
12115 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12119 tree_nop_conversion_p (const_tree outer_type
, const_tree inner_type
)
12121 /* Use precision rather then machine mode when we can, which gives
12122 the correct answer even for submode (bit-field) types. */
12123 if ((INTEGRAL_TYPE_P (outer_type
)
12124 || POINTER_TYPE_P (outer_type
)
12125 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
12126 && (INTEGRAL_TYPE_P (inner_type
)
12127 || POINTER_TYPE_P (inner_type
)
12128 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
12129 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
12131 /* Otherwise fall back on comparing machine modes (e.g. for
12132 aggregate types, floats). */
12133 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
12136 /* Return true iff conversion in EXP generates no instruction. Mark
12137 it inline so that we fully inline into the stripping functions even
12138 though we have two uses of this function. */
12141 tree_nop_conversion (const_tree exp
)
12143 tree outer_type
, inner_type
;
12145 if (!CONVERT_EXPR_P (exp
)
12146 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
12148 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
12151 outer_type
= TREE_TYPE (exp
);
12152 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
12157 return tree_nop_conversion_p (outer_type
, inner_type
);
12160 /* Return true iff conversion in EXP generates no instruction. Don't
12161 consider conversions changing the signedness. */
12164 tree_sign_nop_conversion (const_tree exp
)
12166 tree outer_type
, inner_type
;
12168 if (!tree_nop_conversion (exp
))
12171 outer_type
= TREE_TYPE (exp
);
12172 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
12174 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
12175 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
12178 /* Strip conversions from EXP according to tree_nop_conversion and
12179 return the resulting expression. */
12182 tree_strip_nop_conversions (tree exp
)
12184 while (tree_nop_conversion (exp
))
12185 exp
= TREE_OPERAND (exp
, 0);
12189 /* Strip conversions from EXP according to tree_sign_nop_conversion
12190 and return the resulting expression. */
12193 tree_strip_sign_nop_conversions (tree exp
)
12195 while (tree_sign_nop_conversion (exp
))
12196 exp
= TREE_OPERAND (exp
, 0);
12200 /* Avoid any floating point extensions from EXP. */
12202 strip_float_extensions (tree exp
)
12204 tree sub
, expt
, subt
;
12206 /* For floating point constant look up the narrowest type that can hold
12207 it properly and handle it like (type)(narrowest_type)constant.
12208 This way we can optimize for instance a=a*2.0 where "a" is float
12209 but 2.0 is double constant. */
12210 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
12212 REAL_VALUE_TYPE orig
;
12215 orig
= TREE_REAL_CST (exp
);
12216 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
12217 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
12218 type
= float_type_node
;
12219 else if (TYPE_PRECISION (TREE_TYPE (exp
))
12220 > TYPE_PRECISION (double_type_node
)
12221 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
12222 type
= double_type_node
;
12224 return build_real_truncate (type
, orig
);
12227 if (!CONVERT_EXPR_P (exp
))
12230 sub
= TREE_OPERAND (exp
, 0);
12231 subt
= TREE_TYPE (sub
);
12232 expt
= TREE_TYPE (exp
);
12234 if (!FLOAT_TYPE_P (subt
))
12237 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
12240 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
12243 return strip_float_extensions (sub
);
12246 /* Strip out all handled components that produce invariant
12250 strip_invariant_refs (const_tree op
)
12252 while (handled_component_p (op
))
12254 switch (TREE_CODE (op
))
12257 case ARRAY_RANGE_REF
:
12258 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
12259 || TREE_OPERAND (op
, 2) != NULL_TREE
12260 || TREE_OPERAND (op
, 3) != NULL_TREE
)
12264 case COMPONENT_REF
:
12265 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
12271 op
= TREE_OPERAND (op
, 0);
12277 static GTY(()) tree gcc_eh_personality_decl
;
12279 /* Return the GCC personality function decl. */
12282 lhd_gcc_personality (void)
12284 if (!gcc_eh_personality_decl
)
12285 gcc_eh_personality_decl
= build_personality_function ("gcc");
12286 return gcc_eh_personality_decl
;
12289 /* TARGET is a call target of GIMPLE call statement
12290 (obtained by gimple_call_fn). Return true if it is
12291 OBJ_TYPE_REF representing an virtual call of C++ method.
12292 (As opposed to OBJ_TYPE_REF representing objc calls
12293 through a cast where middle-end devirtualization machinery
12297 virtual_method_call_p (const_tree target
)
12299 if (TREE_CODE (target
) != OBJ_TYPE_REF
)
12301 tree t
= TREE_TYPE (target
);
12302 gcc_checking_assert (TREE_CODE (t
) == POINTER_TYPE
);
12304 if (TREE_CODE (t
) == FUNCTION_TYPE
)
12306 gcc_checking_assert (TREE_CODE (t
) == METHOD_TYPE
);
12307 /* If we do not have BINFO associated, it means that type was built
12308 without devirtualization enabled. Do not consider this a virtual
12310 if (!TYPE_BINFO (obj_type_ref_class (target
)))
12315 /* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */
12318 obj_type_ref_class (const_tree ref
)
12320 gcc_checking_assert (TREE_CODE (ref
) == OBJ_TYPE_REF
);
12321 ref
= TREE_TYPE (ref
);
12322 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12323 ref
= TREE_TYPE (ref
);
12324 /* We look for type THIS points to. ObjC also builds
12325 OBJ_TYPE_REF with non-method calls, Their first parameter
12326 ID however also corresponds to class type. */
12327 gcc_checking_assert (TREE_CODE (ref
) == METHOD_TYPE
12328 || TREE_CODE (ref
) == FUNCTION_TYPE
);
12329 ref
= TREE_VALUE (TYPE_ARG_TYPES (ref
));
12330 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12331 return TREE_TYPE (ref
);
12334 /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12337 lookup_binfo_at_offset (tree binfo
, tree type
, HOST_WIDE_INT pos
)
12340 tree base_binfo
, b
;
12342 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
12343 if (pos
== tree_to_shwi (BINFO_OFFSET (base_binfo
))
12344 && types_same_for_odr (TREE_TYPE (base_binfo
), type
))
12346 else if ((b
= lookup_binfo_at_offset (base_binfo
, type
, pos
)) != NULL
)
12351 /* Try to find a base info of BINFO that would have its field decl at offset
12352 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12353 found, return, otherwise return NULL_TREE. */
12356 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
12358 tree type
= BINFO_TYPE (binfo
);
12362 HOST_WIDE_INT pos
, size
;
12366 if (types_same_for_odr (type
, expected_type
))
12371 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
12373 if (TREE_CODE (fld
) != FIELD_DECL
|| !DECL_ARTIFICIAL (fld
))
12376 pos
= int_bit_position (fld
);
12377 size
= tree_to_uhwi (DECL_SIZE (fld
));
12378 if (pos
<= offset
&& (pos
+ size
) > offset
)
12381 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
12384 /* Offset 0 indicates the primary base, whose vtable contents are
12385 represented in the binfo for the derived class. */
12386 else if (offset
!= 0)
12388 tree found_binfo
= NULL
, base_binfo
;
12389 /* Offsets in BINFO are in bytes relative to the whole structure
12390 while POS is in bits relative to the containing field. */
12391 int binfo_offset
= (tree_to_shwi (BINFO_OFFSET (binfo
)) + pos
12394 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
12395 if (tree_to_shwi (BINFO_OFFSET (base_binfo
)) == binfo_offset
12396 && types_same_for_odr (TREE_TYPE (base_binfo
), TREE_TYPE (fld
)))
12398 found_binfo
= base_binfo
;
12402 binfo
= found_binfo
;
12404 binfo
= lookup_binfo_at_offset (binfo
, TREE_TYPE (fld
),
12408 type
= TREE_TYPE (fld
);
12413 /* Returns true if X is a typedef decl. */
12416 is_typedef_decl (const_tree x
)
12418 return (x
&& TREE_CODE (x
) == TYPE_DECL
12419 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
12422 /* Returns true iff TYPE is a type variant created for a typedef. */
12425 typedef_variant_p (const_tree type
)
12427 return is_typedef_decl (TYPE_NAME (type
));
12430 /* Warn about a use of an identifier which was marked deprecated. */
12432 warn_deprecated_use (tree node
, tree attr
)
12436 if (node
== 0 || !warn_deprecated_decl
)
12442 attr
= DECL_ATTRIBUTES (node
);
12443 else if (TYPE_P (node
))
12445 tree decl
= TYPE_STUB_DECL (node
);
12447 attr
= lookup_attribute ("deprecated",
12448 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
12453 attr
= lookup_attribute ("deprecated", attr
);
12456 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
12464 w
= warning (OPT_Wdeprecated_declarations
,
12465 "%qD is deprecated: %s", node
, msg
);
12467 w
= warning (OPT_Wdeprecated_declarations
,
12468 "%qD is deprecated", node
);
12470 inform (DECL_SOURCE_LOCATION (node
), "declared here");
12472 else if (TYPE_P (node
))
12474 tree what
= NULL_TREE
;
12475 tree decl
= TYPE_STUB_DECL (node
);
12477 if (TYPE_NAME (node
))
12479 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
12480 what
= TYPE_NAME (node
);
12481 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
12482 && DECL_NAME (TYPE_NAME (node
)))
12483 what
= DECL_NAME (TYPE_NAME (node
));
12491 w
= warning (OPT_Wdeprecated_declarations
,
12492 "%qE is deprecated: %s", what
, msg
);
12494 w
= warning (OPT_Wdeprecated_declarations
,
12495 "%qE is deprecated", what
);
12500 w
= warning (OPT_Wdeprecated_declarations
,
12501 "type is deprecated: %s", msg
);
12503 w
= warning (OPT_Wdeprecated_declarations
,
12504 "type is deprecated");
12507 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
12514 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
12517 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
12522 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
12525 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
12531 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12532 somewhere in it. */
12535 contains_bitfld_component_ref_p (const_tree ref
)
12537 while (handled_component_p (ref
))
12539 if (TREE_CODE (ref
) == COMPONENT_REF
12540 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
12542 ref
= TREE_OPERAND (ref
, 0);
12548 /* Try to determine whether a TRY_CATCH expression can fall through.
12549 This is a subroutine of block_may_fallthru. */
12552 try_catch_may_fallthru (const_tree stmt
)
12554 tree_stmt_iterator i
;
12556 /* If the TRY block can fall through, the whole TRY_CATCH can
12558 if (block_may_fallthru (TREE_OPERAND (stmt
, 0)))
12561 i
= tsi_start (TREE_OPERAND (stmt
, 1));
12562 switch (TREE_CODE (tsi_stmt (i
)))
12565 /* We expect to see a sequence of CATCH_EXPR trees, each with a
12566 catch expression and a body. The whole TRY_CATCH may fall
12567 through iff any of the catch bodies falls through. */
12568 for (; !tsi_end_p (i
); tsi_next (&i
))
12570 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i
))))
12575 case EH_FILTER_EXPR
:
12576 /* The exception filter expression only matters if there is an
12577 exception. If the exception does not match EH_FILTER_TYPES,
12578 we will execute EH_FILTER_FAILURE, and we will fall through
12579 if that falls through. If the exception does match
12580 EH_FILTER_TYPES, the stack unwinder will continue up the
12581 stack, so we will not fall through. We don't know whether we
12582 will throw an exception which matches EH_FILTER_TYPES or not,
12583 so we just ignore EH_FILTER_TYPES and assume that we might
12584 throw an exception which doesn't match. */
12585 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i
)));
12588 /* This case represents statements to be executed when an
12589 exception occurs. Those statements are implicitly followed
12590 by a RESX statement to resume execution after the exception.
12591 So in this case the TRY_CATCH never falls through. */
12596 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12597 need not be 100% accurate; simply be conservative and return true if we
12598 don't know. This is used only to avoid stupidly generating extra code.
12599 If we're wrong, we'll just delete the extra code later. */
12602 block_may_fallthru (const_tree block
)
12604 /* This CONST_CAST is okay because expr_last returns its argument
12605 unmodified and we assign it to a const_tree. */
12606 const_tree stmt
= expr_last (CONST_CAST_TREE (block
));
12608 switch (stmt
? TREE_CODE (stmt
) : ERROR_MARK
)
12612 /* Easy cases. If the last statement of the block implies
12613 control transfer, then we can't fall through. */
12617 /* If SWITCH_LABELS is set, this is lowered, and represents a
12618 branch to a selected label and hence can not fall through.
12619 Otherwise SWITCH_BODY is set, and the switch can fall
12621 return SWITCH_LABELS (stmt
) == NULL_TREE
;
12624 if (block_may_fallthru (COND_EXPR_THEN (stmt
)))
12626 return block_may_fallthru (COND_EXPR_ELSE (stmt
));
12629 return block_may_fallthru (BIND_EXPR_BODY (stmt
));
12631 case TRY_CATCH_EXPR
:
12632 return try_catch_may_fallthru (stmt
);
12634 case TRY_FINALLY_EXPR
:
12635 /* The finally clause is always executed after the try clause,
12636 so if it does not fall through, then the try-finally will not
12637 fall through. Otherwise, if the try clause does not fall
12638 through, then when the finally clause falls through it will
12639 resume execution wherever the try clause was going. So the
12640 whole try-finally will only fall through if both the try
12641 clause and the finally clause fall through. */
12642 return (block_may_fallthru (TREE_OPERAND (stmt
, 0))
12643 && block_may_fallthru (TREE_OPERAND (stmt
, 1)));
12646 if (TREE_CODE (TREE_OPERAND (stmt
, 1)) == CALL_EXPR
)
12647 stmt
= TREE_OPERAND (stmt
, 1);
12653 /* Functions that do not return do not fall through. */
12654 return (call_expr_flags (stmt
) & ECF_NORETURN
) == 0;
12656 case CLEANUP_POINT_EXPR
:
12657 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
12660 return block_may_fallthru (TREE_OPERAND (stmt
, 1));
12666 return lang_hooks
.block_may_fallthru (stmt
);
12670 /* True if we are using EH to handle cleanups. */
12671 static bool using_eh_for_cleanups_flag
= false;
12673 /* This routine is called from front ends to indicate eh should be used for
12676 using_eh_for_cleanups (void)
12678 using_eh_for_cleanups_flag
= true;
12681 /* Query whether EH is used for cleanups. */
12683 using_eh_for_cleanups_p (void)
12685 return using_eh_for_cleanups_flag
;
12688 /* Wrapper for tree_code_name to ensure that tree code is valid */
12690 get_tree_code_name (enum tree_code code
)
12692 const char *invalid
= "<invalid tree code>";
12694 if (code
>= MAX_TREE_CODES
)
12697 return tree_code_name
[code
];
12700 /* Drops the TREE_OVERFLOW flag from T. */
12703 drop_tree_overflow (tree t
)
12705 gcc_checking_assert (TREE_OVERFLOW (t
));
12707 /* For tree codes with a sharing machinery re-build the result. */
12708 if (TREE_CODE (t
) == INTEGER_CST
)
12709 return wide_int_to_tree (TREE_TYPE (t
), t
);
12711 /* Otherwise, as all tcc_constants are possibly shared, copy the node
12712 and drop the flag. */
12714 TREE_OVERFLOW (t
) = 0;
12718 /* Given a memory reference expression T, return its base address.
12719 The base address of a memory reference expression is the main
12720 object being referenced. For instance, the base address for
12721 'array[i].fld[j]' is 'array'. You can think of this as stripping
12722 away the offset part from a memory address.
12724 This function calls handled_component_p to strip away all the inner
12725 parts of the memory reference until it reaches the base object. */
12728 get_base_address (tree t
)
12730 while (handled_component_p (t
))
12731 t
= TREE_OPERAND (t
, 0);
12733 if ((TREE_CODE (t
) == MEM_REF
12734 || TREE_CODE (t
) == TARGET_MEM_REF
)
12735 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
12736 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
12738 /* ??? Either the alias oracle or all callers need to properly deal
12739 with WITH_SIZE_EXPRs before we can look through those. */
12740 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
12746 /* Return a tree of sizetype representing the size, in bytes, of the element
12747 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12750 array_ref_element_size (tree exp
)
12752 tree aligned_size
= TREE_OPERAND (exp
, 3);
12753 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12754 location_t loc
= EXPR_LOCATION (exp
);
12756 /* If a size was specified in the ARRAY_REF, it's the size measured
12757 in alignment units of the element type. So multiply by that value. */
12760 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12761 sizetype from another type of the same width and signedness. */
12762 if (TREE_TYPE (aligned_size
) != sizetype
)
12763 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
12764 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
12765 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
12768 /* Otherwise, take the size from that of the element type. Substitute
12769 any PLACEHOLDER_EXPR that we have. */
12771 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
12774 /* Return a tree representing the lower bound of the array mentioned in
12775 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12778 array_ref_low_bound (tree exp
)
12780 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12782 /* If a lower bound is specified in EXP, use it. */
12783 if (TREE_OPERAND (exp
, 2))
12784 return TREE_OPERAND (exp
, 2);
12786 /* Otherwise, if there is a domain type and it has a lower bound, use it,
12787 substituting for a PLACEHOLDER_EXPR as needed. */
12788 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
12789 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
12791 /* Otherwise, return a zero of the appropriate type. */
12792 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
12795 /* Return a tree representing the upper bound of the array mentioned in
12796 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12799 array_ref_up_bound (tree exp
)
12801 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12803 /* If there is a domain type and it has an upper bound, use it, substituting
12804 for a PLACEHOLDER_EXPR as needed. */
12805 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
12806 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
12808 /* Otherwise fail. */
12812 /* Returns true if REF is an array reference to an array at the end of
12813 a structure. If this is the case, the array may be allocated larger
12814 than its upper bound implies. */
12817 array_at_struct_end_p (tree ref
)
12819 if (TREE_CODE (ref
) != ARRAY_REF
12820 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
12823 while (handled_component_p (ref
))
12825 /* If the reference chain contains a component reference to a
12826 non-union type and there follows another field the reference
12827 is not at the end of a structure. */
12828 if (TREE_CODE (ref
) == COMPONENT_REF
12829 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
12831 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
12832 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
12833 nextf
= DECL_CHAIN (nextf
);
12838 ref
= TREE_OPERAND (ref
, 0);
12841 /* If the reference is based on a declared entity, the size of the array
12842 is constrained by its given domain. */
12849 /* Return a tree representing the offset, in bytes, of the field referenced
12850 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
12853 component_ref_field_offset (tree exp
)
12855 tree aligned_offset
= TREE_OPERAND (exp
, 2);
12856 tree field
= TREE_OPERAND (exp
, 1);
12857 location_t loc
= EXPR_LOCATION (exp
);
12859 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
12860 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
12862 if (aligned_offset
)
12864 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12865 sizetype from another type of the same width and signedness. */
12866 if (TREE_TYPE (aligned_offset
) != sizetype
)
12867 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
12868 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
12869 size_int (DECL_OFFSET_ALIGN (field
)
12873 /* Otherwise, take the offset from that of the field. Substitute
12874 any PLACEHOLDER_EXPR that we have. */
12876 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
12879 /* Return the machine mode of T. For vectors, returns the mode of the
12880 inner type. The main use case is to feed the result to HONOR_NANS,
12881 avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
12884 element_mode (const_tree t
)
12888 if (VECTOR_TYPE_P (t
) || TREE_CODE (t
) == COMPLEX_TYPE
)
12890 return TYPE_MODE (t
);
12894 /* Veirfy that basic properties of T match TV and thus T can be a variant of
12895 TV. TV should be the more specified variant (i.e. the main variant). */
12898 verify_type_variant (const_tree t
, tree tv
)
12900 /* Type variant can differ by:
12902 - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
12903 ENCODE_QUAL_ADDR_SPACE.
12904 - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
12905 in this case some values may not be set in the variant types
12906 (see TYPE_COMPLETE_P checks).
12907 - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
12908 - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
12909 - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
12910 - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
12911 - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
12912 this is necessary to make it possible to merge types form different TUs
12913 - arrays, pointers and references may have TREE_TYPE that is a variant
12914 of TREE_TYPE of their main variants.
12915 - aggregates may have new TYPE_FIELDS list that list variants of
12916 the main variant TYPE_FIELDS.
12917 - vector types may differ by TYPE_VECTOR_OPAQUE
12918 - TYPE_METHODS is always NULL for vairant types and maintained for
12922 /* Convenience macro for matching individual fields. */
12923 #define verify_variant_match(flag) \
12925 if (flag (tv) != flag (t)) \
12927 error ("type variant differs by " #flag "."); \
12933 /* tree_base checks. */
12935 verify_variant_match (TREE_CODE
);
12936 /* FIXME: Ada builds non-artificial variants of artificial types. */
12937 if (TYPE_ARTIFICIAL (tv
) && 0)
12938 verify_variant_match (TYPE_ARTIFICIAL
);
12939 if (POINTER_TYPE_P (tv
))
12940 verify_variant_match (TYPE_REF_CAN_ALIAS_ALL
);
12941 /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
12942 verify_variant_match (TYPE_UNSIGNED
);
12943 verify_variant_match (TYPE_ALIGN_OK
);
12944 verify_variant_match (TYPE_PACKED
);
12945 if (TREE_CODE (t
) == REFERENCE_TYPE
)
12946 verify_variant_match (TYPE_REF_IS_RVALUE
);
12947 if (AGGREGATE_TYPE_P (t
))
12948 verify_variant_match (TYPE_REVERSE_STORAGE_ORDER
);
12950 verify_variant_match (TYPE_SATURATING
);
12951 /* FIXME: This check trigger during libstdc++ build. */
12952 if (RECORD_OR_UNION_TYPE_P (t
) && COMPLETE_TYPE_P (t
) && 0)
12953 verify_variant_match (TYPE_FINAL_P
);
12955 /* tree_type_common checks. */
12957 if (COMPLETE_TYPE_P (t
))
12959 verify_variant_match (TYPE_SIZE
);
12960 verify_variant_match (TYPE_MODE
);
12961 if (TYPE_SIZE_UNIT (t
) != TYPE_SIZE_UNIT (tv
)
12962 /* FIXME: ideally we should compare pointer equality, but java FE
12963 produce variants where size is INTEGER_CST of different type (int
12964 wrt size_type) during libjava biuld. */
12965 && !operand_equal_p (TYPE_SIZE_UNIT (t
), TYPE_SIZE_UNIT (tv
), 0))
12967 error ("type variant has different TYPE_SIZE_UNIT");
12969 error ("type variant's TYPE_SIZE_UNIT");
12970 debug_tree (TYPE_SIZE_UNIT (tv
));
12971 error ("type's TYPE_SIZE_UNIT");
12972 debug_tree (TYPE_SIZE_UNIT (t
));
12976 verify_variant_match (TYPE_PRECISION
);
12977 verify_variant_match (TYPE_NEEDS_CONSTRUCTING
);
12978 if (RECORD_OR_UNION_TYPE_P (t
))
12979 verify_variant_match (TYPE_TRANSPARENT_AGGR
);
12980 else if (TREE_CODE (t
) == ARRAY_TYPE
)
12981 verify_variant_match (TYPE_NONALIASED_COMPONENT
);
12982 /* During LTO we merge variant lists from diferent translation units
12983 that may differ BY TYPE_CONTEXT that in turn may point
12984 to TRANSLATION_UNIT_DECL.
12985 Ada also builds variants of types with different TYPE_CONTEXT. */
12986 if ((!in_lto_p
|| !TYPE_FILE_SCOPE_P (t
)) && 0)
12987 verify_variant_match (TYPE_CONTEXT
);
12988 verify_variant_match (TYPE_STRING_FLAG
);
12989 if (TYPE_ALIAS_SET_KNOWN_P (t
) && TYPE_ALIAS_SET_KNOWN_P (tv
))
12990 verify_variant_match (TYPE_ALIAS_SET
);
12992 /* tree_type_non_common checks. */
12994 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
12995 and dangle the pointer from time to time. */
12996 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_VFIELD (t
) != TYPE_VFIELD (tv
)
12997 && (in_lto_p
|| !TYPE_VFIELD (tv
)
12998 || TREE_CODE (TYPE_VFIELD (tv
)) != TREE_LIST
))
13000 error ("type variant has different TYPE_VFIELD");
13004 if ((TREE_CODE (t
) == ENUMERAL_TYPE
&& COMPLETE_TYPE_P (t
))
13005 || TREE_CODE (t
) == INTEGER_TYPE
13006 || TREE_CODE (t
) == BOOLEAN_TYPE
13007 || TREE_CODE (t
) == REAL_TYPE
13008 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13010 verify_variant_match (TYPE_MAX_VALUE
);
13011 verify_variant_match (TYPE_MIN_VALUE
);
13013 if (TREE_CODE (t
) == METHOD_TYPE
)
13014 verify_variant_match (TYPE_METHOD_BASETYPE
);
13015 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_METHODS (t
))
13017 error ("type variant has TYPE_METHODS");
13021 if (TREE_CODE (t
) == OFFSET_TYPE
)
13022 verify_variant_match (TYPE_OFFSET_BASETYPE
);
13023 if (TREE_CODE (t
) == ARRAY_TYPE
)
13024 verify_variant_match (TYPE_ARRAY_MAX_SIZE
);
13025 /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13026 or even type's main variant. This is needed to make bootstrap pass
13027 and the bug seems new in GCC 5.
13028 C++ FE should be updated to make this consistent and we should check
13029 that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13030 is a match with main variant.
13032 Also disable the check for Java for now because of parser hack that builds
13033 first an dummy BINFO and then sometimes replace it by real BINFO in some
13035 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
) && TYPE_BINFO (tv
)
13036 && TYPE_BINFO (t
) != TYPE_BINFO (tv
)
13037 /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13038 Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13039 at LTO time only. */
13040 && (in_lto_p
&& odr_type_p (t
)))
13042 error ("type variant has different TYPE_BINFO");
13044 error ("type variant's TYPE_BINFO");
13045 debug_tree (TYPE_BINFO (tv
));
13046 error ("type's TYPE_BINFO");
13047 debug_tree (TYPE_BINFO (t
));
13051 /* Check various uses of TYPE_VALUES_RAW. */
13052 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
13053 verify_variant_match (TYPE_VALUES
);
13054 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13055 verify_variant_match (TYPE_DOMAIN
);
13056 /* Permit incomplete variants of complete type. While FEs may complete
13057 all variants, this does not happen for C++ templates in all cases. */
13058 else if (RECORD_OR_UNION_TYPE_P (t
)
13059 && COMPLETE_TYPE_P (t
)
13060 && TYPE_FIELDS (t
) != TYPE_FIELDS (tv
))
13064 /* Fortran builds qualified variants as new records with items of
13065 qualified type. Verify that they looks same. */
13066 for (f1
= TYPE_FIELDS (t
), f2
= TYPE_FIELDS (tv
);
13068 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
13069 if (TREE_CODE (f1
) != FIELD_DECL
|| TREE_CODE (f2
) != FIELD_DECL
13070 || (TYPE_MAIN_VARIANT (TREE_TYPE (f1
))
13071 != TYPE_MAIN_VARIANT (TREE_TYPE (f2
))
13072 /* FIXME: gfc_nonrestricted_type builds all types as variants
13073 with exception of pointer types. It deeply copies the type
13074 which means that we may end up with a variant type
13075 referring non-variant pointer. We may change it to
13076 produce types as variants, too, like
13077 objc_get_protocol_qualified_type does. */
13078 && !POINTER_TYPE_P (TREE_TYPE (f1
)))
13079 || DECL_FIELD_OFFSET (f1
) != DECL_FIELD_OFFSET (f2
)
13080 || DECL_FIELD_BIT_OFFSET (f1
) != DECL_FIELD_BIT_OFFSET (f2
))
13084 error ("type variant has different TYPE_FIELDS");
13086 error ("first mismatch is field");
13088 error ("and field");
13093 else if ((TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
))
13094 verify_variant_match (TYPE_ARG_TYPES
);
13095 /* For C++ the qualified variant of array type is really an array type
13096 of qualified TREE_TYPE.
13097 objc builds variants of pointer where pointer to type is a variant, too
13098 in objc_get_protocol_qualified_type. */
13099 if (TREE_TYPE (t
) != TREE_TYPE (tv
)
13100 && ((TREE_CODE (t
) != ARRAY_TYPE
13101 && !POINTER_TYPE_P (t
))
13102 || TYPE_MAIN_VARIANT (TREE_TYPE (t
))
13103 != TYPE_MAIN_VARIANT (TREE_TYPE (tv
))))
13105 error ("type variant has different TREE_TYPE");
13107 error ("type variant's TREE_TYPE");
13108 debug_tree (TREE_TYPE (tv
));
13109 error ("type's TREE_TYPE");
13110 debug_tree (TREE_TYPE (t
));
13113 if (type_with_alias_set_p (t
)
13114 && !gimple_canonical_types_compatible_p (t
, tv
, false))
13116 error ("type is not compatible with its vairant");
13118 error ("type variant's TREE_TYPE");
13119 debug_tree (TREE_TYPE (tv
));
13120 error ("type's TREE_TYPE");
13121 debug_tree (TREE_TYPE (t
));
13125 #undef verify_variant_match
13129 /* The TYPE_CANONICAL merging machinery. It should closely resemble
13130 the middle-end types_compatible_p function. It needs to avoid
13131 claiming types are different for types that should be treated
13132 the same with respect to TBAA. Canonical types are also used
13133 for IL consistency checks via the useless_type_conversion_p
13134 predicate which does not handle all type kinds itself but falls
13135 back to pointer-comparison of TYPE_CANONICAL for aggregates
13138 /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13139 type calculation because we need to allow inter-operability between signed
13140 and unsigned variants. */
13143 type_with_interoperable_signedness (const_tree type
)
13145 /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13146 signed char and unsigned char. Similarly fortran FE builds
13147 C_SIZE_T as signed type, while C defines it unsigned. */
13149 return tree_code_for_canonical_type_merging (TREE_CODE (type
))
13151 && (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
)
13152 || TYPE_PRECISION (type
) == TYPE_PRECISION (size_type_node
));
13155 /* Return true iff T1 and T2 are structurally identical for what
13157 This function is used both by lto.c canonical type merging and by the
13158 verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13159 that have TYPE_CANONICAL defined and assume them equivalent. */
13162 gimple_canonical_types_compatible_p (const_tree t1
, const_tree t2
,
13163 bool trust_type_canonical
)
13165 /* Type variants should be same as the main variant. When not doing sanity
13166 checking to verify this fact, go to main variants and save some work. */
13167 if (trust_type_canonical
)
13169 t1
= TYPE_MAIN_VARIANT (t1
);
13170 t2
= TYPE_MAIN_VARIANT (t2
);
13173 /* Check first for the obvious case of pointer identity. */
13177 /* Check that we have two types to compare. */
13178 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
13181 /* We consider complete types always compatible with incomplete type.
13182 This does not make sense for canonical type calculation and thus we
13183 need to ensure that we are never called on it.
13185 FIXME: For more correctness the function probably should have three modes
13186 1) mode assuming that types are complete mathcing their structure
13187 2) mode allowing incomplete types but producing equivalence classes
13188 and thus ignoring all info from complete types
13189 3) mode allowing incomplete types to match complete but checking
13190 compatibility between complete types.
13192 1 and 2 can be used for canonical type calculation. 3 is the real
13193 definition of type compatibility that can be used i.e. for warnings during
13194 declaration merging. */
13196 gcc_assert (!trust_type_canonical
13197 || (type_with_alias_set_p (t1
) && type_with_alias_set_p (t2
)));
13198 /* If the types have been previously registered and found equal
13200 if (TYPE_CANONICAL (t1
) && TYPE_CANONICAL (t2
)
13201 && trust_type_canonical
)
13202 return TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
);
13204 /* Can't be the same type if the types don't have the same code. */
13205 enum tree_code code
= tree_code_for_canonical_type_merging (TREE_CODE (t1
));
13206 if (code
!= tree_code_for_canonical_type_merging (TREE_CODE (t2
)))
13209 /* Qualifiers do not matter for canonical type comparison purposes. */
13211 /* Void types and nullptr types are always the same. */
13212 if (TREE_CODE (t1
) == VOID_TYPE
13213 || TREE_CODE (t1
) == NULLPTR_TYPE
)
13216 /* Can't be the same type if they have different mode. */
13217 if (TYPE_MODE (t1
) != TYPE_MODE (t2
))
13220 /* Non-aggregate types can be handled cheaply. */
13221 if (INTEGRAL_TYPE_P (t1
)
13222 || SCALAR_FLOAT_TYPE_P (t1
)
13223 || FIXED_POINT_TYPE_P (t1
)
13224 || TREE_CODE (t1
) == VECTOR_TYPE
13225 || TREE_CODE (t1
) == COMPLEX_TYPE
13226 || TREE_CODE (t1
) == OFFSET_TYPE
13227 || POINTER_TYPE_P (t1
))
13229 /* Can't be the same type if they have different recision. */
13230 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
))
13233 /* In some cases the signed and unsigned types are required to be
13235 if (TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
)
13236 && !type_with_interoperable_signedness (t1
))
13239 /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
13240 interoperable with "signed char". Unless all frontends are revisited
13241 to agree on these types, we must ignore the flag completely. */
13243 /* Fortran standard define C_PTR type that is compatible with every
13244 C pointer. For this reason we need to glob all pointers into one.
13245 Still pointers in different address spaces are not compatible. */
13246 if (POINTER_TYPE_P (t1
))
13248 if (TYPE_ADDR_SPACE (TREE_TYPE (t1
))
13249 != TYPE_ADDR_SPACE (TREE_TYPE (t2
)))
13253 /* Tail-recurse to components. */
13254 if (TREE_CODE (t1
) == VECTOR_TYPE
13255 || TREE_CODE (t1
) == COMPLEX_TYPE
)
13256 return gimple_canonical_types_compatible_p (TREE_TYPE (t1
),
13258 trust_type_canonical
);
13263 /* Do type-specific comparisons. */
13264 switch (TREE_CODE (t1
))
13267 /* Array types are the same if the element types are the same and
13268 the number of elements are the same. */
13269 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13270 trust_type_canonical
)
13271 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
13272 || TYPE_REVERSE_STORAGE_ORDER (t1
) != TYPE_REVERSE_STORAGE_ORDER (t2
)
13273 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
13277 tree i1
= TYPE_DOMAIN (t1
);
13278 tree i2
= TYPE_DOMAIN (t2
);
13280 /* For an incomplete external array, the type domain can be
13281 NULL_TREE. Check this condition also. */
13282 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
13284 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
13288 tree min1
= TYPE_MIN_VALUE (i1
);
13289 tree min2
= TYPE_MIN_VALUE (i2
);
13290 tree max1
= TYPE_MAX_VALUE (i1
);
13291 tree max2
= TYPE_MAX_VALUE (i2
);
13293 /* The minimum/maximum values have to be the same. */
13296 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
13297 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
13298 || operand_equal_p (min1
, min2
, 0))))
13301 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
13302 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
13303 || operand_equal_p (max1
, max2
, 0)))))
13311 case FUNCTION_TYPE
:
13312 /* Function types are the same if the return type and arguments types
13314 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13315 trust_type_canonical
))
13318 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
13322 tree parms1
, parms2
;
13324 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
13326 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
13328 if (!gimple_canonical_types_compatible_p
13329 (TREE_VALUE (parms1
), TREE_VALUE (parms2
),
13330 trust_type_canonical
))
13334 if (parms1
|| parms2
)
13342 case QUAL_UNION_TYPE
:
13346 if (TYPE_REVERSE_STORAGE_ORDER (t1
) != TYPE_REVERSE_STORAGE_ORDER (t2
))
13349 /* For aggregate types, all the fields must be the same. */
13350 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
13352 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
13354 /* Skip non-fields. */
13355 while (f1
&& TREE_CODE (f1
) != FIELD_DECL
)
13356 f1
= TREE_CHAIN (f1
);
13357 while (f2
&& TREE_CODE (f2
) != FIELD_DECL
)
13358 f2
= TREE_CHAIN (f2
);
13361 /* The fields must have the same name, offset and type. */
13362 if (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
13363 || !gimple_compare_field_offset (f1
, f2
)
13364 || !gimple_canonical_types_compatible_p
13365 (TREE_TYPE (f1
), TREE_TYPE (f2
),
13366 trust_type_canonical
))
13370 /* If one aggregate has more fields than the other, they
13371 are not the same. */
13379 /* Consider all types with language specific trees in them mutually
13380 compatible. This is executed only from verify_type and false
13381 positives can be tolerated. */
13382 gcc_assert (!in_lto_p
);
13387 /* Verify type T. */
13390 verify_type (const_tree t
)
13392 bool error_found
= false;
13393 tree mv
= TYPE_MAIN_VARIANT (t
);
13396 error ("Main variant is not defined");
13397 error_found
= true;
13399 else if (mv
!= TYPE_MAIN_VARIANT (mv
))
13401 error ("TYPE_MAIN_VARIANT has different TYPE_MAIN_VARIANT");
13403 error_found
= true;
13405 else if (t
!= mv
&& !verify_type_variant (t
, mv
))
13406 error_found
= true;
13408 tree ct
= TYPE_CANONICAL (t
);
13411 else if (TYPE_CANONICAL (t
) != ct
)
13413 error ("TYPE_CANONICAL has different TYPE_CANONICAL");
13415 error_found
= true;
13417 /* Method and function types can not be used to address memory and thus
13418 TYPE_CANONICAL really matters only for determining useless conversions.
13420 FIXME: C++ FE produce declarations of builtin functions that are not
13421 compatible with main variants. */
13422 else if (TREE_CODE (t
) == FUNCTION_TYPE
)
13425 /* FIXME: gimple_canonical_types_compatible_p can not compare types
13426 with variably sized arrays because their sizes possibly
13427 gimplified to different variables. */
13428 && !variably_modified_type_p (ct
, NULL
)
13429 && !gimple_canonical_types_compatible_p (t
, ct
, false))
13431 error ("TYPE_CANONICAL is not compatible");
13433 error_found
= true;
13436 if (COMPLETE_TYPE_P (t
) && TYPE_CANONICAL (t
)
13437 && TYPE_MODE (t
) != TYPE_MODE (TYPE_CANONICAL (t
)))
13439 error ("TYPE_MODE of TYPE_CANONICAL is not compatible");
13441 error_found
= true;
13445 /* Check various uses of TYPE_MINVAL. */
13446 if (RECORD_OR_UNION_TYPE_P (t
))
13448 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13449 and danagle the pointer from time to time. */
13450 if (TYPE_VFIELD (t
)
13451 && TREE_CODE (TYPE_VFIELD (t
)) != FIELD_DECL
13452 && TREE_CODE (TYPE_VFIELD (t
)) != TREE_LIST
)
13454 error ("TYPE_VFIELD is not FIELD_DECL nor TREE_LIST");
13455 debug_tree (TYPE_VFIELD (t
));
13456 error_found
= true;
13459 else if (TREE_CODE (t
) == POINTER_TYPE
)
13461 if (TYPE_NEXT_PTR_TO (t
)
13462 && TREE_CODE (TYPE_NEXT_PTR_TO (t
)) != POINTER_TYPE
)
13464 error ("TYPE_NEXT_PTR_TO is not POINTER_TYPE");
13465 debug_tree (TYPE_NEXT_PTR_TO (t
));
13466 error_found
= true;
13469 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
13471 if (TYPE_NEXT_REF_TO (t
)
13472 && TREE_CODE (TYPE_NEXT_REF_TO (t
)) != REFERENCE_TYPE
)
13474 error ("TYPE_NEXT_REF_TO is not REFERENCE_TYPE");
13475 debug_tree (TYPE_NEXT_REF_TO (t
));
13476 error_found
= true;
13479 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13480 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13482 /* FIXME: The following check should pass:
13483 useless_type_conversion_p (const_cast <tree> (t),
13484 TREE_TYPE (TYPE_MIN_VALUE (t))
13485 but does not for C sizetypes in LTO. */
13487 /* Java uses TYPE_MINVAL for TYPE_ARGUMENT_SIGNATURE. */
13488 else if (TYPE_MINVAL (t
)
13489 && ((TREE_CODE (t
) != METHOD_TYPE
&& TREE_CODE (t
) != FUNCTION_TYPE
)
13492 error ("TYPE_MINVAL non-NULL");
13493 debug_tree (TYPE_MINVAL (t
));
13494 error_found
= true;
13497 /* Check various uses of TYPE_MAXVAL. */
13498 if (RECORD_OR_UNION_TYPE_P (t
))
13500 if (TYPE_METHODS (t
) && TREE_CODE (TYPE_METHODS (t
)) != FUNCTION_DECL
13501 && TREE_CODE (TYPE_METHODS (t
)) != TEMPLATE_DECL
13502 && TYPE_METHODS (t
) != error_mark_node
)
13504 error ("TYPE_METHODS is not FUNCTION_DECL, TEMPLATE_DECL nor error_mark_node");
13505 debug_tree (TYPE_METHODS (t
));
13506 error_found
= true;
13509 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13511 if (TYPE_METHOD_BASETYPE (t
)
13512 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != RECORD_TYPE
13513 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != UNION_TYPE
)
13515 error ("TYPE_METHOD_BASETYPE is not record nor union");
13516 debug_tree (TYPE_METHOD_BASETYPE (t
));
13517 error_found
= true;
13520 else if (TREE_CODE (t
) == OFFSET_TYPE
)
13522 if (TYPE_OFFSET_BASETYPE (t
)
13523 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != RECORD_TYPE
13524 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != UNION_TYPE
)
13526 error ("TYPE_OFFSET_BASETYPE is not record nor union");
13527 debug_tree (TYPE_OFFSET_BASETYPE (t
));
13528 error_found
= true;
13531 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13532 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13534 /* FIXME: The following check should pass:
13535 useless_type_conversion_p (const_cast <tree> (t),
13536 TREE_TYPE (TYPE_MAX_VALUE (t))
13537 but does not for C sizetypes in LTO. */
13539 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13541 if (TYPE_ARRAY_MAX_SIZE (t
)
13542 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t
)) != INTEGER_CST
)
13544 error ("TYPE_ARRAY_MAX_SIZE not INTEGER_CST");
13545 debug_tree (TYPE_ARRAY_MAX_SIZE (t
));
13546 error_found
= true;
13549 else if (TYPE_MAXVAL (t
))
13551 error ("TYPE_MAXVAL non-NULL");
13552 debug_tree (TYPE_MAXVAL (t
));
13553 error_found
= true;
13556 /* Check various uses of TYPE_BINFO. */
13557 if (RECORD_OR_UNION_TYPE_P (t
))
13559 if (!TYPE_BINFO (t
))
13561 else if (TREE_CODE (TYPE_BINFO (t
)) != TREE_BINFO
)
13563 error ("TYPE_BINFO is not TREE_BINFO");
13564 debug_tree (TYPE_BINFO (t
));
13565 error_found
= true;
13567 /* FIXME: Java builds invalid empty binfos that do not have
13569 else if (TREE_TYPE (TYPE_BINFO (t
)) != TYPE_MAIN_VARIANT (t
) && 0)
13571 error ("TYPE_BINFO type is not TYPE_MAIN_VARIANT");
13572 debug_tree (TREE_TYPE (TYPE_BINFO (t
)));
13573 error_found
= true;
13576 else if (TYPE_LANG_SLOT_1 (t
) && in_lto_p
)
13578 error ("TYPE_LANG_SLOT_1 (binfo) field is non-NULL");
13579 debug_tree (TYPE_LANG_SLOT_1 (t
));
13580 error_found
= true;
13583 /* Check various uses of TYPE_VALUES_RAW. */
13584 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
13585 for (tree l
= TYPE_VALUES (t
); l
; l
= TREE_CHAIN (l
))
13587 tree value
= TREE_VALUE (l
);
13588 tree name
= TREE_PURPOSE (l
);
13590 /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
13591 CONST_DECL of ENUMERAL TYPE. */
13592 if (TREE_CODE (value
) != INTEGER_CST
&& TREE_CODE (value
) != CONST_DECL
)
13594 error ("Enum value is not CONST_DECL or INTEGER_CST");
13595 debug_tree (value
);
13597 error_found
= true;
13599 if (TREE_CODE (TREE_TYPE (value
)) != INTEGER_TYPE
13600 && !useless_type_conversion_p (const_cast <tree
> (t
), TREE_TYPE (value
)))
13602 error ("Enum value type is not INTEGER_TYPE nor convertible to the enum");
13603 debug_tree (value
);
13605 error_found
= true;
13607 if (TREE_CODE (name
) != IDENTIFIER_NODE
)
13609 error ("Enum value name is not IDENTIFIER_NODE");
13610 debug_tree (value
);
13612 error_found
= true;
13615 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13617 if (TYPE_DOMAIN (t
) && TREE_CODE (TYPE_DOMAIN (t
)) != INTEGER_TYPE
)
13619 error ("Array TYPE_DOMAIN is not integer type");
13620 debug_tree (TYPE_DOMAIN (t
));
13621 error_found
= true;
13624 else if (RECORD_OR_UNION_TYPE_P (t
))
13625 for (tree fld
= TYPE_FIELDS (t
); fld
; fld
= TREE_CHAIN (fld
))
13627 /* TODO: verify properties of decls. */
13628 if (TREE_CODE (fld
) == FIELD_DECL
)
13630 else if (TREE_CODE (fld
) == TYPE_DECL
)
13632 else if (TREE_CODE (fld
) == CONST_DECL
)
13634 else if (TREE_CODE (fld
) == VAR_DECL
)
13636 else if (TREE_CODE (fld
) == TEMPLATE_DECL
)
13638 else if (TREE_CODE (fld
) == USING_DECL
)
13642 error ("Wrong tree in TYPE_FIELDS list");
13644 error_found
= true;
13647 else if (TREE_CODE (t
) == INTEGER_TYPE
13648 || TREE_CODE (t
) == BOOLEAN_TYPE
13649 || TREE_CODE (t
) == OFFSET_TYPE
13650 || TREE_CODE (t
) == REFERENCE_TYPE
13651 || TREE_CODE (t
) == NULLPTR_TYPE
13652 || TREE_CODE (t
) == POINTER_TYPE
)
13654 if (TYPE_CACHED_VALUES_P (t
) != (TYPE_CACHED_VALUES (t
) != NULL
))
13656 error ("TYPE_CACHED_VALUES_P is %i while TYPE_CACHED_VALUES is %p",
13657 TYPE_CACHED_VALUES_P (t
), (void *)TYPE_CACHED_VALUES (t
));
13658 error_found
= true;
13660 else if (TYPE_CACHED_VALUES_P (t
) && TREE_CODE (TYPE_CACHED_VALUES (t
)) != TREE_VEC
)
13662 error ("TYPE_CACHED_VALUES is not TREE_VEC");
13663 debug_tree (TYPE_CACHED_VALUES (t
));
13664 error_found
= true;
13666 /* Verify just enough of cache to ensure that no one copied it to new type.
13667 All copying should go by copy_node that should clear it. */
13668 else if (TYPE_CACHED_VALUES_P (t
))
13671 for (i
= 0; i
< TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t
)); i
++)
13672 if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)
13673 && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)) != t
)
13675 error ("wrong TYPE_CACHED_VALUES entry");
13676 debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
));
13677 error_found
= true;
13682 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13683 for (tree l
= TYPE_ARG_TYPES (t
); l
; l
= TREE_CHAIN (l
))
13685 /* C++ FE uses TREE_PURPOSE to store initial values. */
13686 if (TREE_PURPOSE (l
) && in_lto_p
)
13688 error ("TREE_PURPOSE is non-NULL in TYPE_ARG_TYPES list");
13690 error_found
= true;
13692 if (!TYPE_P (TREE_VALUE (l
)))
13694 error ("Wrong entry in TYPE_ARG_TYPES list");
13696 error_found
= true;
13699 else if (!is_lang_specific (t
) && TYPE_VALUES_RAW (t
))
13701 error ("TYPE_VALUES_RAW field is non-NULL");
13702 debug_tree (TYPE_VALUES_RAW (t
));
13703 error_found
= true;
13705 if (TREE_CODE (t
) != INTEGER_TYPE
13706 && TREE_CODE (t
) != BOOLEAN_TYPE
13707 && TREE_CODE (t
) != OFFSET_TYPE
13708 && TREE_CODE (t
) != REFERENCE_TYPE
13709 && TREE_CODE (t
) != NULLPTR_TYPE
13710 && TREE_CODE (t
) != POINTER_TYPE
13711 && TYPE_CACHED_VALUES_P (t
))
13713 error ("TYPE_CACHED_VALUES_P is set while it should not");
13714 error_found
= true;
13716 if (TYPE_STRING_FLAG (t
)
13717 && TREE_CODE (t
) != ARRAY_TYPE
&& TREE_CODE (t
) != INTEGER_TYPE
)
13719 error ("TYPE_STRING_FLAG is set on wrong type code");
13720 error_found
= true;
13722 else if (TYPE_STRING_FLAG (t
))
13725 if (TREE_CODE (b
) == ARRAY_TYPE
)
13727 /* Java builds arrays with TYPE_STRING_FLAG of promoted_char_type
13729 if (TREE_CODE (b
) != INTEGER_TYPE
)
13731 error ("TYPE_STRING_FLAG is set on type that does not look like "
13732 "char nor array of chars");
13733 error_found
= true;
13737 /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
13738 TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
13740 if (TREE_CODE (t
) == METHOD_TYPE
13741 && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t
)) != TYPE_METHOD_BASETYPE (t
))
13743 error ("TYPE_METHOD_BASETYPE is not main variant");
13744 error_found
= true;
13749 debug_tree (const_cast <tree
> (t
));
13750 internal_error ("verify_type failed");
13755 /* Return true if ARG is marked with the nonnull attribute in the
13756 current function signature. */
13759 nonnull_arg_p (const_tree arg
)
13761 tree t
, attrs
, fntype
;
13762 unsigned HOST_WIDE_INT arg_num
;
13764 gcc_assert (TREE_CODE (arg
) == PARM_DECL
&& POINTER_TYPE_P (TREE_TYPE (arg
)));
13766 /* The static chain decl is always non null. */
13767 if (arg
== cfun
->static_chain_decl
)
13770 /* THIS argument of method is always non-NULL. */
13771 if (TREE_CODE (TREE_TYPE (cfun
->decl
)) == METHOD_TYPE
13772 && arg
== DECL_ARGUMENTS (cfun
->decl
)
13773 && flag_delete_null_pointer_checks
)
13776 /* Values passed by reference are always non-NULL. */
13777 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
13778 && flag_delete_null_pointer_checks
)
13781 fntype
= TREE_TYPE (cfun
->decl
);
13782 for (attrs
= TYPE_ATTRIBUTES (fntype
); attrs
; attrs
= TREE_CHAIN (attrs
))
13784 attrs
= lookup_attribute ("nonnull", attrs
);
13786 /* If "nonnull" wasn't specified, we know nothing about the argument. */
13787 if (attrs
== NULL_TREE
)
13790 /* If "nonnull" applies to all the arguments, then ARG is non-null. */
13791 if (TREE_VALUE (attrs
) == NULL_TREE
)
13794 /* Get the position number for ARG in the function signature. */
13795 for (arg_num
= 1, t
= DECL_ARGUMENTS (cfun
->decl
);
13797 t
= DECL_CHAIN (t
), arg_num
++)
13803 gcc_assert (t
== arg
);
13805 /* Now see if ARG_NUM is mentioned in the nonnull list. */
13806 for (t
= TREE_VALUE (attrs
); t
; t
= TREE_CHAIN (t
))
13808 if (compare_tree_int (TREE_VALUE (t
), arg_num
) == 0)
13817 #include "gt-tree.h"