1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2022 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"
57 #include "langhooks-def.h"
58 #include "tree-diagnostic.h"
61 #include "print-tree.h"
62 #include "ipa-utils.h"
64 #include "stringpool.h"
68 #include "tree-vector-builder.h"
69 #include "gimple-fold.h"
70 #include "escaped_string.h"
71 #include "gimple-range.h"
73 /* Tree code classes. */
75 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
76 #define END_OF_BASE_TREE_CODES tcc_exceptional,
78 const enum tree_code_class tree_code_type
[] = {
79 #include "all-tree.def"
83 #undef END_OF_BASE_TREE_CODES
85 /* Table indexed by tree code giving number of expression
86 operands beyond the fixed part of the node structure.
87 Not used for types or decls. */
89 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
90 #define END_OF_BASE_TREE_CODES 0,
92 const unsigned char tree_code_length
[] = {
93 #include "all-tree.def"
97 #undef END_OF_BASE_TREE_CODES
99 /* Names of tree components.
100 Used for printing out the tree and error messages. */
101 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
102 #define END_OF_BASE_TREE_CODES "@dummy",
104 static const char *const tree_code_name
[] = {
105 #include "all-tree.def"
109 #undef END_OF_BASE_TREE_CODES
111 /* Each tree code class has an associated string representation.
112 These must correspond to the tree_code_class entries. */
114 const char *const tree_code_class_strings
[] =
129 /* obstack.[ch] explicitly declined to prototype this. */
130 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
132 /* Statistics-gathering stuff. */
134 static uint64_t tree_code_counts
[MAX_TREE_CODES
];
135 uint64_t tree_node_counts
[(int) all_kinds
];
136 uint64_t tree_node_sizes
[(int) all_kinds
];
138 /* Keep in sync with tree.h:enum tree_node_kind. */
139 static const char * const tree_node_kind_names
[] = {
158 /* Unique id for next decl created. */
159 static GTY(()) int next_decl_uid
;
160 /* Unique id for next type created. */
161 static GTY(()) unsigned next_type_uid
= 1;
162 /* Unique id for next debug decl created. Use negative numbers,
163 to catch erroneous uses. */
164 static GTY(()) int next_debug_decl_uid
;
166 /* Since we cannot rehash a type after it is in the table, we have to
167 keep the hash code. */
169 struct GTY((for_user
)) type_hash
{
174 /* Initial size of the hash table (rounded to next prime). */
175 #define TYPE_HASH_INITIAL_SIZE 1000
177 struct type_cache_hasher
: ggc_cache_ptr_hash
<type_hash
>
179 static hashval_t
hash (type_hash
*t
) { return t
->hash
; }
180 static bool equal (type_hash
*a
, type_hash
*b
);
183 keep_cache_entry (type_hash
*&t
)
185 return ggc_marked_p (t
->type
);
189 /* Now here is the hash table. When recording a type, it is added to
190 the slot whose index is the hash code. Note that the hash table is
191 used for several kinds of types (function types, array types and
192 array index range types, for now). While all these live in the
193 same table, they are completely independent, and the hash code is
194 computed differently for each of these. */
196 static GTY ((cache
)) hash_table
<type_cache_hasher
> *type_hash_table
;
198 /* Hash table and temporary node for larger integer const values. */
199 static GTY (()) tree int_cst_node
;
201 struct int_cst_hasher
: ggc_cache_ptr_hash
<tree_node
>
203 static hashval_t
hash (tree t
);
204 static bool equal (tree x
, tree y
);
207 static GTY ((cache
)) hash_table
<int_cst_hasher
> *int_cst_hash_table
;
209 /* Class and variable for making sure that there is a single POLY_INT_CST
210 for a given value. */
211 struct poly_int_cst_hasher
: ggc_cache_ptr_hash
<tree_node
>
213 typedef std::pair
<tree
, const poly_wide_int
*> compare_type
;
214 static hashval_t
hash (tree t
);
215 static bool equal (tree x
, const compare_type
&y
);
218 static GTY ((cache
)) hash_table
<poly_int_cst_hasher
> *poly_int_cst_hash_table
;
220 /* Hash table for optimization flags and target option flags. Use the same
221 hash table for both sets of options. Nodes for building the current
222 optimization and target option nodes. The assumption is most of the time
223 the options created will already be in the hash table, so we avoid
224 allocating and freeing up a node repeatably. */
225 static GTY (()) tree cl_optimization_node
;
226 static GTY (()) tree cl_target_option_node
;
228 struct cl_option_hasher
: ggc_cache_ptr_hash
<tree_node
>
230 static hashval_t
hash (tree t
);
231 static bool equal (tree x
, tree y
);
234 static GTY ((cache
)) hash_table
<cl_option_hasher
> *cl_option_hash_table
;
236 /* General tree->tree mapping structure for use in hash tables. */
240 hash_table
<tree_decl_map_cache_hasher
> *debug_expr_for_decl
;
243 hash_table
<tree_decl_map_cache_hasher
> *value_expr_for_decl
;
246 hash_table
<tree_vec_map_cache_hasher
> *debug_args_for_decl
;
248 static void set_type_quals (tree
, int);
249 static void print_type_hash_statistics (void);
250 static void print_debug_expr_statistics (void);
251 static void print_value_expr_statistics (void);
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 bool tree_contains_struct
[MAX_TREE_CODES
][64];
261 /* Number of operands for each OMP 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 5, /* OMP_CLAUSE_TASK_REDUCTION */
271 5, /* OMP_CLAUSE_IN_REDUCTION */
272 1, /* OMP_CLAUSE_COPYIN */
273 1, /* OMP_CLAUSE_COPYPRIVATE */
274 3, /* OMP_CLAUSE_LINEAR */
275 1, /* OMP_CLAUSE_AFFINITY */
276 2, /* OMP_CLAUSE_ALIGNED */
277 3, /* OMP_CLAUSE_ALLOCATE */
278 1, /* OMP_CLAUSE_DEPEND */
279 1, /* OMP_CLAUSE_NONTEMPORAL */
280 1, /* OMP_CLAUSE_UNIFORM */
281 1, /* OMP_CLAUSE_TO_DECLARE */
282 1, /* OMP_CLAUSE_LINK */
283 1, /* OMP_CLAUSE_DETACH */
284 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
285 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
286 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
287 1, /* OMP_CLAUSE_INCLUSIVE */
288 1, /* OMP_CLAUSE_EXCLUSIVE */
289 2, /* OMP_CLAUSE_FROM */
290 2, /* OMP_CLAUSE_TO */
291 2, /* OMP_CLAUSE_MAP */
292 2, /* OMP_CLAUSE__CACHE_ */
293 2, /* OMP_CLAUSE_GANG */
294 1, /* OMP_CLAUSE_ASYNC */
295 1, /* OMP_CLAUSE_WAIT */
296 0, /* OMP_CLAUSE_AUTO */
297 0, /* OMP_CLAUSE_SEQ */
298 1, /* OMP_CLAUSE__LOOPTEMP_ */
299 1, /* OMP_CLAUSE__REDUCTEMP_ */
300 1, /* OMP_CLAUSE__CONDTEMP_ */
301 1, /* OMP_CLAUSE__SCANTEMP_ */
302 1, /* OMP_CLAUSE_IF */
303 1, /* OMP_CLAUSE_NUM_THREADS */
304 1, /* OMP_CLAUSE_SCHEDULE */
305 0, /* OMP_CLAUSE_NOWAIT */
306 1, /* OMP_CLAUSE_ORDERED */
307 0, /* OMP_CLAUSE_DEFAULT */
308 3, /* OMP_CLAUSE_COLLAPSE */
309 0, /* OMP_CLAUSE_UNTIED */
310 1, /* OMP_CLAUSE_FINAL */
311 0, /* OMP_CLAUSE_MERGEABLE */
312 1, /* OMP_CLAUSE_DEVICE */
313 1, /* OMP_CLAUSE_DIST_SCHEDULE */
314 0, /* OMP_CLAUSE_INBRANCH */
315 0, /* OMP_CLAUSE_NOTINBRANCH */
316 2, /* OMP_CLAUSE_NUM_TEAMS */
317 1, /* OMP_CLAUSE_THREAD_LIMIT */
318 0, /* OMP_CLAUSE_PROC_BIND */
319 1, /* OMP_CLAUSE_SAFELEN */
320 1, /* OMP_CLAUSE_SIMDLEN */
321 0, /* OMP_CLAUSE_DEVICE_TYPE */
322 0, /* OMP_CLAUSE_FOR */
323 0, /* OMP_CLAUSE_PARALLEL */
324 0, /* OMP_CLAUSE_SECTIONS */
325 0, /* OMP_CLAUSE_TASKGROUP */
326 1, /* OMP_CLAUSE_PRIORITY */
327 1, /* OMP_CLAUSE_GRAINSIZE */
328 1, /* OMP_CLAUSE_NUM_TASKS */
329 0, /* OMP_CLAUSE_NOGROUP */
330 0, /* OMP_CLAUSE_THREADS */
331 0, /* OMP_CLAUSE_SIMD */
332 1, /* OMP_CLAUSE_HINT */
333 0, /* OMP_CLAUSE_DEFAULTMAP */
334 0, /* OMP_CLAUSE_ORDER */
335 0, /* OMP_CLAUSE_BIND */
336 1, /* OMP_CLAUSE_FILTER */
337 1, /* OMP_CLAUSE__SIMDUID_ */
338 0, /* OMP_CLAUSE__SIMT_ */
339 0, /* OMP_CLAUSE_INDEPENDENT */
340 1, /* OMP_CLAUSE_WORKER */
341 1, /* OMP_CLAUSE_VECTOR */
342 1, /* OMP_CLAUSE_NUM_GANGS */
343 1, /* OMP_CLAUSE_NUM_WORKERS */
344 1, /* OMP_CLAUSE_VECTOR_LENGTH */
345 3, /* OMP_CLAUSE_TILE */
346 0, /* OMP_CLAUSE_IF_PRESENT */
347 0, /* OMP_CLAUSE_FINALIZE */
348 0, /* OMP_CLAUSE_NOHOST */
351 const char * const omp_clause_code_name
[] =
441 /* Return the tree node structure used by tree code CODE. */
443 static inline enum tree_node_structure_enum
444 tree_node_structure_for_code (enum tree_code code
)
446 switch (TREE_CODE_CLASS (code
))
448 case tcc_declaration
:
451 case CONST_DECL
: return TS_CONST_DECL
;
452 case DEBUG_EXPR_DECL
: return TS_DECL_WRTL
;
453 case FIELD_DECL
: return TS_FIELD_DECL
;
454 case FUNCTION_DECL
: return TS_FUNCTION_DECL
;
455 case LABEL_DECL
: return TS_LABEL_DECL
;
456 case PARM_DECL
: return TS_PARM_DECL
;
457 case RESULT_DECL
: return TS_RESULT_DECL
;
458 case TRANSLATION_UNIT_DECL
: return TS_TRANSLATION_UNIT_DECL
;
459 case TYPE_DECL
: return TS_TYPE_DECL
;
460 case VAR_DECL
: return TS_VAR_DECL
;
461 default: return TS_DECL_NON_COMMON
;
464 case tcc_type
: return TS_TYPE_NON_COMMON
;
472 case tcc_vl_exp
: return TS_EXP
;
474 default: /* tcc_constant and tcc_exceptional */
480 /* tcc_constant cases. */
481 case COMPLEX_CST
: return TS_COMPLEX
;
482 case FIXED_CST
: return TS_FIXED_CST
;
483 case INTEGER_CST
: return TS_INT_CST
;
484 case POLY_INT_CST
: return TS_POLY_INT_CST
;
485 case REAL_CST
: return TS_REAL_CST
;
486 case STRING_CST
: return TS_STRING
;
487 case VECTOR_CST
: return TS_VECTOR
;
488 case VOID_CST
: return TS_TYPED
;
490 /* tcc_exceptional cases. */
491 case BLOCK
: return TS_BLOCK
;
492 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
493 case ERROR_MARK
: return TS_COMMON
;
494 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
495 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
496 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
497 case PLACEHOLDER_EXPR
: return TS_COMMON
;
498 case SSA_NAME
: return TS_SSA_NAME
;
499 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
500 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
501 case TREE_BINFO
: return TS_BINFO
;
502 case TREE_LIST
: return TS_LIST
;
503 case TREE_VEC
: return TS_VEC
;
511 /* Initialize tree_contains_struct to describe the hierarchy of tree
515 initialize_tree_contains_struct (void)
519 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
522 enum tree_node_structure_enum ts_code
;
524 code
= (enum tree_code
) i
;
525 ts_code
= tree_node_structure_for_code (code
);
527 /* Mark the TS structure itself. */
528 tree_contains_struct
[code
][ts_code
] = 1;
530 /* Mark all the structures that TS is derived from. */
535 case TS_OPTIMIZATION
:
536 case TS_TARGET_OPTION
:
542 case TS_POLY_INT_CST
:
551 case TS_STATEMENT_LIST
:
552 MARK_TS_TYPED (code
);
556 case TS_DECL_MINIMAL
:
562 MARK_TS_COMMON (code
);
565 case TS_TYPE_WITH_LANG_SPECIFIC
:
566 MARK_TS_TYPE_COMMON (code
);
569 case TS_TYPE_NON_COMMON
:
570 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
574 MARK_TS_DECL_MINIMAL (code
);
579 MARK_TS_DECL_COMMON (code
);
582 case TS_DECL_NON_COMMON
:
583 MARK_TS_DECL_WITH_VIS (code
);
586 case TS_DECL_WITH_VIS
:
590 MARK_TS_DECL_WRTL (code
);
594 MARK_TS_DECL_COMMON (code
);
598 MARK_TS_DECL_WITH_VIS (code
);
602 case TS_FUNCTION_DECL
:
603 MARK_TS_DECL_NON_COMMON (code
);
606 case TS_TRANSLATION_UNIT_DECL
:
607 MARK_TS_DECL_COMMON (code
);
615 /* Basic consistency checks for attributes used in fold. */
616 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
617 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
618 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
619 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
620 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
621 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
622 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
623 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
624 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
625 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
626 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
627 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
628 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
629 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
630 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
631 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
632 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
633 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
634 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
635 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
636 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
637 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
638 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
639 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
640 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
641 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
642 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
643 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
644 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
645 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
646 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
647 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
648 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
649 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
650 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
651 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
652 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
653 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
654 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_MINIMAL
]);
655 gcc_assert (tree_contains_struct
[NAMELIST_DECL
][TS_DECL_COMMON
]);
664 /* Initialize the hash table of types. */
666 = hash_table
<type_cache_hasher
>::create_ggc (TYPE_HASH_INITIAL_SIZE
);
669 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
672 = hash_table
<tree_decl_map_cache_hasher
>::create_ggc (512);
674 int_cst_hash_table
= hash_table
<int_cst_hasher
>::create_ggc (1024);
676 poly_int_cst_hash_table
= hash_table
<poly_int_cst_hasher
>::create_ggc (64);
678 int_cst_node
= make_int_cst (1, 1);
680 cl_option_hash_table
= hash_table
<cl_option_hasher
>::create_ggc (64);
682 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
683 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
685 /* Initialize the tree_contains_struct array. */
686 initialize_tree_contains_struct ();
687 lang_hooks
.init_ts ();
691 /* The name of the object as the assembler will see it (but before any
692 translations made by ASM_OUTPUT_LABELREF). Often this is the same
693 as DECL_NAME. It is an IDENTIFIER_NODE. */
695 decl_assembler_name (tree decl
)
697 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
698 lang_hooks
.set_decl_assembler_name (decl
);
699 return DECL_ASSEMBLER_NAME_RAW (decl
);
702 /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
703 (either of which may be NULL). Inform the FE, if this changes the
707 overwrite_decl_assembler_name (tree decl
, tree name
)
709 if (DECL_ASSEMBLER_NAME_RAW (decl
) != name
)
710 lang_hooks
.overwrite_decl_assembler_name (decl
, name
);
713 /* Return true if DECL may need an assembler name to be set. */
716 need_assembler_name_p (tree decl
)
718 /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
719 Rule merging. This makes type_odr_p to return true on those types during
720 LTO and by comparing the mangled name, we can say what types are intended
721 to be equivalent across compilation unit.
723 We do not store names of type_in_anonymous_namespace_p.
725 Record, union and enumeration type have linkage that allows use
726 to check type_in_anonymous_namespace_p. We do not mangle compound types
727 that always can be compared structurally.
729 Similarly for builtin types, we compare properties of their main variant.
730 A special case are integer types where mangling do make differences
731 between char/signed char/unsigned char etc. Storing name for these makes
732 e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
733 See cp/mangle.cc:write_builtin_type for details. */
735 if (TREE_CODE (decl
) == TYPE_DECL
)
738 && decl
== TYPE_NAME (TREE_TYPE (decl
))
739 && TYPE_MAIN_VARIANT (TREE_TYPE (decl
)) == TREE_TYPE (decl
)
740 && !TYPE_ARTIFICIAL (TREE_TYPE (decl
))
741 && ((TREE_CODE (TREE_TYPE (decl
)) != RECORD_TYPE
742 && TREE_CODE (TREE_TYPE (decl
)) != UNION_TYPE
)
743 || TYPE_CXX_ODR_P (TREE_TYPE (decl
)))
744 && (type_with_linkage_p (TREE_TYPE (decl
))
745 || TREE_CODE (TREE_TYPE (decl
)) == INTEGER_TYPE
)
746 && !variably_modified_type_p (TREE_TYPE (decl
), NULL_TREE
))
747 return !DECL_ASSEMBLER_NAME_SET_P (decl
);
750 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
751 if (!VAR_OR_FUNCTION_DECL_P (decl
))
754 /* If DECL already has its assembler name set, it does not need a
756 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
757 || DECL_ASSEMBLER_NAME_SET_P (decl
))
760 /* Abstract decls do not need an assembler name. */
761 if (DECL_ABSTRACT_P (decl
))
764 /* For VAR_DECLs, only static, public and external symbols need an
767 && !TREE_STATIC (decl
)
768 && !TREE_PUBLIC (decl
)
769 && !DECL_EXTERNAL (decl
))
772 if (TREE_CODE (decl
) == FUNCTION_DECL
)
774 /* Do not set assembler name on builtins. Allow RTL expansion to
775 decide whether to expand inline or via a regular call. */
776 if (fndecl_built_in_p (decl
)
777 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
780 /* Functions represented in the callgraph need an assembler name. */
781 if (cgraph_node::get (decl
) != NULL
)
784 /* Unused and not public functions don't need an assembler name. */
785 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
792 /* If T needs an assembler name, have one created for it. */
795 assign_assembler_name_if_needed (tree t
)
797 if (need_assembler_name_p (t
))
799 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
800 diagnostics that use input_location to show locus
801 information. The problem here is that, at this point,
802 input_location is generally anchored to the end of the file
803 (since the parser is long gone), so we don't have a good
804 position to pin it to.
806 To alleviate this problem, this uses the location of T's
807 declaration. Examples of this are
808 testsuite/g++.dg/template/cond2.C and
809 testsuite/g++.dg/template/pr35240.C. */
810 location_t saved_location
= input_location
;
811 input_location
= DECL_SOURCE_LOCATION (t
);
813 decl_assembler_name (t
);
815 input_location
= saved_location
;
819 /* When the target supports COMDAT groups, this indicates which group the
820 DECL is associated with. This can be either an IDENTIFIER_NODE or a
821 decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
823 decl_comdat_group (const_tree node
)
825 struct symtab_node
*snode
= symtab_node::get (node
);
828 return snode
->get_comdat_group ();
831 /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
833 decl_comdat_group_id (const_tree node
)
835 struct symtab_node
*snode
= symtab_node::get (node
);
838 return snode
->get_comdat_group_id ();
841 /* When the target supports named section, return its name as IDENTIFIER_NODE
842 or NULL if it is in no section. */
844 decl_section_name (const_tree node
)
846 struct symtab_node
*snode
= symtab_node::get (node
);
849 return snode
->get_section ();
852 /* Set section name of NODE to VALUE (that is expected to be
855 set_decl_section_name (tree node
, const char *value
)
857 struct symtab_node
*snode
;
861 snode
= symtab_node::get (node
);
865 else if (VAR_P (node
))
866 snode
= varpool_node::get_create (node
);
868 snode
= cgraph_node::get_create (node
);
869 snode
->set_section (value
);
872 /* Set section name of NODE to match the section name of OTHER.
874 set_decl_section_name (decl, other) is equivalent to
875 set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
878 set_decl_section_name (tree decl
, const_tree other
)
880 struct symtab_node
*other_node
= symtab_node::get (other
);
883 struct symtab_node
*decl_node
;
885 decl_node
= varpool_node::get_create (decl
);
887 decl_node
= cgraph_node::get_create (decl
);
888 decl_node
->set_section (*other_node
);
892 struct symtab_node
*decl_node
= symtab_node::get (decl
);
895 decl_node
->set_section (NULL
);
899 /* Return TLS model of a variable NODE. */
901 decl_tls_model (const_tree node
)
903 struct varpool_node
*snode
= varpool_node::get (node
);
905 return TLS_MODEL_NONE
;
906 return snode
->tls_model
;
909 /* Set TLS model of variable NODE to MODEL. */
911 set_decl_tls_model (tree node
, enum tls_model model
)
913 struct varpool_node
*vnode
;
915 if (model
== TLS_MODEL_NONE
)
917 vnode
= varpool_node::get (node
);
922 vnode
= varpool_node::get_create (node
);
923 vnode
->tls_model
= model
;
926 /* Compute the number of bytes occupied by a tree with code CODE.
927 This function cannot be used for nodes that have variable sizes,
928 including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
930 tree_code_size (enum tree_code code
)
932 switch (TREE_CODE_CLASS (code
))
934 case tcc_declaration
: /* A decl node */
937 case FIELD_DECL
: return sizeof (tree_field_decl
);
938 case PARM_DECL
: return sizeof (tree_parm_decl
);
939 case VAR_DECL
: return sizeof (tree_var_decl
);
940 case LABEL_DECL
: return sizeof (tree_label_decl
);
941 case RESULT_DECL
: return sizeof (tree_result_decl
);
942 case CONST_DECL
: return sizeof (tree_const_decl
);
943 case TYPE_DECL
: return sizeof (tree_type_decl
);
944 case FUNCTION_DECL
: return sizeof (tree_function_decl
);
945 case DEBUG_EXPR_DECL
: return sizeof (tree_decl_with_rtl
);
946 case TRANSLATION_UNIT_DECL
: return sizeof (tree_translation_unit_decl
);
949 case NAMELIST_DECL
: return sizeof (tree_decl_non_common
);
951 gcc_checking_assert (code
>= NUM_TREE_CODES
);
952 return lang_hooks
.tree_size (code
);
955 case tcc_type
: /* a type node */
967 case FIXED_POINT_TYPE
:
973 case QUAL_UNION_TYPE
:
977 case LANG_TYPE
: return sizeof (tree_type_non_common
);
979 gcc_checking_assert (code
>= NUM_TREE_CODES
);
980 return lang_hooks
.tree_size (code
);
983 case tcc_reference
: /* a reference */
984 case tcc_expression
: /* an expression */
985 case tcc_statement
: /* an expression with side effects */
986 case tcc_comparison
: /* a comparison expression */
987 case tcc_unary
: /* a unary arithmetic expression */
988 case tcc_binary
: /* a binary arithmetic expression */
989 return (sizeof (struct tree_exp
)
990 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
992 case tcc_constant
: /* a constant */
995 case VOID_CST
: return sizeof (tree_typed
);
996 case INTEGER_CST
: gcc_unreachable ();
997 case POLY_INT_CST
: return sizeof (tree_poly_int_cst
);
998 case REAL_CST
: return sizeof (tree_real_cst
);
999 case FIXED_CST
: return sizeof (tree_fixed_cst
);
1000 case COMPLEX_CST
: return sizeof (tree_complex
);
1001 case VECTOR_CST
: gcc_unreachable ();
1002 case STRING_CST
: gcc_unreachable ();
1004 gcc_checking_assert (code
>= NUM_TREE_CODES
);
1005 return lang_hooks
.tree_size (code
);
1008 case tcc_exceptional
: /* something random, like an identifier. */
1011 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
1012 case TREE_LIST
: return sizeof (tree_list
);
1015 case PLACEHOLDER_EXPR
: return sizeof (tree_common
);
1017 case TREE_VEC
: gcc_unreachable ();
1018 case OMP_CLAUSE
: gcc_unreachable ();
1020 case SSA_NAME
: return sizeof (tree_ssa_name
);
1022 case STATEMENT_LIST
: return sizeof (tree_statement_list
);
1023 case BLOCK
: return sizeof (struct tree_block
);
1024 case CONSTRUCTOR
: return sizeof (tree_constructor
);
1025 case OPTIMIZATION_NODE
: return sizeof (tree_optimization_option
);
1026 case TARGET_OPTION_NODE
: return sizeof (tree_target_option
);
1029 gcc_checking_assert (code
>= NUM_TREE_CODES
);
1030 return lang_hooks
.tree_size (code
);
1038 /* Compute the number of bytes occupied by NODE. This routine only
1039 looks at TREE_CODE, except for those nodes that have variable sizes. */
1041 tree_size (const_tree node
)
1043 const enum tree_code code
= TREE_CODE (node
);
1047 return (sizeof (struct tree_int_cst
)
1048 + (TREE_INT_CST_EXT_NUNITS (node
) - 1) * sizeof (HOST_WIDE_INT
));
1051 return (offsetof (struct tree_binfo
, base_binfos
)
1053 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
1056 return (sizeof (struct tree_vec
)
1057 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
1060 return (sizeof (struct tree_vector
)
1061 + (vector_cst_encoded_nelts (node
) - 1) * sizeof (tree
));
1064 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
1067 return (sizeof (struct tree_omp_clause
)
1068 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
1072 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
1073 return (sizeof (struct tree_exp
)
1074 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
1076 return tree_code_size (code
);
1080 /* Return tree node kind based on tree CODE. */
1082 static tree_node_kind
1083 get_stats_node_kind (enum tree_code code
)
1085 enum tree_code_class type
= TREE_CODE_CLASS (code
);
1089 case tcc_declaration
: /* A decl node */
1091 case tcc_type
: /* a type node */
1093 case tcc_statement
: /* an expression with side effects */
1095 case tcc_reference
: /* a reference */
1097 case tcc_expression
: /* an expression */
1098 case tcc_comparison
: /* a comparison expression */
1099 case tcc_unary
: /* a unary arithmetic expression */
1100 case tcc_binary
: /* a binary arithmetic expression */
1102 case tcc_constant
: /* a constant */
1104 case tcc_exceptional
: /* something random, like an identifier. */
1107 case IDENTIFIER_NODE
:
1114 return ssa_name_kind
;
1120 return omp_clause_kind
;
1132 /* Record interesting allocation statistics for a tree node with CODE
1136 record_node_allocation_statistics (enum tree_code code
, size_t length
)
1138 if (!GATHER_STATISTICS
)
1141 tree_node_kind kind
= get_stats_node_kind (code
);
1143 tree_code_counts
[(int) code
]++;
1144 tree_node_counts
[(int) kind
]++;
1145 tree_node_sizes
[(int) kind
] += length
;
1148 /* Allocate and return a new UID from the DECL_UID namespace. */
1151 allocate_decl_uid (void)
1153 return next_decl_uid
++;
1156 /* Return a newly allocated node of code CODE. For decl and type
1157 nodes, some other fields are initialized. The rest of the node is
1158 initialized to zero. This function cannot be used for TREE_VEC,
1159 INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1162 Achoo! I got a code in the node. */
1165 make_node (enum tree_code code MEM_STAT_DECL
)
1168 enum tree_code_class type
= TREE_CODE_CLASS (code
);
1169 size_t length
= tree_code_size (code
);
1171 record_node_allocation_statistics (code
, length
);
1173 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1174 TREE_SET_CODE (t
, code
);
1179 if (code
!= DEBUG_BEGIN_STMT
)
1180 TREE_SIDE_EFFECTS (t
) = 1;
1183 case tcc_declaration
:
1184 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1186 if (code
== FUNCTION_DECL
)
1188 SET_DECL_ALIGN (t
, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY
));
1189 SET_DECL_MODE (t
, FUNCTION_MODE
);
1192 SET_DECL_ALIGN (t
, 1);
1194 DECL_SOURCE_LOCATION (t
) = input_location
;
1195 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
1196 DECL_UID (t
) = --next_debug_decl_uid
;
1199 DECL_UID (t
) = allocate_decl_uid ();
1200 SET_DECL_PT_UID (t
, -1);
1202 if (TREE_CODE (t
) == LABEL_DECL
)
1203 LABEL_DECL_UID (t
) = -1;
1208 TYPE_UID (t
) = next_type_uid
++;
1209 SET_TYPE_ALIGN (t
, BITS_PER_UNIT
);
1210 TYPE_USER_ALIGN (t
) = 0;
1211 TYPE_MAIN_VARIANT (t
) = t
;
1212 TYPE_CANONICAL (t
) = t
;
1214 /* Default to no attributes for type, but let target change that. */
1215 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1216 targetm
.set_default_type_attributes (t
);
1218 /* We have not yet computed the alias set for this type. */
1219 TYPE_ALIAS_SET (t
) = -1;
1223 TREE_CONSTANT (t
) = 1;
1226 case tcc_expression
:
1232 case PREDECREMENT_EXPR
:
1233 case PREINCREMENT_EXPR
:
1234 case POSTDECREMENT_EXPR
:
1235 case POSTINCREMENT_EXPR
:
1236 /* All of these have side-effects, no matter what their
1238 TREE_SIDE_EFFECTS (t
) = 1;
1246 case tcc_exceptional
:
1249 case TARGET_OPTION_NODE
:
1250 TREE_TARGET_OPTION(t
)
1251 = ggc_cleared_alloc
<struct cl_target_option
> ();
1254 case OPTIMIZATION_NODE
:
1255 TREE_OPTIMIZATION (t
)
1256 = ggc_cleared_alloc
<struct cl_optimization
> ();
1265 /* Other classes need no special treatment. */
1272 /* Free tree node. */
1275 free_node (tree node
)
1277 enum tree_code code
= TREE_CODE (node
);
1278 if (GATHER_STATISTICS
)
1280 enum tree_node_kind kind
= get_stats_node_kind (code
);
1282 gcc_checking_assert (tree_code_counts
[(int) TREE_CODE (node
)] != 0);
1283 gcc_checking_assert (tree_node_counts
[(int) kind
] != 0);
1284 gcc_checking_assert (tree_node_sizes
[(int) kind
] >= tree_size (node
));
1286 tree_code_counts
[(int) TREE_CODE (node
)]--;
1287 tree_node_counts
[(int) kind
]--;
1288 tree_node_sizes
[(int) kind
] -= tree_size (node
);
1290 if (CODE_CONTAINS_STRUCT (code
, TS_CONSTRUCTOR
))
1291 vec_free (CONSTRUCTOR_ELTS (node
));
1292 else if (code
== BLOCK
)
1293 vec_free (BLOCK_NONLOCALIZED_VARS (node
));
1294 else if (code
== TREE_BINFO
)
1295 vec_free (BINFO_BASE_ACCESSES (node
));
1296 else if (code
== OPTIMIZATION_NODE
)
1297 cl_optimization_option_free (TREE_OPTIMIZATION (node
));
1298 else if (code
== TARGET_OPTION_NODE
)
1299 cl_target_option_free (TREE_TARGET_OPTION (node
));
1303 /* Return a new node with the same contents as NODE except that its
1304 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1307 copy_node (tree node MEM_STAT_DECL
)
1310 enum tree_code code
= TREE_CODE (node
);
1313 gcc_assert (code
!= STATEMENT_LIST
);
1315 length
= tree_size (node
);
1316 record_node_allocation_statistics (code
, length
);
1317 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1318 memcpy (t
, node
, length
);
1320 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1322 TREE_ASM_WRITTEN (t
) = 0;
1323 TREE_VISITED (t
) = 0;
1325 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
1327 if (code
== DEBUG_EXPR_DECL
)
1328 DECL_UID (t
) = --next_debug_decl_uid
;
1331 DECL_UID (t
) = allocate_decl_uid ();
1332 if (DECL_PT_UID_SET_P (node
))
1333 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
1335 if ((TREE_CODE (node
) == PARM_DECL
|| VAR_P (node
))
1336 && DECL_HAS_VALUE_EXPR_P (node
))
1338 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
1339 DECL_HAS_VALUE_EXPR_P (t
) = 1;
1341 /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1344 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
1345 t
->decl_with_vis
.symtab_node
= NULL
;
1347 if (VAR_P (node
) && DECL_HAS_INIT_PRIORITY_P (node
))
1349 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
1350 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
1352 if (TREE_CODE (node
) == FUNCTION_DECL
)
1354 DECL_STRUCT_FUNCTION (t
) = NULL
;
1355 t
->decl_with_vis
.symtab_node
= NULL
;
1358 else if (TREE_CODE_CLASS (code
) == tcc_type
)
1360 TYPE_UID (t
) = next_type_uid
++;
1361 /* The following is so that the debug code for
1362 the copy is different from the original type.
1363 The two statements usually duplicate each other
1364 (because they clear fields of the same union),
1365 but the optimizer should catch that. */
1366 TYPE_SYMTAB_ADDRESS (t
) = 0;
1367 TYPE_SYMTAB_DIE (t
) = 0;
1369 /* Do not copy the values cache. */
1370 if (TYPE_CACHED_VALUES_P (t
))
1372 TYPE_CACHED_VALUES_P (t
) = 0;
1373 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1376 else if (code
== TARGET_OPTION_NODE
)
1378 TREE_TARGET_OPTION (t
) = ggc_alloc
<struct cl_target_option
>();
1379 memcpy (TREE_TARGET_OPTION (t
), TREE_TARGET_OPTION (node
),
1380 sizeof (struct cl_target_option
));
1382 else if (code
== OPTIMIZATION_NODE
)
1384 TREE_OPTIMIZATION (t
) = ggc_alloc
<struct cl_optimization
>();
1385 memcpy (TREE_OPTIMIZATION (t
), TREE_OPTIMIZATION (node
),
1386 sizeof (struct cl_optimization
));
1392 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1393 For example, this can copy a list made of TREE_LIST nodes. */
1396 copy_list (tree list
)
1404 head
= prev
= copy_node (list
);
1405 next
= TREE_CHAIN (list
);
1408 TREE_CHAIN (prev
) = copy_node (next
);
1409 prev
= TREE_CHAIN (prev
);
1410 next
= TREE_CHAIN (next
);
1416 /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1417 INTEGER_CST with value CST and type TYPE. */
1420 get_int_cst_ext_nunits (tree type
, const wide_int
&cst
)
1422 gcc_checking_assert (cst
.get_precision () == TYPE_PRECISION (type
));
1423 /* We need extra HWIs if CST is an unsigned integer with its
1425 if (TYPE_UNSIGNED (type
) && wi::neg_p (cst
))
1426 return cst
.get_precision () / HOST_BITS_PER_WIDE_INT
+ 1;
1427 return cst
.get_len ();
1430 /* Return a new INTEGER_CST with value CST and type TYPE. */
1433 build_new_int_cst (tree type
, const wide_int
&cst
)
1435 unsigned int len
= cst
.get_len ();
1436 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1437 tree nt
= make_int_cst (len
, ext_len
);
1442 TREE_INT_CST_ELT (nt
, ext_len
)
1443 = zext_hwi (-1, cst
.get_precision () % HOST_BITS_PER_WIDE_INT
);
1444 for (unsigned int i
= len
; i
< ext_len
; ++i
)
1445 TREE_INT_CST_ELT (nt
, i
) = -1;
1447 else if (TYPE_UNSIGNED (type
)
1448 && cst
.get_precision () < len
* HOST_BITS_PER_WIDE_INT
)
1451 TREE_INT_CST_ELT (nt
, len
)
1452 = zext_hwi (cst
.elt (len
),
1453 cst
.get_precision () % HOST_BITS_PER_WIDE_INT
);
1456 for (unsigned int i
= 0; i
< len
; i
++)
1457 TREE_INT_CST_ELT (nt
, i
) = cst
.elt (i
);
1458 TREE_TYPE (nt
) = type
;
1462 /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1465 build_new_poly_int_cst (tree type
, tree (&coeffs
)[NUM_POLY_INT_COEFFS
]
1468 size_t length
= sizeof (struct tree_poly_int_cst
);
1469 record_node_allocation_statistics (POLY_INT_CST
, length
);
1471 tree t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1473 TREE_SET_CODE (t
, POLY_INT_CST
);
1474 TREE_CONSTANT (t
) = 1;
1475 TREE_TYPE (t
) = type
;
1476 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1477 POLY_INT_CST_COEFF (t
, i
) = coeffs
[i
];
1481 /* Create a constant tree that contains CST sign-extended to TYPE. */
1484 build_int_cst (tree type
, poly_int64 cst
)
1486 /* Support legacy code. */
1488 type
= integer_type_node
;
1490 return wide_int_to_tree (type
, wi::shwi (cst
, TYPE_PRECISION (type
)));
1493 /* Create a constant tree that contains CST zero-extended to TYPE. */
1496 build_int_cstu (tree type
, poly_uint64 cst
)
1498 return wide_int_to_tree (type
, wi::uhwi (cst
, TYPE_PRECISION (type
)));
1501 /* Create a constant tree that contains CST sign-extended to TYPE. */
1504 build_int_cst_type (tree type
, poly_int64 cst
)
1507 return wide_int_to_tree (type
, wi::shwi (cst
, TYPE_PRECISION (type
)));
1510 /* Constructs tree in type TYPE from with value given by CST. Signedness
1511 of CST is assumed to be the same as the signedness of TYPE. */
1514 double_int_to_tree (tree type
, double_int cst
)
1516 return wide_int_to_tree (type
, widest_int::from (cst
, TYPE_SIGN (type
)));
1519 /* We force the wide_int CST to the range of the type TYPE by sign or
1520 zero extending it. OVERFLOWABLE indicates if we are interested in
1521 overflow of the value, when >0 we are only interested in signed
1522 overflow, for <0 we are interested in any overflow. OVERFLOWED
1523 indicates whether overflow has already occurred. CONST_OVERFLOWED
1524 indicates whether constant overflow has already occurred. We force
1525 T's value to be within range of T's type (by setting to 0 or 1 all
1526 the bits outside the type's range). We set TREE_OVERFLOWED if,
1527 OVERFLOWED is nonzero,
1528 or OVERFLOWABLE is >0 and signed overflow occurs
1529 or OVERFLOWABLE is <0 and any overflow occurs
1530 We return a new tree node for the extended wide_int. The node
1531 is shared if no overflow flags are set. */
1535 force_fit_type (tree type
, const poly_wide_int_ref
&cst
,
1536 int overflowable
, bool overflowed
)
1538 signop sign
= TYPE_SIGN (type
);
1540 /* If we need to set overflow flags, return a new unshared node. */
1541 if (overflowed
|| !wi::fits_to_tree_p (cst
, type
))
1545 || (overflowable
> 0 && sign
== SIGNED
))
1547 poly_wide_int tmp
= poly_wide_int::from (cst
, TYPE_PRECISION (type
),
1550 if (tmp
.is_constant ())
1551 t
= build_new_int_cst (type
, tmp
.coeffs
[0]);
1554 tree coeffs
[NUM_POLY_INT_COEFFS
];
1555 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1557 coeffs
[i
] = build_new_int_cst (type
, tmp
.coeffs
[i
]);
1558 TREE_OVERFLOW (coeffs
[i
]) = 1;
1560 t
= build_new_poly_int_cst (type
, coeffs
);
1562 TREE_OVERFLOW (t
) = 1;
1567 /* Else build a shared node. */
1568 return wide_int_to_tree (type
, cst
);
1571 /* These are the hash table functions for the hash table of INTEGER_CST
1572 nodes of a sizetype. */
1574 /* Return the hash code X, an INTEGER_CST. */
1577 int_cst_hasher::hash (tree x
)
1579 const_tree
const t
= x
;
1580 hashval_t code
= TYPE_UID (TREE_TYPE (t
));
1583 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
1584 code
= iterative_hash_host_wide_int (TREE_INT_CST_ELT(t
, i
), code
);
1589 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1590 is the same as that given by *Y, which is the same. */
1593 int_cst_hasher::equal (tree x
, tree y
)
1595 const_tree
const xt
= x
;
1596 const_tree
const yt
= y
;
1598 if (TREE_TYPE (xt
) != TREE_TYPE (yt
)
1599 || TREE_INT_CST_NUNITS (xt
) != TREE_INT_CST_NUNITS (yt
)
1600 || TREE_INT_CST_EXT_NUNITS (xt
) != TREE_INT_CST_EXT_NUNITS (yt
))
1603 for (int i
= 0; i
< TREE_INT_CST_NUNITS (xt
); i
++)
1604 if (TREE_INT_CST_ELT (xt
, i
) != TREE_INT_CST_ELT (yt
, i
))
1610 /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1611 SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1612 number of slots that can be cached for the type. */
1615 cache_wide_int_in_type_cache (tree type
, const wide_int
&cst
,
1616 int slot
, int max_slots
)
1618 gcc_checking_assert (slot
>= 0);
1619 /* Initialize cache. */
1620 if (!TYPE_CACHED_VALUES_P (type
))
1622 TYPE_CACHED_VALUES_P (type
) = 1;
1623 TYPE_CACHED_VALUES (type
) = make_tree_vec (max_slots
);
1625 tree t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), slot
);
1628 /* Create a new shared int. */
1629 t
= build_new_int_cst (type
, cst
);
1630 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), slot
) = t
;
1635 /* Create an INT_CST node of TYPE and value CST.
1636 The returned node is always shared. For small integers we use a
1637 per-type vector cache, for larger ones we use a single hash table.
1638 The value is extended from its precision according to the sign of
1639 the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1640 the upper bits and ensures that hashing and value equality based
1641 upon the underlying HOST_WIDE_INTs works without masking. */
1644 wide_int_to_tree_1 (tree type
, const wide_int_ref
&pcst
)
1651 unsigned int prec
= TYPE_PRECISION (type
);
1652 signop sgn
= TYPE_SIGN (type
);
1654 /* Verify that everything is canonical. */
1655 int l
= pcst
.get_len ();
1658 if (pcst
.elt (l
- 1) == 0)
1659 gcc_checking_assert (pcst
.elt (l
- 2) < 0);
1660 if (pcst
.elt (l
- 1) == HOST_WIDE_INT_M1
)
1661 gcc_checking_assert (pcst
.elt (l
- 2) >= 0);
1664 wide_int cst
= wide_int::from (pcst
, prec
, sgn
);
1665 unsigned int ext_len
= get_int_cst_ext_nunits (type
, cst
);
1667 enum tree_code code
= TREE_CODE (type
);
1668 if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
1670 /* Cache NULL pointer and zero bounds. */
1673 /* Cache upper bounds of pointers. */
1674 else if (cst
== wi::max_value (prec
, sgn
))
1676 /* Cache 1 which is used for a non-zero range. */
1682 t
= cache_wide_int_in_type_cache (type
, cst
, ix
, 3);
1683 /* Make sure no one is clobbering the shared constant. */
1684 gcc_checking_assert (TREE_TYPE (t
) == type
1685 && cst
== wi::to_wide (t
));
1691 /* We just need to store a single HOST_WIDE_INT. */
1693 if (TYPE_UNSIGNED (type
))
1694 hwi
= cst
.to_uhwi ();
1696 hwi
= cst
.to_shwi ();
1701 gcc_assert (hwi
== 0);
1705 case REFERENCE_TYPE
:
1706 /* Ignore pointers, as they were already handled above. */
1710 /* Cache false or true. */
1712 if (IN_RANGE (hwi
, 0, 1))
1718 if (TYPE_SIGN (type
) == UNSIGNED
)
1721 limit
= param_integer_share_limit
;
1722 if (IN_RANGE (hwi
, 0, param_integer_share_limit
- 1))
1727 /* Cache [-1, N). */
1728 limit
= param_integer_share_limit
+ 1;
1729 if (IN_RANGE (hwi
, -1, param_integer_share_limit
- 1))
1743 t
= cache_wide_int_in_type_cache (type
, cst
, ix
, limit
);
1744 /* Make sure no one is clobbering the shared constant. */
1745 gcc_checking_assert (TREE_TYPE (t
) == type
1746 && TREE_INT_CST_NUNITS (t
) == 1
1747 && TREE_INT_CST_OFFSET_NUNITS (t
) == 1
1748 && TREE_INT_CST_EXT_NUNITS (t
) == 1
1749 && TREE_INT_CST_ELT (t
, 0) == hwi
);
1754 /* Use the cache of larger shared ints, using int_cst_node as
1757 TREE_INT_CST_ELT (int_cst_node
, 0) = hwi
;
1758 TREE_TYPE (int_cst_node
) = type
;
1760 tree
*slot
= int_cst_hash_table
->find_slot (int_cst_node
, INSERT
);
1764 /* Insert this one into the hash table. */
1767 /* Make a new node for next time round. */
1768 int_cst_node
= make_int_cst (1, 1);
1774 /* The value either hashes properly or we drop it on the floor
1775 for the gc to take care of. There will not be enough of them
1778 tree nt
= build_new_int_cst (type
, cst
);
1779 tree
*slot
= int_cst_hash_table
->find_slot (nt
, INSERT
);
1783 /* Insert this one into the hash table. */
1795 poly_int_cst_hasher::hash (tree t
)
1797 inchash::hash hstate
;
1799 hstate
.add_int (TYPE_UID (TREE_TYPE (t
)));
1800 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1801 hstate
.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t
, i
)));
1803 return hstate
.end ();
1807 poly_int_cst_hasher::equal (tree x
, const compare_type
&y
)
1809 if (TREE_TYPE (x
) != y
.first
)
1811 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1812 if (wi::to_wide (POLY_INT_CST_COEFF (x
, i
)) != y
.second
->coeffs
[i
])
1817 /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1818 The elements must also have type TYPE. */
1821 build_poly_int_cst (tree type
, const poly_wide_int_ref
&values
)
1823 unsigned int prec
= TYPE_PRECISION (type
);
1824 gcc_assert (prec
<= values
.coeffs
[0].get_precision ());
1825 poly_wide_int c
= poly_wide_int::from (values
, prec
, SIGNED
);
1828 h
.add_int (TYPE_UID (type
));
1829 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1830 h
.add_wide_int (c
.coeffs
[i
]);
1831 poly_int_cst_hasher::compare_type
comp (type
, &c
);
1832 tree
*slot
= poly_int_cst_hash_table
->find_slot_with_hash (comp
, h
.end (),
1834 if (*slot
== NULL_TREE
)
1836 tree coeffs
[NUM_POLY_INT_COEFFS
];
1837 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1838 coeffs
[i
] = wide_int_to_tree_1 (type
, c
.coeffs
[i
]);
1839 *slot
= build_new_poly_int_cst (type
, coeffs
);
1844 /* Create a constant tree with value VALUE in type TYPE. */
1847 wide_int_to_tree (tree type
, const poly_wide_int_ref
&value
)
1849 if (value
.is_constant ())
1850 return wide_int_to_tree_1 (type
, value
.coeffs
[0]);
1851 return build_poly_int_cst (type
, value
);
1854 /* Insert INTEGER_CST T into a cache of integer constants. And return
1855 the cached constant (which may or may not be T). If MIGHT_DUPLICATE
1856 is false, and T falls into the type's 'smaller values' range, there
1857 cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
1858 or the value is large, should an existing entry exist, it is
1859 returned (rather than inserting T). */
1862 cache_integer_cst (tree t
, bool might_duplicate ATTRIBUTE_UNUSED
)
1864 tree type
= TREE_TYPE (t
);
1867 int prec
= TYPE_PRECISION (type
);
1869 gcc_assert (!TREE_OVERFLOW (t
));
1871 /* The caching indices here must match those in
1872 wide_int_to_type_1. */
1873 switch (TREE_CODE (type
))
1876 gcc_checking_assert (integer_zerop (t
));
1880 case REFERENCE_TYPE
:
1882 if (integer_zerop (t
))
1884 else if (integer_onep (t
))
1893 /* Cache false or true. */
1895 if (wi::ltu_p (wi::to_wide (t
), 2))
1896 ix
= TREE_INT_CST_ELT (t
, 0);
1901 if (TYPE_UNSIGNED (type
))
1904 limit
= param_integer_share_limit
;
1906 /* This is a little hokie, but if the prec is smaller than
1907 what is necessary to hold param_integer_share_limit, then the
1908 obvious test will not get the correct answer. */
1909 if (prec
< HOST_BITS_PER_WIDE_INT
)
1911 if (tree_to_uhwi (t
)
1912 < (unsigned HOST_WIDE_INT
) param_integer_share_limit
)
1913 ix
= tree_to_uhwi (t
);
1915 else if (wi::ltu_p (wi::to_wide (t
), param_integer_share_limit
))
1916 ix
= tree_to_uhwi (t
);
1921 limit
= param_integer_share_limit
+ 1;
1923 if (integer_minus_onep (t
))
1925 else if (!wi::neg_p (wi::to_wide (t
)))
1927 if (prec
< HOST_BITS_PER_WIDE_INT
)
1929 if (tree_to_shwi (t
) < param_integer_share_limit
)
1930 ix
= tree_to_shwi (t
) + 1;
1932 else if (wi::ltu_p (wi::to_wide (t
), param_integer_share_limit
))
1933 ix
= tree_to_shwi (t
) + 1;
1939 /* The slot used by TYPE_CACHED_VALUES is used for the enum
1949 /* Look for it in the type's vector of small shared ints. */
1950 if (!TYPE_CACHED_VALUES_P (type
))
1952 TYPE_CACHED_VALUES_P (type
) = 1;
1953 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1956 if (tree r
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
))
1958 gcc_checking_assert (might_duplicate
);
1962 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1966 /* Use the cache of larger shared ints. */
1967 tree
*slot
= int_cst_hash_table
->find_slot (t
, INSERT
);
1970 /* If there is already an entry for the number verify it's the
1972 gcc_checking_assert (wi::to_wide (tree (r
)) == wi::to_wide (t
));
1973 /* And return the cached value. */
1977 /* Otherwise insert this one into the hash table. */
1985 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1986 and the rest are zeros. */
1989 build_low_bits_mask (tree type
, unsigned bits
)
1991 gcc_assert (bits
<= TYPE_PRECISION (type
));
1993 return wide_int_to_tree (type
, wi::mask (bits
, false,
1994 TYPE_PRECISION (type
)));
1997 /* Checks that X is integer constant that can be expressed in (unsigned)
1998 HOST_WIDE_INT without loss of precision. */
2001 cst_and_fits_in_hwi (const_tree x
)
2003 return (TREE_CODE (x
) == INTEGER_CST
2004 && (tree_fits_shwi_p (x
) || tree_fits_uhwi_p (x
)));
2007 /* Build a newly constructed VECTOR_CST with the given values of
2008 (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2011 make_vector (unsigned log2_npatterns
,
2012 unsigned int nelts_per_pattern MEM_STAT_DECL
)
2014 gcc_assert (IN_RANGE (nelts_per_pattern
, 1, 3));
2016 unsigned npatterns
= 1 << log2_npatterns
;
2017 unsigned encoded_nelts
= npatterns
* nelts_per_pattern
;
2018 unsigned length
= (sizeof (struct tree_vector
)
2019 + (encoded_nelts
- 1) * sizeof (tree
));
2021 record_node_allocation_statistics (VECTOR_CST
, length
);
2023 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2025 TREE_SET_CODE (t
, VECTOR_CST
);
2026 TREE_CONSTANT (t
) = 1;
2027 VECTOR_CST_LOG2_NPATTERNS (t
) = log2_npatterns
;
2028 VECTOR_CST_NELTS_PER_PATTERN (t
) = nelts_per_pattern
;
2033 /* Return a new VECTOR_CST node whose type is TYPE and whose values
2034 are extracted from V, a vector of CONSTRUCTOR_ELT. */
2037 build_vector_from_ctor (tree type
, const vec
<constructor_elt
, va_gc
> *v
)
2039 if (vec_safe_length (v
) == 0)
2040 return build_zero_cst (type
);
2042 unsigned HOST_WIDE_INT idx
, nelts
;
2045 /* We can't construct a VECTOR_CST for a variable number of elements. */
2046 nelts
= TYPE_VECTOR_SUBPARTS (type
).to_constant ();
2047 tree_vector_builder
vec (type
, nelts
, 1);
2048 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2050 if (TREE_CODE (value
) == VECTOR_CST
)
2052 /* If NELTS is constant then this must be too. */
2053 unsigned int sub_nelts
= VECTOR_CST_NELTS (value
).to_constant ();
2054 for (unsigned i
= 0; i
< sub_nelts
; ++i
)
2055 vec
.quick_push (VECTOR_CST_ELT (value
, i
));
2058 vec
.quick_push (value
);
2060 while (vec
.length () < nelts
)
2061 vec
.quick_push (build_zero_cst (TREE_TYPE (type
)));
2063 return vec
.build ();
2066 /* Build a vector of type VECTYPE where all the elements are SCs. */
2068 build_vector_from_val (tree vectype
, tree sc
)
2070 unsigned HOST_WIDE_INT i
, nunits
;
2072 if (sc
== error_mark_node
)
2075 /* Verify that the vector type is suitable for SC. Note that there
2076 is some inconsistency in the type-system with respect to restrict
2077 qualifications of pointers. Vector types always have a main-variant
2078 element type and the qualification is applied to the vector-type.
2079 So TREE_TYPE (vector-type) does not return a properly qualified
2080 vector element-type. */
2081 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
2082 TREE_TYPE (vectype
)));
2084 if (CONSTANT_CLASS_P (sc
))
2086 tree_vector_builder
v (vectype
, 1, 1);
2090 else if (!TYPE_VECTOR_SUBPARTS (vectype
).is_constant (&nunits
))
2091 return fold_build1 (VEC_DUPLICATE_EXPR
, vectype
, sc
);
2094 vec
<constructor_elt
, va_gc
> *v
;
2095 vec_alloc (v
, nunits
);
2096 for (i
= 0; i
< nunits
; ++i
)
2097 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
2098 return build_constructor (vectype
, v
);
2102 /* If TYPE is not a vector type, just return SC, otherwise return
2103 build_vector_from_val (TYPE, SC). */
2106 build_uniform_cst (tree type
, tree sc
)
2108 if (!VECTOR_TYPE_P (type
))
2111 return build_vector_from_val (type
, sc
);
2114 /* Build a vector series of type TYPE in which element I has the value
2115 BASE + I * STEP. The result is a constant if BASE and STEP are constant
2116 and a VEC_SERIES_EXPR otherwise. */
2119 build_vec_series (tree type
, tree base
, tree step
)
2121 if (integer_zerop (step
))
2122 return build_vector_from_val (type
, base
);
2123 if (TREE_CODE (base
) == INTEGER_CST
&& TREE_CODE (step
) == INTEGER_CST
)
2125 tree_vector_builder
builder (type
, 1, 3);
2126 tree elt1
= wide_int_to_tree (TREE_TYPE (base
),
2127 wi::to_wide (base
) + wi::to_wide (step
));
2128 tree elt2
= wide_int_to_tree (TREE_TYPE (base
),
2129 wi::to_wide (elt1
) + wi::to_wide (step
));
2130 builder
.quick_push (base
);
2131 builder
.quick_push (elt1
);
2132 builder
.quick_push (elt2
);
2133 return builder
.build ();
2135 return build2 (VEC_SERIES_EXPR
, type
, base
, step
);
2138 /* Return a vector with the same number of units and number of bits
2139 as VEC_TYPE, but in which the elements are a linear series of unsigned
2140 integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2143 build_index_vector (tree vec_type
, poly_uint64 base
, poly_uint64 step
)
2145 tree index_vec_type
= vec_type
;
2146 tree index_elt_type
= TREE_TYPE (vec_type
);
2147 poly_uint64 nunits
= TYPE_VECTOR_SUBPARTS (vec_type
);
2148 if (!INTEGRAL_TYPE_P (index_elt_type
) || !TYPE_UNSIGNED (index_elt_type
))
2150 index_elt_type
= build_nonstandard_integer_type
2151 (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type
)), true);
2152 index_vec_type
= build_vector_type (index_elt_type
, nunits
);
2155 tree_vector_builder
v (index_vec_type
, 1, 3);
2156 for (unsigned int i
= 0; i
< 3; ++i
)
2157 v
.quick_push (build_int_cstu (index_elt_type
, base
+ i
* step
));
2161 /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2162 elements are A and the rest are B. */
2165 build_vector_a_then_b (tree vec_type
, unsigned int num_a
, tree a
, tree b
)
2167 gcc_assert (known_le (num_a
, TYPE_VECTOR_SUBPARTS (vec_type
)));
2168 unsigned int count
= constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type
));
2169 /* Optimize the constant case. */
2170 if ((count
& 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type
).is_constant ())
2172 tree_vector_builder
builder (vec_type
, count
, 2);
2173 for (unsigned int i
= 0; i
< count
* 2; ++i
)
2174 builder
.quick_push (i
< num_a
? a
: b
);
2175 return builder
.build ();
2178 /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2179 calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2182 recompute_constructor_flags (tree c
)
2186 bool constant_p
= true;
2187 bool side_effects_p
= false;
2188 vec
<constructor_elt
, va_gc
> *vals
= CONSTRUCTOR_ELTS (c
);
2190 FOR_EACH_CONSTRUCTOR_VALUE (vals
, i
, val
)
2192 /* Mostly ctors will have elts that don't have side-effects, so
2193 the usual case is to scan all the elements. Hence a single
2194 loop for both const and side effects, rather than one loop
2195 each (with early outs). */
2196 if (!TREE_CONSTANT (val
))
2198 if (TREE_SIDE_EFFECTS (val
))
2199 side_effects_p
= true;
2202 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
2203 TREE_CONSTANT (c
) = constant_p
;
2206 /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2210 verify_constructor_flags (tree c
)
2214 bool constant_p
= TREE_CONSTANT (c
);
2215 bool side_effects_p
= TREE_SIDE_EFFECTS (c
);
2216 vec
<constructor_elt
, va_gc
> *vals
= CONSTRUCTOR_ELTS (c
);
2218 FOR_EACH_CONSTRUCTOR_VALUE (vals
, i
, val
)
2220 if (constant_p
&& !TREE_CONSTANT (val
))
2221 internal_error ("non-constant element in constant CONSTRUCTOR");
2222 if (!side_effects_p
&& TREE_SIDE_EFFECTS (val
))
2223 internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2227 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2228 are in the vec pointed to by VALS. */
2230 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals MEM_STAT_DECL
)
2232 tree c
= make_node (CONSTRUCTOR PASS_MEM_STAT
);
2234 TREE_TYPE (c
) = type
;
2235 CONSTRUCTOR_ELTS (c
) = vals
;
2237 recompute_constructor_flags (c
);
2242 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2245 build_constructor_single (tree type
, tree index
, tree value
)
2247 vec
<constructor_elt
, va_gc
> *v
;
2248 constructor_elt elt
= {index
, value
};
2251 v
->quick_push (elt
);
2253 return build_constructor (type
, v
);
2257 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2258 are in a list pointed to by VALS. */
2260 build_constructor_from_list (tree type
, tree vals
)
2263 vec
<constructor_elt
, va_gc
> *v
= NULL
;
2267 vec_alloc (v
, list_length (vals
));
2268 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
2269 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
2272 return build_constructor (type
, v
);
2275 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2276 are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2277 fields in the constructor remain null. */
2280 build_constructor_from_vec (tree type
, const vec
<tree
, va_gc
> *vals
)
2282 vec
<constructor_elt
, va_gc
> *v
= NULL
;
2285 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, t
);
2287 return build_constructor (type
, v
);
2290 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2291 of elements, provided as index/value pairs. */
2294 build_constructor_va (tree type
, int nelts
, ...)
2296 vec
<constructor_elt
, va_gc
> *v
= NULL
;
2299 va_start (p
, nelts
);
2300 vec_alloc (v
, nelts
);
2303 tree index
= va_arg (p
, tree
);
2304 tree value
= va_arg (p
, tree
);
2305 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
2308 return build_constructor (type
, v
);
2311 /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2314 build_clobber (tree type
, enum clobber_kind kind
)
2316 tree clobber
= build_constructor (type
, NULL
);
2317 TREE_THIS_VOLATILE (clobber
) = true;
2318 CLOBBER_KIND (clobber
) = kind
;
2322 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2325 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
2328 FIXED_VALUE_TYPE
*fp
;
2330 v
= make_node (FIXED_CST
);
2331 fp
= ggc_alloc
<fixed_value
> ();
2332 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
2334 TREE_TYPE (v
) = type
;
2335 TREE_FIXED_CST_PTR (v
) = fp
;
2339 /* Return a new REAL_CST node whose type is TYPE and value is D. */
2342 build_real (tree type
, REAL_VALUE_TYPE d
)
2345 REAL_VALUE_TYPE
*dp
;
2348 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2349 Consider doing it via real_convert now. */
2351 v
= make_node (REAL_CST
);
2352 dp
= ggc_alloc
<real_value
> ();
2353 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
2355 TREE_TYPE (v
) = type
;
2356 TREE_REAL_CST_PTR (v
) = dp
;
2357 TREE_OVERFLOW (v
) = overflow
;
2361 /* Like build_real, but first truncate D to the type. */
2364 build_real_truncate (tree type
, REAL_VALUE_TYPE d
)
2366 return build_real (type
, real_value_truncate (TYPE_MODE (type
), d
));
2369 /* Return a new REAL_CST node whose type is TYPE
2370 and whose value is the integer value of the INTEGER_CST node I. */
2373 real_value_from_int_cst (const_tree type
, const_tree i
)
2377 /* Clear all bits of the real value type so that we can later do
2378 bitwise comparisons to see if two values are the same. */
2379 memset (&d
, 0, sizeof d
);
2381 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
, wi::to_wide (i
),
2382 TYPE_SIGN (TREE_TYPE (i
)));
2386 /* Given a tree representing an integer constant I, return a tree
2387 representing the same value as a floating-point constant of type TYPE. */
2390 build_real_from_int_cst (tree type
, const_tree i
)
2393 int overflow
= TREE_OVERFLOW (i
);
2395 v
= build_real (type
, real_value_from_int_cst (type
, i
));
2397 TREE_OVERFLOW (v
) |= overflow
;
2401 /* Return a new REAL_CST node whose type is TYPE
2402 and whose value is the integer value I which has sign SGN. */
2405 build_real_from_wide (tree type
, const wide_int_ref
&i
, signop sgn
)
2409 /* Clear all bits of the real value type so that we can later do
2410 bitwise comparisons to see if two values are the same. */
2411 memset (&d
, 0, sizeof d
);
2413 real_from_integer (&d
, TYPE_MODE (type
), i
, sgn
);
2414 return build_real (type
, d
);
2417 /* Return a newly constructed STRING_CST node whose value is the LEN
2418 characters at STR when STR is nonnull, or all zeros otherwise.
2419 Note that for a C string literal, LEN should include the trailing NUL.
2420 The TREE_TYPE is not initialized. */
2423 build_string (unsigned len
, const char *str
/*= NULL */)
2425 /* Do not waste bytes provided by padding of struct tree_string. */
2426 unsigned size
= len
+ offsetof (struct tree_string
, str
) + 1;
2428 record_node_allocation_statistics (STRING_CST
, size
);
2430 tree s
= (tree
) ggc_internal_alloc (size
);
2432 memset (s
, 0, sizeof (struct tree_typed
));
2433 TREE_SET_CODE (s
, STRING_CST
);
2434 TREE_CONSTANT (s
) = 1;
2435 TREE_STRING_LENGTH (s
) = len
;
2437 memcpy (s
->string
.str
, str
, len
);
2439 memset (s
->string
.str
, 0, len
);
2440 s
->string
.str
[len
] = '\0';
2445 /* Return a newly constructed COMPLEX_CST node whose value is
2446 specified by the real and imaginary parts REAL and IMAG.
2447 Both REAL and IMAG should be constant nodes. TYPE, if specified,
2448 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2451 build_complex (tree type
, tree real
, tree imag
)
2453 gcc_assert (CONSTANT_CLASS_P (real
));
2454 gcc_assert (CONSTANT_CLASS_P (imag
));
2456 tree t
= make_node (COMPLEX_CST
);
2458 TREE_REALPART (t
) = real
;
2459 TREE_IMAGPART (t
) = imag
;
2460 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
2461 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
2465 /* Build a complex (inf +- 0i), such as for the result of cproj.
2466 TYPE is the complex tree type of the result. If NEG is true, the
2467 imaginary zero is negative. */
2470 build_complex_inf (tree type
, bool neg
)
2472 REAL_VALUE_TYPE rinf
, rzero
= dconst0
;
2476 return build_complex (type
, build_real (TREE_TYPE (type
), rinf
),
2477 build_real (TREE_TYPE (type
), rzero
));
2480 /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2481 element is set to 1. In particular, this is 1 + i for complex types. */
2484 build_each_one_cst (tree type
)
2486 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2488 tree scalar
= build_one_cst (TREE_TYPE (type
));
2489 return build_complex (type
, scalar
, scalar
);
2492 return build_one_cst (type
);
2495 /* Return a constant of arithmetic type TYPE which is the
2496 multiplicative identity of the set TYPE. */
2499 build_one_cst (tree type
)
2501 switch (TREE_CODE (type
))
2503 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2504 case POINTER_TYPE
: case REFERENCE_TYPE
:
2506 return build_int_cst (type
, 1);
2509 return build_real (type
, dconst1
);
2511 case FIXED_POINT_TYPE
:
2512 /* We can only generate 1 for accum types. */
2513 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
2514 return build_fixed (type
, FCONST1 (TYPE_MODE (type
)));
2518 tree scalar
= build_one_cst (TREE_TYPE (type
));
2520 return build_vector_from_val (type
, scalar
);
2524 return build_complex (type
,
2525 build_one_cst (TREE_TYPE (type
)),
2526 build_zero_cst (TREE_TYPE (type
)));
2533 /* Return an integer of type TYPE containing all 1's in as much precision as
2534 it contains, or a complex or vector whose subparts are such integers. */
2537 build_all_ones_cst (tree type
)
2539 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2541 tree scalar
= build_all_ones_cst (TREE_TYPE (type
));
2542 return build_complex (type
, scalar
, scalar
);
2545 return build_minus_one_cst (type
);
2548 /* Return a constant of arithmetic type TYPE which is the
2549 opposite of the multiplicative identity of the set TYPE. */
2552 build_minus_one_cst (tree type
)
2554 switch (TREE_CODE (type
))
2556 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2557 case POINTER_TYPE
: case REFERENCE_TYPE
:
2559 return build_int_cst (type
, -1);
2562 return build_real (type
, dconstm1
);
2564 case FIXED_POINT_TYPE
:
2565 /* We can only generate 1 for accum types. */
2566 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
2567 return build_fixed (type
,
2568 fixed_from_double_int (double_int_minus_one
,
2569 SCALAR_TYPE_MODE (type
)));
2573 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
2575 return build_vector_from_val (type
, scalar
);
2579 return build_complex (type
,
2580 build_minus_one_cst (TREE_TYPE (type
)),
2581 build_zero_cst (TREE_TYPE (type
)));
2588 /* Build 0 constant of type TYPE. This is used by constructor folding
2589 and thus the constant should be represented in memory by
2593 build_zero_cst (tree type
)
2595 switch (TREE_CODE (type
))
2597 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
2598 case POINTER_TYPE
: case REFERENCE_TYPE
:
2599 case OFFSET_TYPE
: case NULLPTR_TYPE
:
2600 return build_int_cst (type
, 0);
2603 return build_real (type
, dconst0
);
2605 case FIXED_POINT_TYPE
:
2606 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
2610 tree scalar
= build_zero_cst (TREE_TYPE (type
));
2612 return build_vector_from_val (type
, scalar
);
2617 tree zero
= build_zero_cst (TREE_TYPE (type
));
2619 return build_complex (type
, zero
, zero
);
2623 if (!AGGREGATE_TYPE_P (type
))
2624 return fold_convert (type
, integer_zero_node
);
2625 return build_constructor (type
, NULL
);
2630 /* Build a BINFO with LEN language slots. */
2633 make_tree_binfo (unsigned base_binfos MEM_STAT_DECL
)
2636 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
2637 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
2639 record_node_allocation_statistics (TREE_BINFO
, length
);
2641 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
2643 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
2645 TREE_SET_CODE (t
, TREE_BINFO
);
2647 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
2652 /* Create a CASE_LABEL_EXPR tree node and return it. */
2655 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
2657 tree t
= make_node (CASE_LABEL_EXPR
);
2659 TREE_TYPE (t
) = void_type_node
;
2660 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
2662 CASE_LOW (t
) = low_value
;
2663 CASE_HIGH (t
) = high_value
;
2664 CASE_LABEL (t
) = label_decl
;
2665 CASE_CHAIN (t
) = NULL_TREE
;
2670 /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2671 values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2672 The latter determines the length of the HOST_WIDE_INT vector. */
2675 make_int_cst (int len
, int ext_len MEM_STAT_DECL
)
2678 int length
= ((ext_len
- 1) * sizeof (HOST_WIDE_INT
)
2679 + sizeof (struct tree_int_cst
));
2682 record_node_allocation_statistics (INTEGER_CST
, length
);
2684 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2686 TREE_SET_CODE (t
, INTEGER_CST
);
2687 TREE_INT_CST_NUNITS (t
) = len
;
2688 TREE_INT_CST_EXT_NUNITS (t
) = ext_len
;
2689 /* to_offset can only be applied to trees that are offset_int-sized
2690 or smaller. EXT_LEN is correct if it fits, otherwise the constant
2691 must be exactly the precision of offset_int and so LEN is correct. */
2692 if (ext_len
<= OFFSET_INT_ELTS
)
2693 TREE_INT_CST_OFFSET_NUNITS (t
) = ext_len
;
2695 TREE_INT_CST_OFFSET_NUNITS (t
) = len
;
2697 TREE_CONSTANT (t
) = 1;
2702 /* Build a newly constructed TREE_VEC node of length LEN. */
2705 make_tree_vec (int len MEM_STAT_DECL
)
2708 size_t length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2710 record_node_allocation_statistics (TREE_VEC
, length
);
2712 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
2714 TREE_SET_CODE (t
, TREE_VEC
);
2715 TREE_VEC_LENGTH (t
) = len
;
2720 /* Grow a TREE_VEC node to new length LEN. */
2723 grow_tree_vec (tree v
, int len MEM_STAT_DECL
)
2725 gcc_assert (TREE_CODE (v
) == TREE_VEC
);
2727 int oldlen
= TREE_VEC_LENGTH (v
);
2728 gcc_assert (len
> oldlen
);
2730 size_t oldlength
= (oldlen
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2731 size_t length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
2733 record_node_allocation_statistics (TREE_VEC
, length
- oldlength
);
2735 v
= (tree
) ggc_realloc (v
, length PASS_MEM_STAT
);
2737 TREE_VEC_LENGTH (v
) = len
;
2742 /* Return 1 if EXPR is the constant zero, whether it is integral, float or
2743 fixed, and scalar, complex or vector. */
2746 zerop (const_tree expr
)
2748 return (integer_zerop (expr
)
2749 || real_zerop (expr
)
2750 || fixed_zerop (expr
));
2753 /* Return 1 if EXPR is the integer constant zero or a complex constant
2754 of zero, or a location wrapper for such a constant. */
2757 integer_zerop (const_tree expr
)
2759 STRIP_ANY_LOCATION_WRAPPER (expr
);
2761 switch (TREE_CODE (expr
))
2764 return wi::to_wide (expr
) == 0;
2766 return (integer_zerop (TREE_REALPART (expr
))
2767 && integer_zerop (TREE_IMAGPART (expr
)));
2769 return (VECTOR_CST_NPATTERNS (expr
) == 1
2770 && VECTOR_CST_DUPLICATE_P (expr
)
2771 && integer_zerop (VECTOR_CST_ENCODED_ELT (expr
, 0)));
2777 /* Return 1 if EXPR is the integer constant one or the corresponding
2778 complex constant, or a location wrapper for such a constant. */
2781 integer_onep (const_tree expr
)
2783 STRIP_ANY_LOCATION_WRAPPER (expr
);
2785 switch (TREE_CODE (expr
))
2788 return wi::eq_p (wi::to_widest (expr
), 1);
2790 return (integer_onep (TREE_REALPART (expr
))
2791 && integer_zerop (TREE_IMAGPART (expr
)));
2793 return (VECTOR_CST_NPATTERNS (expr
) == 1
2794 && VECTOR_CST_DUPLICATE_P (expr
)
2795 && integer_onep (VECTOR_CST_ENCODED_ELT (expr
, 0)));
2801 /* Return 1 if EXPR is the integer constant one. For complex and vector,
2802 return 1 if every piece is the integer constant one.
2803 Also return 1 for location wrappers for such a constant. */
2806 integer_each_onep (const_tree expr
)
2808 STRIP_ANY_LOCATION_WRAPPER (expr
);
2810 if (TREE_CODE (expr
) == COMPLEX_CST
)
2811 return (integer_onep (TREE_REALPART (expr
))
2812 && integer_onep (TREE_IMAGPART (expr
)));
2814 return integer_onep (expr
);
2817 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
2818 it contains, or a complex or vector whose subparts are such integers,
2819 or a location wrapper for such a constant. */
2822 integer_all_onesp (const_tree expr
)
2824 STRIP_ANY_LOCATION_WRAPPER (expr
);
2826 if (TREE_CODE (expr
) == COMPLEX_CST
2827 && integer_all_onesp (TREE_REALPART (expr
))
2828 && integer_all_onesp (TREE_IMAGPART (expr
)))
2831 else if (TREE_CODE (expr
) == VECTOR_CST
)
2832 return (VECTOR_CST_NPATTERNS (expr
) == 1
2833 && VECTOR_CST_DUPLICATE_P (expr
)
2834 && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr
, 0)));
2836 else if (TREE_CODE (expr
) != INTEGER_CST
)
2839 return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr
)), UNSIGNED
)
2840 == wi::to_wide (expr
));
2843 /* Return 1 if EXPR is the integer constant minus one, or a location wrapper
2844 for such a constant. */
2847 integer_minus_onep (const_tree expr
)
2849 STRIP_ANY_LOCATION_WRAPPER (expr
);
2851 if (TREE_CODE (expr
) == COMPLEX_CST
)
2852 return (integer_all_onesp (TREE_REALPART (expr
))
2853 && integer_zerop (TREE_IMAGPART (expr
)));
2855 return integer_all_onesp (expr
);
2858 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2859 one bit on), or a location wrapper for such a constant. */
2862 integer_pow2p (const_tree expr
)
2864 STRIP_ANY_LOCATION_WRAPPER (expr
);
2866 if (TREE_CODE (expr
) == COMPLEX_CST
2867 && integer_pow2p (TREE_REALPART (expr
))
2868 && integer_zerop (TREE_IMAGPART (expr
)))
2871 if (TREE_CODE (expr
) != INTEGER_CST
)
2874 return wi::popcount (wi::to_wide (expr
)) == 1;
2877 /* Return 1 if EXPR is an integer constant other than zero or a
2878 complex constant other than zero, or a location wrapper for such a
2882 integer_nonzerop (const_tree expr
)
2884 STRIP_ANY_LOCATION_WRAPPER (expr
);
2886 return ((TREE_CODE (expr
) == INTEGER_CST
2887 && wi::to_wide (expr
) != 0)
2888 || (TREE_CODE (expr
) == COMPLEX_CST
2889 && (integer_nonzerop (TREE_REALPART (expr
))
2890 || integer_nonzerop (TREE_IMAGPART (expr
)))));
2893 /* Return 1 if EXPR is the integer constant one. For vector,
2894 return 1 if every piece is the integer constant minus one
2895 (representing the value TRUE).
2896 Also return 1 for location wrappers for such a constant. */
2899 integer_truep (const_tree expr
)
2901 STRIP_ANY_LOCATION_WRAPPER (expr
);
2903 if (TREE_CODE (expr
) == VECTOR_CST
)
2904 return integer_all_onesp (expr
);
2905 return integer_onep (expr
);
2908 /* Return 1 if EXPR is the fixed-point constant zero, or a location wrapper
2909 for such a constant. */
2912 fixed_zerop (const_tree expr
)
2914 STRIP_ANY_LOCATION_WRAPPER (expr
);
2916 return (TREE_CODE (expr
) == FIXED_CST
2917 && TREE_FIXED_CST (expr
).data
.is_zero ());
2920 /* Return the power of two represented by a tree node known to be a
2924 tree_log2 (const_tree expr
)
2926 if (TREE_CODE (expr
) == COMPLEX_CST
)
2927 return tree_log2 (TREE_REALPART (expr
));
2929 return wi::exact_log2 (wi::to_wide (expr
));
2932 /* Similar, but return the largest integer Y such that 2 ** Y is less
2933 than or equal to EXPR. */
2936 tree_floor_log2 (const_tree expr
)
2938 if (TREE_CODE (expr
) == COMPLEX_CST
)
2939 return tree_log2 (TREE_REALPART (expr
));
2941 return wi::floor_log2 (wi::to_wide (expr
));
2944 /* Return number of known trailing zero bits in EXPR, or, if the value of
2945 EXPR is known to be zero, the precision of it's type. */
2948 tree_ctz (const_tree expr
)
2950 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
2951 && !POINTER_TYPE_P (TREE_TYPE (expr
)))
2954 unsigned int ret1
, ret2
, prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2955 switch (TREE_CODE (expr
))
2958 ret1
= wi::ctz (wi::to_wide (expr
));
2959 return MIN (ret1
, prec
);
2961 ret1
= wi::ctz (get_nonzero_bits (expr
));
2962 return MIN (ret1
, prec
);
2969 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2972 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2973 return MIN (ret1
, ret2
);
2974 case POINTER_PLUS_EXPR
:
2975 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2976 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2977 /* Second operand is sizetype, which could be in theory
2978 wider than pointer's precision. Make sure we never
2979 return more than prec. */
2980 ret2
= MIN (ret2
, prec
);
2981 return MIN (ret1
, ret2
);
2983 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2984 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2985 return MAX (ret1
, ret2
);
2987 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2988 ret2
= tree_ctz (TREE_OPERAND (expr
, 1));
2989 return MIN (ret1
+ ret2
, prec
);
2991 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
2992 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
2993 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
2995 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
2996 return MIN (ret1
+ ret2
, prec
);
3000 if (tree_fits_uhwi_p (TREE_OPERAND (expr
, 1))
3001 && (tree_to_uhwi (TREE_OPERAND (expr
, 1)) < prec
))
3003 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
3004 ret2
= tree_to_uhwi (TREE_OPERAND (expr
, 1));
3009 case TRUNC_DIV_EXPR
:
3011 case FLOOR_DIV_EXPR
:
3012 case ROUND_DIV_EXPR
:
3013 case EXACT_DIV_EXPR
:
3014 if (TREE_CODE (TREE_OPERAND (expr
, 1)) == INTEGER_CST
3015 && tree_int_cst_sgn (TREE_OPERAND (expr
, 1)) == 1)
3017 int l
= tree_log2 (TREE_OPERAND (expr
, 1));
3020 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
3028 ret1
= tree_ctz (TREE_OPERAND (expr
, 0));
3029 if (ret1
&& ret1
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
3031 return MIN (ret1
, prec
);
3033 return tree_ctz (TREE_OPERAND (expr
, 0));
3035 ret1
= tree_ctz (TREE_OPERAND (expr
, 1));
3038 ret2
= tree_ctz (TREE_OPERAND (expr
, 2));
3039 return MIN (ret1
, ret2
);
3041 return tree_ctz (TREE_OPERAND (expr
, 1));
3043 ret1
= get_pointer_alignment (CONST_CAST_TREE (expr
));
3044 if (ret1
> BITS_PER_UNIT
)
3046 ret1
= ctz_hwi (ret1
/ BITS_PER_UNIT
);
3047 return MIN (ret1
, prec
);
3055 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
3056 decimal float constants, so don't return 1 for them.
3057 Also return 1 for location wrappers around such a constant. */
3060 real_zerop (const_tree expr
)
3062 STRIP_ANY_LOCATION_WRAPPER (expr
);
3064 switch (TREE_CODE (expr
))
3067 return real_equal (&TREE_REAL_CST (expr
), &dconst0
)
3068 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
3070 return real_zerop (TREE_REALPART (expr
))
3071 && real_zerop (TREE_IMAGPART (expr
));
3074 /* Don't simply check for a duplicate because the predicate
3075 accepts both +0.0 and -0.0. */
3076 unsigned count
= vector_cst_encoded_nelts (expr
);
3077 for (unsigned int i
= 0; i
< count
; ++i
)
3078 if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr
, i
)))
3087 /* Return 1 if EXPR is the real constant one in real or complex form.
3088 Trailing zeroes matter for decimal float constants, so don't return
3090 Also return 1 for location wrappers around such a constant. */
3093 real_onep (const_tree expr
)
3095 STRIP_ANY_LOCATION_WRAPPER (expr
);
3097 switch (TREE_CODE (expr
))
3100 return real_equal (&TREE_REAL_CST (expr
), &dconst1
)
3101 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
3103 return real_onep (TREE_REALPART (expr
))
3104 && real_zerop (TREE_IMAGPART (expr
));
3106 return (VECTOR_CST_NPATTERNS (expr
) == 1
3107 && VECTOR_CST_DUPLICATE_P (expr
)
3108 && real_onep (VECTOR_CST_ENCODED_ELT (expr
, 0)));
3114 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
3115 matter for decimal float constants, so don't return 1 for them.
3116 Also return 1 for location wrappers around such a constant. */
3119 real_minus_onep (const_tree expr
)
3121 STRIP_ANY_LOCATION_WRAPPER (expr
);
3123 switch (TREE_CODE (expr
))
3126 return real_equal (&TREE_REAL_CST (expr
), &dconstm1
)
3127 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
3129 return real_minus_onep (TREE_REALPART (expr
))
3130 && real_zerop (TREE_IMAGPART (expr
));
3132 return (VECTOR_CST_NPATTERNS (expr
) == 1
3133 && VECTOR_CST_DUPLICATE_P (expr
)
3134 && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr
, 0)));
3140 /* Nonzero if EXP is a constant or a cast of a constant. */
3143 really_constant_p (const_tree exp
)
3145 /* This is not quite the same as STRIP_NOPS. It does more. */
3146 while (CONVERT_EXPR_P (exp
)
3147 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3148 exp
= TREE_OPERAND (exp
, 0);
3149 return TREE_CONSTANT (exp
);
3152 /* Return true if T holds a polynomial pointer difference, storing it in
3153 *VALUE if so. A true return means that T's precision is no greater
3154 than 64 bits, which is the largest address space we support, so *VALUE
3155 never loses precision. However, the signedness of the result does
3156 not necessarily match the signedness of T: sometimes an unsigned type
3157 like sizetype is used to encode a value that is actually negative. */
3160 ptrdiff_tree_p (const_tree t
, poly_int64_pod
*value
)
3164 if (TREE_CODE (t
) == INTEGER_CST
)
3166 if (!cst_and_fits_in_hwi (t
))
3168 *value
= int_cst_value (t
);
3171 if (POLY_INT_CST_P (t
))
3173 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
3174 if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t
, i
)))
3176 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
3177 value
->coeffs
[i
] = int_cst_value (POLY_INT_CST_COEFF (t
, i
));
3184 tree_to_poly_int64 (const_tree t
)
3186 gcc_assert (tree_fits_poly_int64_p (t
));
3187 if (POLY_INT_CST_P (t
))
3188 return poly_int_cst_value (t
).force_shwi ();
3189 return TREE_INT_CST_LOW (t
);
3193 tree_to_poly_uint64 (const_tree t
)
3195 gcc_assert (tree_fits_poly_uint64_p (t
));
3196 if (POLY_INT_CST_P (t
))
3197 return poly_int_cst_value (t
).force_uhwi ();
3198 return TREE_INT_CST_LOW (t
);
3201 /* Return first list element whose TREE_VALUE is ELEM.
3202 Return 0 if ELEM is not in LIST. */
3205 value_member (tree elem
, tree list
)
3209 if (elem
== TREE_VALUE (list
))
3211 list
= TREE_CHAIN (list
);
3216 /* Return first list element whose TREE_PURPOSE is ELEM.
3217 Return 0 if ELEM is not in LIST. */
3220 purpose_member (const_tree elem
, tree list
)
3224 if (elem
== TREE_PURPOSE (list
))
3226 list
= TREE_CHAIN (list
);
3231 /* Return true if ELEM is in V. */
3234 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
3238 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
3244 /* Returns element number IDX (zero-origin) of chain CHAIN, or
3248 chain_index (int idx
, tree chain
)
3250 for (; chain
&& idx
> 0; --idx
)
3251 chain
= TREE_CHAIN (chain
);
3255 /* Return nonzero if ELEM is part of the chain CHAIN. */
3258 chain_member (const_tree elem
, const_tree chain
)
3264 chain
= DECL_CHAIN (chain
);
3270 /* Return the length of a chain of nodes chained through TREE_CHAIN.
3271 We expect a null pointer to mark the end of the chain.
3272 This is the Lisp primitive `length'. */
3275 list_length (const_tree t
)
3278 #ifdef ENABLE_TREE_CHECKING
3286 #ifdef ENABLE_TREE_CHECKING
3289 gcc_assert (p
!= q
);
3297 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3298 UNION_TYPE TYPE, or NULL_TREE if none. */
3301 first_field (const_tree type
)
3303 tree t
= TYPE_FIELDS (type
);
3304 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
3309 /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3310 UNION_TYPE TYPE, or NULL_TREE if none. */
3313 last_field (const_tree type
)
3315 tree last
= NULL_TREE
;
3317 for (tree fld
= TYPE_FIELDS (type
); fld
; fld
= TREE_CHAIN (fld
))
3319 if (TREE_CODE (fld
) != FIELD_DECL
)
3328 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3329 by modifying the last node in chain 1 to point to chain 2.
3330 This is the Lisp primitive `nconc'. */
3333 chainon (tree op1
, tree op2
)
3342 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
3344 TREE_CHAIN (t1
) = op2
;
3346 #ifdef ENABLE_TREE_CHECKING
3349 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
3350 gcc_assert (t2
!= t1
);
3357 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3360 tree_last (tree chain
)
3364 while ((next
= TREE_CHAIN (chain
)))
3369 /* Reverse the order of elements in the chain T,
3370 and return the new head of the chain (old last element). */
3375 tree prev
= 0, decl
, next
;
3376 for (decl
= t
; decl
; decl
= next
)
3378 /* We shouldn't be using this function to reverse BLOCK chains; we
3379 have blocks_nreverse for that. */
3380 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
3381 next
= TREE_CHAIN (decl
);
3382 TREE_CHAIN (decl
) = prev
;
3388 /* Return a newly created TREE_LIST node whose
3389 purpose and value fields are PARM and VALUE. */
3392 build_tree_list (tree parm
, tree value MEM_STAT_DECL
)
3394 tree t
= make_node (TREE_LIST PASS_MEM_STAT
);
3395 TREE_PURPOSE (t
) = parm
;
3396 TREE_VALUE (t
) = value
;
3400 /* Build a chain of TREE_LIST nodes from a vector. */
3403 build_tree_list_vec (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
3405 tree ret
= NULL_TREE
;
3409 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
3411 *pp
= build_tree_list (NULL
, t PASS_MEM_STAT
);
3412 pp
= &TREE_CHAIN (*pp
);
3417 /* Return a newly created TREE_LIST node whose
3418 purpose and value fields are PURPOSE and VALUE
3419 and whose TREE_CHAIN is CHAIN. */
3422 tree_cons (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
3426 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
3427 memset (node
, 0, sizeof (struct tree_common
));
3429 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
3431 TREE_SET_CODE (node
, TREE_LIST
);
3432 TREE_CHAIN (node
) = chain
;
3433 TREE_PURPOSE (node
) = purpose
;
3434 TREE_VALUE (node
) = value
;
3438 /* Return the values of the elements of a CONSTRUCTOR as a vector of
3442 ctor_to_vec (tree ctor
)
3444 vec
<tree
, va_gc
> *vec
;
3445 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
3449 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
3450 vec
->quick_push (val
);
3455 /* Return the size nominally occupied by an object of type TYPE
3456 when it resides in memory. The value is measured in units of bytes,
3457 and its data type is that normally used for type sizes
3458 (which is the first type created by make_signed_type or
3459 make_unsigned_type). */
3462 size_in_bytes_loc (location_t loc
, const_tree type
)
3466 if (type
== error_mark_node
)
3467 return integer_zero_node
;
3469 type
= TYPE_MAIN_VARIANT (type
);
3470 t
= TYPE_SIZE_UNIT (type
);
3474 lang_hooks
.types
.incomplete_type_error (loc
, NULL_TREE
, type
);
3475 return size_zero_node
;
3481 /* Return the size of TYPE (in bytes) as a wide integer
3482 or return -1 if the size can vary or is larger than an integer. */
3485 int_size_in_bytes (const_tree type
)
3489 if (type
== error_mark_node
)
3492 type
= TYPE_MAIN_VARIANT (type
);
3493 t
= TYPE_SIZE_UNIT (type
);
3495 if (t
&& tree_fits_uhwi_p (t
))
3496 return TREE_INT_CST_LOW (t
);
3501 /* Return the maximum size of TYPE (in bytes) as a wide integer
3502 or return -1 if the size can vary or is larger than an integer. */
3505 max_int_size_in_bytes (const_tree type
)
3507 HOST_WIDE_INT size
= -1;
3510 /* If this is an array type, check for a possible MAX_SIZE attached. */
3512 if (TREE_CODE (type
) == ARRAY_TYPE
)
3514 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
3516 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
3517 size
= tree_to_uhwi (size_tree
);
3520 /* If we still haven't been able to get a size, see if the language
3521 can compute a maximum size. */
3525 size_tree
= lang_hooks
.types
.max_size (type
);
3527 if (size_tree
&& tree_fits_uhwi_p (size_tree
))
3528 size
= tree_to_uhwi (size_tree
);
3534 /* Return the bit position of FIELD, in bits from the start of the record.
3535 This is a tree of type bitsizetype. */
3538 bit_position (const_tree field
)
3540 return bit_from_pos (DECL_FIELD_OFFSET (field
),
3541 DECL_FIELD_BIT_OFFSET (field
));
3544 /* Return the byte position of FIELD, in bytes from the start of the record.
3545 This is a tree of type sizetype. */
3548 byte_position (const_tree field
)
3550 return byte_from_pos (DECL_FIELD_OFFSET (field
),
3551 DECL_FIELD_BIT_OFFSET (field
));
3554 /* Likewise, but return as an integer. It must be representable in
3555 that way (since it could be a signed value, we don't have the
3556 option of returning -1 like int_size_in_byte can. */
3559 int_byte_position (const_tree field
)
3561 return tree_to_shwi (byte_position (field
));
3564 /* Return, as a tree node, the number of elements for TYPE (which is an
3565 ARRAY_TYPE) minus one. This counts only elements of the top array. */
3568 array_type_nelts (const_tree type
)
3570 tree index_type
, min
, max
;
3572 /* If they did it with unspecified bounds, then we should have already
3573 given an error about it before we got here. */
3574 if (! TYPE_DOMAIN (type
))
3575 return error_mark_node
;
3577 index_type
= TYPE_DOMAIN (type
);
3578 min
= TYPE_MIN_VALUE (index_type
);
3579 max
= TYPE_MAX_VALUE (index_type
);
3581 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3584 /* zero sized arrays are represented from C FE as complete types with
3585 NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3586 them as min 0, max -1. */
3587 if (COMPLETE_TYPE_P (type
)
3588 && integer_zerop (TYPE_SIZE (type
))
3589 && integer_zerop (min
))
3590 return build_int_cst (TREE_TYPE (min
), -1);
3592 return error_mark_node
;
3595 return (integer_zerop (min
)
3597 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
3600 /* If arg is static -- a reference to an object in static storage -- then
3601 return the object. This is not the same as the C meaning of `static'.
3602 If arg isn't static, return NULL. */
3607 switch (TREE_CODE (arg
))
3610 /* Nested functions are static, even though taking their address will
3611 involve a trampoline as we unnest the nested function and create
3612 the trampoline on the tree level. */
3616 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3617 && ! DECL_THREAD_LOCAL_P (arg
)
3618 && ! DECL_DLLIMPORT_P (arg
)
3622 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
3626 return TREE_STATIC (arg
) ? arg
: NULL
;
3633 /* If the thing being referenced is not a field, then it is
3634 something language specific. */
3635 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
3637 /* If we are referencing a bitfield, we can't evaluate an
3638 ADDR_EXPR at compile time and so it isn't a constant. */
3639 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
3642 return staticp (TREE_OPERAND (arg
, 0));
3648 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
3651 case ARRAY_RANGE_REF
:
3652 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
3653 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
3654 return staticp (TREE_OPERAND (arg
, 0));
3658 case COMPOUND_LITERAL_EXPR
:
3659 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
3669 /* Return whether OP is a DECL whose address is function-invariant. */
3672 decl_address_invariant_p (const_tree op
)
3674 /* The conditions below are slightly less strict than the one in
3677 switch (TREE_CODE (op
))
3686 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3687 || DECL_THREAD_LOCAL_P (op
)
3688 || DECL_CONTEXT (op
) == current_function_decl
3689 || decl_function_context (op
) == current_function_decl
)
3694 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3695 || decl_function_context (op
) == current_function_decl
)
3706 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3709 decl_address_ip_invariant_p (const_tree op
)
3711 /* The conditions below are slightly less strict than the one in
3714 switch (TREE_CODE (op
))
3722 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
3723 && !DECL_DLLIMPORT_P (op
))
3724 || DECL_THREAD_LOCAL_P (op
))
3729 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
3741 /* Return true if T is function-invariant (internal function, does
3742 not handle arithmetic; that's handled in skip_simple_arithmetic and
3743 tree_invariant_p). */
3746 tree_invariant_p_1 (tree t
)
3750 if (TREE_CONSTANT (t
)
3751 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
3754 switch (TREE_CODE (t
))
3760 op
= TREE_OPERAND (t
, 0);
3761 while (handled_component_p (op
))
3763 switch (TREE_CODE (op
))
3766 case ARRAY_RANGE_REF
:
3767 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
3768 || TREE_OPERAND (op
, 2) != NULL_TREE
3769 || TREE_OPERAND (op
, 3) != NULL_TREE
)
3774 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
3780 op
= TREE_OPERAND (op
, 0);
3783 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
3792 /* Return true if T is function-invariant. */
3795 tree_invariant_p (tree t
)
3797 tree inner
= skip_simple_arithmetic (t
);
3798 return tree_invariant_p_1 (inner
);
3801 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
3802 Do this to any expression which may be used in more than one place,
3803 but must be evaluated only once.
3805 Normally, expand_expr would reevaluate the expression each time.
3806 Calling save_expr produces something that is evaluated and recorded
3807 the first time expand_expr is called on it. Subsequent calls to
3808 expand_expr just reuse the recorded value.
3810 The call to expand_expr that generates code that actually computes
3811 the value is the first call *at compile time*. Subsequent calls
3812 *at compile time* generate code to use the saved value.
3813 This produces correct result provided that *at run time* control
3814 always flows through the insns made by the first expand_expr
3815 before reaching the other places where the save_expr was evaluated.
3816 You, the caller of save_expr, must make sure this is so.
3818 Constants, and certain read-only nodes, are returned with no
3819 SAVE_EXPR because that is safe. Expressions containing placeholders
3820 are not touched; see tree.def for an explanation of what these
3824 save_expr (tree expr
)
3828 /* If the tree evaluates to a constant, then we don't want to hide that
3829 fact (i.e. this allows further folding, and direct checks for constants).
3830 However, a read-only object that has side effects cannot be bypassed.
3831 Since it is no problem to reevaluate literals, we just return the
3833 inner
= skip_simple_arithmetic (expr
);
3834 if (TREE_CODE (inner
) == ERROR_MARK
)
3837 if (tree_invariant_p_1 (inner
))
3840 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
3841 it means that the size or offset of some field of an object depends on
3842 the value within another field.
3844 Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
3845 and some variable since it would then need to be both evaluated once and
3846 evaluated more than once. Front-ends must assure this case cannot
3847 happen by surrounding any such subexpressions in their own SAVE_EXPR
3848 and forcing evaluation at the proper time. */
3849 if (contains_placeholder_p (inner
))
3852 expr
= build1_loc (EXPR_LOCATION (expr
), SAVE_EXPR
, TREE_TYPE (expr
), expr
);
3854 /* This expression might be placed ahead of a jump to ensure that the
3855 value was computed on both sides of the jump. So make sure it isn't
3856 eliminated as dead. */
3857 TREE_SIDE_EFFECTS (expr
) = 1;
3861 /* Look inside EXPR into any simple arithmetic operations. Return the
3862 outermost non-arithmetic or non-invariant node. */
3865 skip_simple_arithmetic (tree expr
)
3867 /* We don't care about whether this can be used as an lvalue in this
3869 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3870 expr
= TREE_OPERAND (expr
, 0);
3872 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3873 a constant, it will be more efficient to not make another SAVE_EXPR since
3874 it will allow better simplification and GCSE will be able to merge the
3875 computations if they actually occur. */
3878 if (UNARY_CLASS_P (expr
))
3879 expr
= TREE_OPERAND (expr
, 0);
3880 else if (BINARY_CLASS_P (expr
))
3882 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
3883 expr
= TREE_OPERAND (expr
, 0);
3884 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
3885 expr
= TREE_OPERAND (expr
, 1);
3896 /* Look inside EXPR into simple arithmetic operations involving constants.
3897 Return the outermost non-arithmetic or non-constant node. */
3900 skip_simple_constant_arithmetic (tree expr
)
3902 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3903 expr
= TREE_OPERAND (expr
, 0);
3907 if (UNARY_CLASS_P (expr
))
3908 expr
= TREE_OPERAND (expr
, 0);
3909 else if (BINARY_CLASS_P (expr
))
3911 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
3912 expr
= TREE_OPERAND (expr
, 0);
3913 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3914 expr
= TREE_OPERAND (expr
, 1);
3925 /* Return which tree structure is used by T. */
3927 enum tree_node_structure_enum
3928 tree_node_structure (const_tree t
)
3930 const enum tree_code code
= TREE_CODE (t
);
3931 return tree_node_structure_for_code (code
);
3934 /* Set various status flags when building a CALL_EXPR object T. */
3937 process_call_operands (tree t
)
3939 bool side_effects
= TREE_SIDE_EFFECTS (t
);
3940 bool read_only
= false;
3941 int i
= call_expr_flags (t
);
3943 /* Calls have side-effects, except those to const or pure functions. */
3944 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
3945 side_effects
= true;
3946 /* Propagate TREE_READONLY of arguments for const functions. */
3950 if (!side_effects
|| read_only
)
3951 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3953 tree op
= TREE_OPERAND (t
, i
);
3954 if (op
&& TREE_SIDE_EFFECTS (op
))
3955 side_effects
= true;
3956 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3960 TREE_SIDE_EFFECTS (t
) = side_effects
;
3961 TREE_READONLY (t
) = read_only
;
3964 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3965 size or offset that depends on a field within a record. */
3968 contains_placeholder_p (const_tree exp
)
3970 enum tree_code code
;
3975 code
= TREE_CODE (exp
);
3976 if (code
== PLACEHOLDER_EXPR
)
3979 switch (TREE_CODE_CLASS (code
))
3982 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3983 position computations since they will be converted into a
3984 WITH_RECORD_EXPR involving the reference, which will assume
3985 here will be valid. */
3986 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3988 case tcc_exceptional
:
3989 if (code
== TREE_LIST
)
3990 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3991 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3996 case tcc_comparison
:
3997 case tcc_expression
:
4001 /* Ignoring the first operand isn't quite right, but works best. */
4002 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
4005 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
4006 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
4007 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
4010 /* The save_expr function never wraps anything containing
4011 a PLACEHOLDER_EXPR. */
4018 switch (TREE_CODE_LENGTH (code
))
4021 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
4023 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
4024 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
4035 const_call_expr_arg_iterator iter
;
4036 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
4037 if (CONTAINS_PLACEHOLDER_P (arg
))
4051 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4052 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4056 type_contains_placeholder_1 (const_tree type
)
4058 /* If the size contains a placeholder or the parent type (component type in
4059 the case of arrays) type involves a placeholder, this type does. */
4060 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
4061 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
4062 || (!POINTER_TYPE_P (type
)
4064 && type_contains_placeholder_p (TREE_TYPE (type
))))
4067 /* Now do type-specific checks. Note that the last part of the check above
4068 greatly limits what we have to do below. */
4069 switch (TREE_CODE (type
))
4078 case REFERENCE_TYPE
:
4087 case FIXED_POINT_TYPE
:
4088 /* Here we just check the bounds. */
4089 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
4090 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
4093 /* We have already checked the component type above, so just check
4094 the domain type. Flexible array members have a null domain. */
4095 return TYPE_DOMAIN (type
) ?
4096 type_contains_placeholder_p (TYPE_DOMAIN (type
)) : false;
4100 case QUAL_UNION_TYPE
:
4104 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
4105 if (TREE_CODE (field
) == FIELD_DECL
4106 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
4107 || (TREE_CODE (type
) == QUAL_UNION_TYPE
4108 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
4109 || type_contains_placeholder_p (TREE_TYPE (field
))))
4120 /* Wrapper around above function used to cache its result. */
4123 type_contains_placeholder_p (tree type
)
4127 /* If the contains_placeholder_bits field has been initialized,
4128 then we know the answer. */
4129 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
4130 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
4132 /* Indicate that we've seen this type node, and the answer is false.
4133 This is what we want to return if we run into recursion via fields. */
4134 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
4136 /* Compute the real value. */
4137 result
= type_contains_placeholder_1 (type
);
4139 /* Store the real value. */
4140 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
4145 /* Push tree EXP onto vector QUEUE if it is not already present. */
4148 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
4153 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
4154 if (simple_cst_equal (iter
, exp
) == 1)
4158 queue
->safe_push (exp
);
4161 /* Given a tree EXP, find all occurrences of references to fields
4162 in a PLACEHOLDER_EXPR and place them in vector REFS without
4163 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4164 we assume here that EXP contains only arithmetic expressions
4165 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4169 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
4171 enum tree_code code
= TREE_CODE (exp
);
4175 /* We handle TREE_LIST and COMPONENT_REF separately. */
4176 if (code
== TREE_LIST
)
4178 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
4179 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
4181 else if (code
== COMPONENT_REF
)
4183 for (inner
= TREE_OPERAND (exp
, 0);
4184 REFERENCE_CLASS_P (inner
);
4185 inner
= TREE_OPERAND (inner
, 0))
4188 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
4189 push_without_duplicates (exp
, refs
);
4191 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
4194 switch (TREE_CODE_CLASS (code
))
4199 case tcc_declaration
:
4200 /* Variables allocated to static storage can stay. */
4201 if (!TREE_STATIC (exp
))
4202 push_without_duplicates (exp
, refs
);
4205 case tcc_expression
:
4206 /* This is the pattern built in ada/make_aligning_type. */
4207 if (code
== ADDR_EXPR
4208 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
4210 push_without_duplicates (exp
, refs
);
4216 case tcc_exceptional
:
4219 case tcc_comparison
:
4221 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
4222 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
4226 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4227 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
4235 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4236 return a tree with all occurrences of references to F in a
4237 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4238 CONST_DECLs. Note that we assume here that EXP contains only
4239 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4240 occurring only in their argument list. */
4243 substitute_in_expr (tree exp
, tree f
, tree r
)
4245 enum tree_code code
= TREE_CODE (exp
);
4246 tree op0
, op1
, op2
, op3
;
4249 /* We handle TREE_LIST and COMPONENT_REF separately. */
4250 if (code
== TREE_LIST
)
4252 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
4253 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
4254 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
4257 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
4259 else if (code
== COMPONENT_REF
)
4263 /* If this expression is getting a value from a PLACEHOLDER_EXPR
4264 and it is the right field, replace it with R. */
4265 for (inner
= TREE_OPERAND (exp
, 0);
4266 REFERENCE_CLASS_P (inner
);
4267 inner
= TREE_OPERAND (inner
, 0))
4271 op1
= TREE_OPERAND (exp
, 1);
4273 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
4276 /* If this expression hasn't been completed let, leave it alone. */
4277 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
4280 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
4281 if (op0
== TREE_OPERAND (exp
, 0))
4285 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
4288 switch (TREE_CODE_CLASS (code
))
4293 case tcc_declaration
:
4299 case tcc_expression
:
4305 case tcc_exceptional
:
4308 case tcc_comparison
:
4310 switch (TREE_CODE_LENGTH (code
))
4316 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
4317 if (op0
== TREE_OPERAND (exp
, 0))
4320 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
4324 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
4325 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
4327 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
4330 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
4334 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
4335 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
4336 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
4338 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4339 && op2
== TREE_OPERAND (exp
, 2))
4342 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
4346 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
4347 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
4348 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
4349 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
4351 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4352 && op2
== TREE_OPERAND (exp
, 2)
4353 && op3
== TREE_OPERAND (exp
, 3))
4357 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
4369 new_tree
= NULL_TREE
;
4371 /* If we are trying to replace F with a constant or with another
4372 instance of one of the arguments of the call, inline back
4373 functions which do nothing else than computing a value from
4374 the arguments they are passed. This makes it possible to
4375 fold partially or entirely the replacement expression. */
4376 if (code
== CALL_EXPR
)
4378 bool maybe_inline
= false;
4379 if (CONSTANT_CLASS_P (r
))
4380 maybe_inline
= true;
4382 for (i
= 3; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4383 if (operand_equal_p (TREE_OPERAND (exp
, i
), r
, 0))
4385 maybe_inline
= true;
4390 tree t
= maybe_inline_call_in_expr (exp
);
4392 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
4396 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4398 tree op
= TREE_OPERAND (exp
, i
);
4399 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
4403 new_tree
= copy_node (exp
);
4404 TREE_OPERAND (new_tree
, i
) = new_op
;
4410 new_tree
= fold (new_tree
);
4411 if (TREE_CODE (new_tree
) == CALL_EXPR
)
4412 process_call_operands (new_tree
);
4423 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
4425 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
4426 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
4431 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4432 for it within OBJ, a tree that is an object or a chain of references. */
4435 substitute_placeholder_in_expr (tree exp
, tree obj
)
4437 enum tree_code code
= TREE_CODE (exp
);
4438 tree op0
, op1
, op2
, op3
;
4441 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4442 in the chain of OBJ. */
4443 if (code
== PLACEHOLDER_EXPR
)
4445 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
4448 for (elt
= obj
; elt
!= 0;
4449 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
4450 || TREE_CODE (elt
) == COND_EXPR
)
4451 ? TREE_OPERAND (elt
, 1)
4452 : (REFERENCE_CLASS_P (elt
)
4453 || UNARY_CLASS_P (elt
)
4454 || BINARY_CLASS_P (elt
)
4455 || VL_EXP_CLASS_P (elt
)
4456 || EXPRESSION_CLASS_P (elt
))
4457 ? TREE_OPERAND (elt
, 0) : 0))
4458 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
4461 for (elt
= obj
; elt
!= 0;
4462 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
4463 || TREE_CODE (elt
) == COND_EXPR
)
4464 ? TREE_OPERAND (elt
, 1)
4465 : (REFERENCE_CLASS_P (elt
)
4466 || UNARY_CLASS_P (elt
)
4467 || BINARY_CLASS_P (elt
)
4468 || VL_EXP_CLASS_P (elt
)
4469 || EXPRESSION_CLASS_P (elt
))
4470 ? TREE_OPERAND (elt
, 0) : 0))
4471 if (POINTER_TYPE_P (TREE_TYPE (elt
))
4472 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
4474 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
4476 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4477 survives until RTL generation, there will be an error. */
4481 /* TREE_LIST is special because we need to look at TREE_VALUE
4482 and TREE_CHAIN, not TREE_OPERANDS. */
4483 else if (code
== TREE_LIST
)
4485 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
4486 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
4487 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
4490 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
4493 switch (TREE_CODE_CLASS (code
))
4496 case tcc_declaration
:
4499 case tcc_exceptional
:
4502 case tcc_comparison
:
4503 case tcc_expression
:
4506 switch (TREE_CODE_LENGTH (code
))
4512 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4513 if (op0
== TREE_OPERAND (exp
, 0))
4516 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
4520 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4521 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4523 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
4526 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
4530 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4531 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4532 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
4534 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4535 && op2
== TREE_OPERAND (exp
, 2))
4538 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
4542 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
4543 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
4544 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
4545 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
4547 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
4548 && op2
== TREE_OPERAND (exp
, 2)
4549 && op3
== TREE_OPERAND (exp
, 3))
4553 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
4565 new_tree
= NULL_TREE
;
4567 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
4569 tree op
= TREE_OPERAND (exp
, i
);
4570 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
4574 new_tree
= copy_node (exp
);
4575 TREE_OPERAND (new_tree
, i
) = new_op
;
4581 new_tree
= fold (new_tree
);
4582 if (TREE_CODE (new_tree
) == CALL_EXPR
)
4583 process_call_operands (new_tree
);
4594 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
4596 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
4597 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
4603 /* Subroutine of stabilize_reference; this is called for subtrees of
4604 references. Any expression with side-effects must be put in a SAVE_EXPR
4605 to ensure that it is only evaluated once.
4607 We don't put SAVE_EXPR nodes around everything, because assigning very
4608 simple expressions to temporaries causes us to miss good opportunities
4609 for optimizations. Among other things, the opportunity to fold in the
4610 addition of a constant into an addressing mode often gets lost, e.g.
4611 "y[i+1] += x;". In general, we take the approach that we should not make
4612 an assignment unless we are forced into it - i.e., that any non-side effect
4613 operator should be allowed, and that cse should take care of coalescing
4614 multiple utterances of the same expression should that prove fruitful. */
4617 stabilize_reference_1 (tree e
)
4620 enum tree_code code
= TREE_CODE (e
);
4622 /* We cannot ignore const expressions because it might be a reference
4623 to a const array but whose index contains side-effects. But we can
4624 ignore things that are actual constant or that already have been
4625 handled by this function. */
4627 if (tree_invariant_p (e
))
4630 switch (TREE_CODE_CLASS (code
))
4632 case tcc_exceptional
:
4633 /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4634 have side-effects. */
4635 if (code
== STATEMENT_LIST
)
4636 return save_expr (e
);
4639 case tcc_declaration
:
4640 case tcc_comparison
:
4642 case tcc_expression
:
4645 /* If the expression has side-effects, then encase it in a SAVE_EXPR
4646 so that it will only be evaluated once. */
4647 /* The reference (r) and comparison (<) classes could be handled as
4648 below, but it is generally faster to only evaluate them once. */
4649 if (TREE_SIDE_EFFECTS (e
))
4650 return save_expr (e
);
4654 /* Constants need no processing. In fact, we should never reach
4659 /* Division is slow and tends to be compiled with jumps,
4660 especially the division by powers of 2 that is often
4661 found inside of an array reference. So do it just once. */
4662 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
4663 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
4664 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
4665 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
4666 return save_expr (e
);
4667 /* Recursively stabilize each operand. */
4668 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
4669 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
4673 /* Recursively stabilize each operand. */
4674 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
4681 TREE_TYPE (result
) = TREE_TYPE (e
);
4682 TREE_READONLY (result
) = TREE_READONLY (e
);
4683 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
4684 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
4689 /* Stabilize a reference so that we can use it any number of times
4690 without causing its operands to be evaluated more than once.
4691 Returns the stabilized reference. This works by means of save_expr,
4692 so see the caveats in the comments about save_expr.
4694 Also allows conversion expressions whose operands are references.
4695 Any other kind of expression is returned unchanged. */
4698 stabilize_reference (tree ref
)
4701 enum tree_code code
= TREE_CODE (ref
);
4708 /* No action is needed in this case. */
4713 case FIX_TRUNC_EXPR
:
4714 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
4718 result
= build_nt (INDIRECT_REF
,
4719 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
4723 result
= build_nt (COMPONENT_REF
,
4724 stabilize_reference (TREE_OPERAND (ref
, 0)),
4725 TREE_OPERAND (ref
, 1), NULL_TREE
);
4729 result
= build_nt (BIT_FIELD_REF
,
4730 stabilize_reference (TREE_OPERAND (ref
, 0)),
4731 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
4732 REF_REVERSE_STORAGE_ORDER (result
) = REF_REVERSE_STORAGE_ORDER (ref
);
4736 result
= build_nt (ARRAY_REF
,
4737 stabilize_reference (TREE_OPERAND (ref
, 0)),
4738 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4739 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4742 case ARRAY_RANGE_REF
:
4743 result
= build_nt (ARRAY_RANGE_REF
,
4744 stabilize_reference (TREE_OPERAND (ref
, 0)),
4745 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
4746 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
4750 /* We cannot wrap the first expression in a SAVE_EXPR, as then
4751 it wouldn't be ignored. This matters when dealing with
4753 return stabilize_reference_1 (ref
);
4755 /* If arg isn't a kind of lvalue we recognize, make no change.
4756 Caller should recognize the error for an invalid lvalue. */
4761 return error_mark_node
;
4764 TREE_TYPE (result
) = TREE_TYPE (ref
);
4765 TREE_READONLY (result
) = TREE_READONLY (ref
);
4766 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
4767 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
4768 protected_set_expr_location (result
, EXPR_LOCATION (ref
));
4773 /* Low-level constructors for expressions. */
4775 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
4776 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
4779 recompute_tree_invariant_for_addr_expr (tree t
)
4782 bool tc
= true, se
= false;
4784 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
);
4786 /* We started out assuming this address is both invariant and constant, but
4787 does not have side effects. Now go down any handled components and see if
4788 any of them involve offsets that are either non-constant or non-invariant.
4789 Also check for side-effects.
4791 ??? Note that this code makes no attempt to deal with the case where
4792 taking the address of something causes a copy due to misalignment. */
4794 #define UPDATE_FLAGS(NODE) \
4795 do { tree _node = (NODE); \
4796 if (_node && !TREE_CONSTANT (_node)) tc = false; \
4797 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
4799 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
4800 node
= TREE_OPERAND (node
, 0))
4802 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
4803 array reference (probably made temporarily by the G++ front end),
4804 so ignore all the operands. */
4805 if ((TREE_CODE (node
) == ARRAY_REF
4806 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
4807 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
4809 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
4810 if (TREE_OPERAND (node
, 2))
4811 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4812 if (TREE_OPERAND (node
, 3))
4813 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
4815 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
4816 FIELD_DECL, apparently. The G++ front end can put something else
4817 there, at least temporarily. */
4818 else if (TREE_CODE (node
) == COMPONENT_REF
4819 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
4821 if (TREE_OPERAND (node
, 2))
4822 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
4826 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
4828 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
4829 the address, since &(*a)->b is a form of addition. If it's a constant, the
4830 address is constant too. If it's a decl, its address is constant if the
4831 decl is static. Everything else is not constant and, furthermore,
4832 taking the address of a volatile variable is not volatile. */
4833 if (TREE_CODE (node
) == INDIRECT_REF
4834 || TREE_CODE (node
) == MEM_REF
)
4835 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
4836 else if (CONSTANT_CLASS_P (node
))
4838 else if (DECL_P (node
))
4839 tc
&= (staticp (node
) != NULL_TREE
);
4843 se
|= TREE_SIDE_EFFECTS (node
);
4847 TREE_CONSTANT (t
) = tc
;
4848 TREE_SIDE_EFFECTS (t
) = se
;
4852 /* Build an expression of code CODE, data type TYPE, and operands as
4853 specified. Expressions and reference nodes can be created this way.
4854 Constants, decls, types and misc nodes cannot be.
4856 We define 5 non-variadic functions, from 0 to 4 arguments. This is
4857 enough for all extant tree codes. */
4860 build0 (enum tree_code code
, tree tt MEM_STAT_DECL
)
4864 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
4866 t
= make_node (code PASS_MEM_STAT
);
4873 build1 (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
4875 int length
= sizeof (struct tree_exp
);
4878 record_node_allocation_statistics (code
, length
);
4880 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
4882 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
4884 memset (t
, 0, sizeof (struct tree_common
));
4886 TREE_SET_CODE (t
, code
);
4888 TREE_TYPE (t
) = type
;
4889 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
4890 TREE_OPERAND (t
, 0) = node
;
4891 if (node
&& !TYPE_P (node
))
4893 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
4894 TREE_READONLY (t
) = TREE_READONLY (node
);
4897 if (TREE_CODE_CLASS (code
) == tcc_statement
)
4899 if (code
!= DEBUG_BEGIN_STMT
)
4900 TREE_SIDE_EFFECTS (t
) = 1;
4905 /* All of these have side-effects, no matter what their
4907 TREE_SIDE_EFFECTS (t
) = 1;
4908 TREE_READONLY (t
) = 0;
4912 /* Whether a dereference is readonly has nothing to do with whether
4913 its operand is readonly. */
4914 TREE_READONLY (t
) = 0;
4919 recompute_tree_invariant_for_addr_expr (t
);
4923 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
4924 && node
&& !TYPE_P (node
)
4925 && TREE_CONSTANT (node
))
4926 TREE_CONSTANT (t
) = 1;
4927 if (TREE_CODE_CLASS (code
) == tcc_reference
4928 && node
&& TREE_THIS_VOLATILE (node
))
4929 TREE_THIS_VOLATILE (t
) = 1;
4936 #define PROCESS_ARG(N) \
4938 TREE_OPERAND (t, N) = arg##N; \
4939 if (arg##N &&!TYPE_P (arg##N)) \
4941 if (TREE_SIDE_EFFECTS (arg##N)) \
4943 if (!TREE_READONLY (arg##N) \
4944 && !CONSTANT_CLASS_P (arg##N)) \
4945 (void) (read_only = 0); \
4946 if (!TREE_CONSTANT (arg##N)) \
4947 (void) (constant = 0); \
4952 build2 (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
4954 bool constant
, read_only
, side_effects
, div_by_zero
;
4957 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
4959 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
4960 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
4961 /* When sizetype precision doesn't match that of pointers
4962 we need to be able to build explicit extensions or truncations
4963 of the offset argument. */
4964 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
4965 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
4966 && TREE_CODE (arg1
) == INTEGER_CST
);
4968 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4969 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4970 && ptrofftype_p (TREE_TYPE (arg1
)));
4972 t
= make_node (code PASS_MEM_STAT
);
4975 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4976 result based on those same flags for the arguments. But if the
4977 arguments aren't really even `tree' expressions, we shouldn't be trying
4980 /* Expressions without side effects may be constant if their
4981 arguments are as well. */
4982 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4983 || TREE_CODE_CLASS (code
) == tcc_binary
);
4985 side_effects
= TREE_SIDE_EFFECTS (t
);
4989 case TRUNC_DIV_EXPR
:
4991 case FLOOR_DIV_EXPR
:
4992 case ROUND_DIV_EXPR
:
4993 case EXACT_DIV_EXPR
:
4995 case FLOOR_MOD_EXPR
:
4996 case ROUND_MOD_EXPR
:
4997 case TRUNC_MOD_EXPR
:
4998 div_by_zero
= integer_zerop (arg1
);
5001 div_by_zero
= false;
5007 TREE_SIDE_EFFECTS (t
) = side_effects
;
5008 if (code
== MEM_REF
)
5010 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
5012 tree o
= TREE_OPERAND (arg0
, 0);
5013 TREE_READONLY (t
) = TREE_READONLY (o
);
5014 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
5019 TREE_READONLY (t
) = read_only
;
5020 /* Don't mark X / 0 as constant. */
5021 TREE_CONSTANT (t
) = constant
&& !div_by_zero
;
5022 TREE_THIS_VOLATILE (t
)
5023 = (TREE_CODE_CLASS (code
) == tcc_reference
5024 && arg0
&& TREE_THIS_VOLATILE (arg0
));
5032 build3 (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
5033 tree arg2 MEM_STAT_DECL
)
5035 bool constant
, read_only
, side_effects
;
5038 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
5039 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
5041 t
= make_node (code PASS_MEM_STAT
);
5046 /* As a special exception, if COND_EXPR has NULL branches, we
5047 assume that it is a gimple statement and always consider
5048 it to have side effects. */
5049 if (code
== COND_EXPR
5050 && tt
== void_type_node
5051 && arg1
== NULL_TREE
5052 && arg2
== NULL_TREE
)
5053 side_effects
= true;
5055 side_effects
= TREE_SIDE_EFFECTS (t
);
5061 if (code
== COND_EXPR
)
5062 TREE_READONLY (t
) = read_only
;
5064 TREE_SIDE_EFFECTS (t
) = side_effects
;
5065 TREE_THIS_VOLATILE (t
)
5066 = (TREE_CODE_CLASS (code
) == tcc_reference
5067 && arg0
&& TREE_THIS_VOLATILE (arg0
));
5073 build4 (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
5074 tree arg2
, tree arg3 MEM_STAT_DECL
)
5076 bool constant
, read_only
, side_effects
;
5079 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
5081 t
= make_node (code PASS_MEM_STAT
);
5084 side_effects
= TREE_SIDE_EFFECTS (t
);
5091 TREE_SIDE_EFFECTS (t
) = side_effects
;
5092 TREE_THIS_VOLATILE (t
)
5093 = (TREE_CODE_CLASS (code
) == tcc_reference
5094 && arg0
&& TREE_THIS_VOLATILE (arg0
));
5100 build5 (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
5101 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
5103 bool constant
, read_only
, side_effects
;
5106 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
5108 t
= make_node (code PASS_MEM_STAT
);
5111 side_effects
= TREE_SIDE_EFFECTS (t
);
5119 TREE_SIDE_EFFECTS (t
) = side_effects
;
5120 if (code
== TARGET_MEM_REF
)
5122 if (arg0
&& TREE_CODE (arg0
) == ADDR_EXPR
)
5124 tree o
= TREE_OPERAND (arg0
, 0);
5125 TREE_READONLY (t
) = TREE_READONLY (o
);
5126 TREE_THIS_VOLATILE (t
) = TREE_THIS_VOLATILE (o
);
5130 TREE_THIS_VOLATILE (t
)
5131 = (TREE_CODE_CLASS (code
) == tcc_reference
5132 && arg0
&& TREE_THIS_VOLATILE (arg0
));
5137 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5138 on the pointer PTR. */
5141 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
5143 poly_int64 offset
= 0;
5144 tree ptype
= TREE_TYPE (ptr
);
5146 /* For convenience allow addresses that collapse to a simple base
5148 if (TREE_CODE (ptr
) == ADDR_EXPR
5149 && (handled_component_p (TREE_OPERAND (ptr
, 0))
5150 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
5152 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
5154 if (TREE_CODE (ptr
) == MEM_REF
)
5156 offset
+= mem_ref_offset (ptr
).force_shwi ();
5157 ptr
= TREE_OPERAND (ptr
, 0);
5160 ptr
= build_fold_addr_expr (ptr
);
5161 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
5163 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
5164 ptr
, build_int_cst (ptype
, offset
));
5165 SET_EXPR_LOCATION (tem
, loc
);
5169 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5172 mem_ref_offset (const_tree t
)
5174 return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t
, 1)),
5178 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5179 offsetted by OFFSET units. */
5182 build_invariant_address (tree type
, tree base
, poly_int64 offset
)
5184 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
5185 build_fold_addr_expr (base
),
5186 build_int_cst (ptr_type_node
, offset
));
5187 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
5188 recompute_tree_invariant_for_addr_expr (addr
);
5192 /* Similar except don't specify the TREE_TYPE
5193 and leave the TREE_SIDE_EFFECTS as 0.
5194 It is permissible for arguments to be null,
5195 or even garbage if their values do not matter. */
5198 build_nt (enum tree_code code
, ...)
5205 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
5209 t
= make_node (code
);
5210 length
= TREE_CODE_LENGTH (code
);
5212 for (i
= 0; i
< length
; i
++)
5213 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
5219 /* Similar to build_nt, but for creating a CALL_EXPR object with a
5223 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
5228 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
5229 CALL_EXPR_FN (ret
) = fn
;
5230 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
5231 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
5232 CALL_EXPR_ARG (ret
, ix
) = t
;
5236 /* Create a DECL_... node of code CODE, name NAME (if non-null)
5238 We do NOT enter this node in any sort of symbol table.
5240 LOC is the location of the decl.
5242 layout_decl is used to set up the decl's storage layout.
5243 Other slots are initialized to 0 or null pointers. */
5246 build_decl (location_t loc
, enum tree_code code
, tree name
,
5247 tree type MEM_STAT_DECL
)
5251 t
= make_node (code PASS_MEM_STAT
);
5252 DECL_SOURCE_LOCATION (t
) = loc
;
5254 /* if (type == error_mark_node)
5255 type = integer_type_node; */
5256 /* That is not done, deliberately, so that having error_mark_node
5257 as the type can suppress useless errors in the use of this variable. */
5259 DECL_NAME (t
) = name
;
5260 TREE_TYPE (t
) = type
;
5262 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
5268 /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5271 build_debug_expr_decl (tree type
)
5273 tree vexpr
= make_node (DEBUG_EXPR_DECL
);
5274 DECL_ARTIFICIAL (vexpr
) = 1;
5275 TREE_TYPE (vexpr
) = type
;
5276 SET_DECL_MODE (vexpr
, TYPE_MODE (type
));
5280 /* Builds and returns function declaration with NAME and TYPE. */
5283 build_fn_decl (const char *name
, tree type
)
5285 tree id
= get_identifier (name
);
5286 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
5288 DECL_EXTERNAL (decl
) = 1;
5289 TREE_PUBLIC (decl
) = 1;
5290 DECL_ARTIFICIAL (decl
) = 1;
5291 TREE_NOTHROW (decl
) = 1;
5296 vec
<tree
, va_gc
> *all_translation_units
;
5298 /* Builds a new translation-unit decl with name NAME, queues it in the
5299 global list of translation-unit decls and returns it. */
5302 build_translation_unit_decl (tree name
)
5304 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
5306 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
5307 vec_safe_push (all_translation_units
, tu
);
5312 /* BLOCK nodes are used to represent the structure of binding contours
5313 and declarations, once those contours have been exited and their contents
5314 compiled. This information is used for outputting debugging info. */
5317 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
5319 tree block
= make_node (BLOCK
);
5321 BLOCK_VARS (block
) = vars
;
5322 BLOCK_SUBBLOCKS (block
) = subblocks
;
5323 BLOCK_SUPERCONTEXT (block
) = supercontext
;
5324 BLOCK_CHAIN (block
) = chain
;
5329 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5331 LOC is the location to use in tree T. */
5334 protected_set_expr_location (tree t
, location_t loc
)
5336 if (CAN_HAVE_LOCATION_P (t
))
5337 SET_EXPR_LOCATION (t
, loc
);
5338 else if (t
&& TREE_CODE (t
) == STATEMENT_LIST
)
5340 t
= expr_single (t
);
5341 if (t
&& CAN_HAVE_LOCATION_P (t
))
5342 SET_EXPR_LOCATION (t
, loc
);
5346 /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5347 UNKNOWN_LOCATION. */
5350 protected_set_expr_location_if_unset (tree t
, location_t loc
)
5352 t
= expr_single (t
);
5353 if (t
&& !EXPR_HAS_LOCATION (t
))
5354 protected_set_expr_location (t
, loc
);
5357 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5358 of the various TYPE_QUAL values. */
5361 set_type_quals (tree type
, int type_quals
)
5363 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
5364 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
5365 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
5366 TYPE_ATOMIC (type
) = (type_quals
& TYPE_QUAL_ATOMIC
) != 0;
5367 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
5370 /* Returns true iff CAND and BASE have equivalent language-specific
5374 check_lang_type (const_tree cand
, const_tree base
)
5376 if (lang_hooks
.types
.type_hash_eq
== NULL
)
5378 /* type_hash_eq currently only applies to these types. */
5379 if (TREE_CODE (cand
) != FUNCTION_TYPE
5380 && TREE_CODE (cand
) != METHOD_TYPE
)
5382 return lang_hooks
.types
.type_hash_eq (cand
, base
);
5385 /* This function checks to see if TYPE matches the size one of the built-in
5386 atomic types, and returns that core atomic type. */
5389 find_atomic_core_type (const_tree type
)
5391 tree base_atomic_type
;
5393 /* Only handle complete types. */
5394 if (!tree_fits_uhwi_p (TYPE_SIZE (type
)))
5397 switch (tree_to_uhwi (TYPE_SIZE (type
)))
5400 base_atomic_type
= atomicQI_type_node
;
5404 base_atomic_type
= atomicHI_type_node
;
5408 base_atomic_type
= atomicSI_type_node
;
5412 base_atomic_type
= atomicDI_type_node
;
5416 base_atomic_type
= atomicTI_type_node
;
5420 base_atomic_type
= NULL_TREE
;
5423 return base_atomic_type
;
5426 /* Returns true iff unqualified CAND and BASE are equivalent. */
5429 check_base_type (const_tree cand
, const_tree base
)
5431 if (TYPE_NAME (cand
) != TYPE_NAME (base
)
5432 /* Apparently this is needed for Objective-C. */
5433 || TYPE_CONTEXT (cand
) != TYPE_CONTEXT (base
)
5434 || !attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5435 TYPE_ATTRIBUTES (base
)))
5437 /* Check alignment. */
5438 if (TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
5439 && TYPE_USER_ALIGN (cand
) == TYPE_USER_ALIGN (base
))
5441 /* Atomic types increase minimal alignment. We must to do so as well
5442 or we get duplicated canonical types. See PR88686. */
5443 if ((TYPE_QUALS (cand
) & TYPE_QUAL_ATOMIC
))
5445 /* See if this object can map to a basic atomic type. */
5446 tree atomic_type
= find_atomic_core_type (cand
);
5447 if (atomic_type
&& TYPE_ALIGN (atomic_type
) == TYPE_ALIGN (cand
))
5453 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5456 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
5458 return (TYPE_QUALS (cand
) == type_quals
5459 && check_base_type (cand
, base
)
5460 && check_lang_type (cand
, base
));
5463 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5466 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
5468 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
5469 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5470 /* Apparently this is needed for Objective-C. */
5471 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5472 /* Check alignment. */
5473 && TYPE_ALIGN (cand
) == align
5474 /* Check this is a user-aligned type as build_aligned_type
5476 && TYPE_USER_ALIGN (cand
)
5477 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5478 TYPE_ATTRIBUTES (base
))
5479 && check_lang_type (cand
, base
));
5482 /* Return a version of the TYPE, qualified as indicated by the
5483 TYPE_QUALS, if one exists. If no qualified version exists yet,
5484 return NULL_TREE. */
5487 get_qualified_type (tree type
, int type_quals
)
5489 if (TYPE_QUALS (type
) == type_quals
)
5492 tree mv
= TYPE_MAIN_VARIANT (type
);
5493 if (check_qualified_type (mv
, type
, type_quals
))
5496 /* Search the chain of variants to see if there is already one there just
5497 like the one we need to have. If so, use that existing one. We must
5498 preserve the TYPE_NAME, since there is code that depends on this. */
5499 for (tree
*tp
= &TYPE_NEXT_VARIANT (mv
); *tp
; tp
= &TYPE_NEXT_VARIANT (*tp
))
5500 if (check_qualified_type (*tp
, type
, type_quals
))
5502 /* Put the found variant at the head of the variant list so
5503 frequently searched variants get found faster. The C++ FE
5504 benefits greatly from this. */
5506 *tp
= TYPE_NEXT_VARIANT (t
);
5507 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (mv
);
5508 TYPE_NEXT_VARIANT (mv
) = t
;
5515 /* Like get_qualified_type, but creates the type if it does not
5516 exist. This function never returns NULL_TREE. */
5519 build_qualified_type (tree type
, int type_quals MEM_STAT_DECL
)
5523 /* See if we already have the appropriate qualified variant. */
5524 t
= get_qualified_type (type
, type_quals
);
5526 /* If not, build it. */
5529 t
= build_variant_type_copy (type PASS_MEM_STAT
);
5530 set_type_quals (t
, type_quals
);
5532 if (((type_quals
& TYPE_QUAL_ATOMIC
) == TYPE_QUAL_ATOMIC
))
5534 /* See if this object can map to a basic atomic type. */
5535 tree atomic_type
= find_atomic_core_type (type
);
5538 /* Ensure the alignment of this type is compatible with
5539 the required alignment of the atomic type. */
5540 if (TYPE_ALIGN (atomic_type
) > TYPE_ALIGN (t
))
5541 SET_TYPE_ALIGN (t
, TYPE_ALIGN (atomic_type
));
5545 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5546 /* Propagate structural equality. */
5547 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5548 else if (TYPE_CANONICAL (type
) != type
)
5549 /* Build the underlying canonical type, since it is different
5552 tree c
= build_qualified_type (TYPE_CANONICAL (type
), type_quals
);
5553 TYPE_CANONICAL (t
) = TYPE_CANONICAL (c
);
5556 /* T is its own canonical type. */
5557 TYPE_CANONICAL (t
) = t
;
5564 /* Create a variant of type T with alignment ALIGN. */
5567 build_aligned_type (tree type
, unsigned int align
)
5571 if (TYPE_PACKED (type
)
5572 || TYPE_ALIGN (type
) == align
)
5575 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5576 if (check_aligned_type (t
, type
, align
))
5579 t
= build_variant_type_copy (type
);
5580 SET_TYPE_ALIGN (t
, align
);
5581 TYPE_USER_ALIGN (t
) = 1;
5586 /* Create a new distinct copy of TYPE. The new type is made its own
5587 MAIN_VARIANT. If TYPE requires structural equality checks, the
5588 resulting type requires structural equality checks; otherwise, its
5589 TYPE_CANONICAL points to itself. */
5592 build_distinct_type_copy (tree type MEM_STAT_DECL
)
5594 tree t
= copy_node (type PASS_MEM_STAT
);
5596 TYPE_POINTER_TO (t
) = 0;
5597 TYPE_REFERENCE_TO (t
) = 0;
5599 /* Set the canonical type either to a new equivalence class, or
5600 propagate the need for structural equality checks. */
5601 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5602 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5604 TYPE_CANONICAL (t
) = t
;
5606 /* Make it its own variant. */
5607 TYPE_MAIN_VARIANT (t
) = t
;
5608 TYPE_NEXT_VARIANT (t
) = 0;
5610 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5611 whose TREE_TYPE is not t. This can also happen in the Ada
5612 frontend when using subtypes. */
5617 /* Create a new variant of TYPE, equivalent but distinct. This is so
5618 the caller can modify it. TYPE_CANONICAL for the return type will
5619 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5620 are considered equal by the language itself (or that both types
5621 require structural equality checks). */
5624 build_variant_type_copy (tree type MEM_STAT_DECL
)
5626 tree t
, m
= TYPE_MAIN_VARIANT (type
);
5628 t
= build_distinct_type_copy (type PASS_MEM_STAT
);
5630 /* Since we're building a variant, assume that it is a non-semantic
5631 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5632 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
5633 /* Type variants have no alias set defined. */
5634 TYPE_ALIAS_SET (t
) = -1;
5636 /* Add the new type to the chain of variants of TYPE. */
5637 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
5638 TYPE_NEXT_VARIANT (m
) = t
;
5639 TYPE_MAIN_VARIANT (t
) = m
;
5644 /* Return true if the from tree in both tree maps are equal. */
5647 tree_map_base_eq (const void *va
, const void *vb
)
5649 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
5650 *const b
= (const struct tree_map_base
*) vb
;
5651 return (a
->from
== b
->from
);
5654 /* Hash a from tree in a tree_base_map. */
5657 tree_map_base_hash (const void *item
)
5659 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
5662 /* Return true if this tree map structure is marked for garbage collection
5663 purposes. We simply return true if the from tree is marked, so that this
5664 structure goes away when the from tree goes away. */
5667 tree_map_base_marked_p (const void *p
)
5669 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
5672 /* Hash a from tree in a tree_map. */
5675 tree_map_hash (const void *item
)
5677 return (((const struct tree_map
*) item
)->hash
);
5680 /* Hash a from tree in a tree_decl_map. */
5683 tree_decl_map_hash (const void *item
)
5685 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
5688 /* Return the initialization priority for DECL. */
5691 decl_init_priority_lookup (tree decl
)
5693 symtab_node
*snode
= symtab_node::get (decl
);
5696 return DEFAULT_INIT_PRIORITY
;
5698 snode
->get_init_priority ();
5701 /* Return the finalization priority for DECL. */
5704 decl_fini_priority_lookup (tree decl
)
5706 cgraph_node
*node
= cgraph_node::get (decl
);
5709 return DEFAULT_INIT_PRIORITY
;
5711 node
->get_fini_priority ();
5714 /* Set the initialization priority for DECL to PRIORITY. */
5717 decl_init_priority_insert (tree decl
, priority_type priority
)
5719 struct symtab_node
*snode
;
5721 if (priority
== DEFAULT_INIT_PRIORITY
)
5723 snode
= symtab_node::get (decl
);
5727 else if (VAR_P (decl
))
5728 snode
= varpool_node::get_create (decl
);
5730 snode
= cgraph_node::get_create (decl
);
5731 snode
->set_init_priority (priority
);
5734 /* Set the finalization priority for DECL to PRIORITY. */
5737 decl_fini_priority_insert (tree decl
, priority_type priority
)
5739 struct cgraph_node
*node
;
5741 if (priority
== DEFAULT_INIT_PRIORITY
)
5743 node
= cgraph_node::get (decl
);
5748 node
= cgraph_node::get_create (decl
);
5749 node
->set_fini_priority (priority
);
5752 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5755 print_debug_expr_statistics (void)
5757 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
5758 (long) debug_expr_for_decl
->size (),
5759 (long) debug_expr_for_decl
->elements (),
5760 debug_expr_for_decl
->collisions ());
5763 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
5766 print_value_expr_statistics (void)
5768 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
5769 (long) value_expr_for_decl
->size (),
5770 (long) value_expr_for_decl
->elements (),
5771 value_expr_for_decl
->collisions ());
5774 /* Lookup a debug expression for FROM, and return it if we find one. */
5777 decl_debug_expr_lookup (tree from
)
5779 struct tree_decl_map
*h
, in
;
5780 in
.base
.from
= from
;
5782 h
= debug_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
5788 /* Insert a mapping FROM->TO in the debug expression hashtable. */
5791 decl_debug_expr_insert (tree from
, tree to
)
5793 struct tree_decl_map
*h
;
5795 h
= ggc_alloc
<tree_decl_map
> ();
5796 h
->base
.from
= from
;
5798 *debug_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
5801 /* Lookup a value expression for FROM, and return it if we find one. */
5804 decl_value_expr_lookup (tree from
)
5806 struct tree_decl_map
*h
, in
;
5807 in
.base
.from
= from
;
5809 h
= value_expr_for_decl
->find_with_hash (&in
, DECL_UID (from
));
5815 /* Insert a mapping FROM->TO in the value expression hashtable. */
5818 decl_value_expr_insert (tree from
, tree to
)
5820 struct tree_decl_map
*h
;
5822 h
= ggc_alloc
<tree_decl_map
> ();
5823 h
->base
.from
= from
;
5825 *value_expr_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
) = h
;
5828 /* Lookup a vector of debug arguments for FROM, and return it if we
5832 decl_debug_args_lookup (tree from
)
5834 struct tree_vec_map
*h
, in
;
5836 if (!DECL_HAS_DEBUG_ARGS_P (from
))
5838 gcc_checking_assert (debug_args_for_decl
!= NULL
);
5839 in
.base
.from
= from
;
5840 h
= debug_args_for_decl
->find_with_hash (&in
, DECL_UID (from
));
5846 /* Insert a mapping FROM->empty vector of debug arguments in the value
5847 expression hashtable. */
5850 decl_debug_args_insert (tree from
)
5852 struct tree_vec_map
*h
;
5855 if (DECL_HAS_DEBUG_ARGS_P (from
))
5856 return decl_debug_args_lookup (from
);
5857 if (debug_args_for_decl
== NULL
)
5858 debug_args_for_decl
= hash_table
<tree_vec_map_cache_hasher
>::create_ggc (64);
5859 h
= ggc_alloc
<tree_vec_map
> ();
5860 h
->base
.from
= from
;
5862 loc
= debug_args_for_decl
->find_slot_with_hash (h
, DECL_UID (from
), INSERT
);
5864 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
5868 /* Hashing of types so that we don't make duplicates.
5869 The entry point is `type_hash_canon'. */
5871 /* Generate the default hash code for TYPE. This is designed for
5872 speed, rather than maximum entropy. */
5875 type_hash_canon_hash (tree type
)
5877 inchash::hash hstate
;
5879 hstate
.add_int (TREE_CODE (type
));
5881 if (TREE_TYPE (type
))
5882 hstate
.add_object (TYPE_HASH (TREE_TYPE (type
)));
5884 for (tree t
= TYPE_ATTRIBUTES (type
); t
; t
= TREE_CHAIN (t
))
5885 /* Just the identifier is adequate to distinguish. */
5886 hstate
.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t
)));
5888 switch (TREE_CODE (type
))
5891 hstate
.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type
)));
5894 for (tree t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
5895 if (TREE_VALUE (t
) != error_mark_node
)
5896 hstate
.add_object (TYPE_HASH (TREE_VALUE (t
)));
5900 hstate
.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type
)));
5905 if (TYPE_DOMAIN (type
))
5906 hstate
.add_object (TYPE_HASH (TYPE_DOMAIN (type
)));
5907 if (!AGGREGATE_TYPE_P (TREE_TYPE (type
)))
5909 unsigned typeless
= TYPE_TYPELESS_STORAGE (type
);
5910 hstate
.add_object (typeless
);
5917 tree t
= TYPE_MAX_VALUE (type
);
5919 t
= TYPE_MIN_VALUE (type
);
5920 for (int i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
5921 hstate
.add_object (TREE_INT_CST_ELT (t
, i
));
5926 case FIXED_POINT_TYPE
:
5928 unsigned prec
= TYPE_PRECISION (type
);
5929 hstate
.add_object (prec
);
5934 hstate
.add_poly_int (TYPE_VECTOR_SUBPARTS (type
));
5941 return hstate
.end ();
5944 /* These are the Hashtable callback functions. */
5946 /* Returns true iff the types are equivalent. */
5949 type_cache_hasher::equal (type_hash
*a
, type_hash
*b
)
5951 /* First test the things that are the same for all types. */
5952 if (a
->hash
!= b
->hash
5953 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
5954 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
5955 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
5956 TYPE_ATTRIBUTES (b
->type
))
5957 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
5958 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
5961 /* Be careful about comparing arrays before and after the element type
5962 has been completed; don't compare TYPE_ALIGN unless both types are
5964 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
5965 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
5966 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
5969 switch (TREE_CODE (a
->type
))
5975 case REFERENCE_TYPE
:
5980 return known_eq (TYPE_VECTOR_SUBPARTS (a
->type
),
5981 TYPE_VECTOR_SUBPARTS (b
->type
));
5984 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
5985 && !(TYPE_VALUES (a
->type
)
5986 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
5987 && TYPE_VALUES (b
->type
)
5988 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
5989 && type_list_equal (TYPE_VALUES (a
->type
),
5990 TYPE_VALUES (b
->type
))))
5998 if (TYPE_PRECISION (a
->type
) != TYPE_PRECISION (b
->type
))
6000 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6001 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6002 TYPE_MAX_VALUE (b
->type
)))
6003 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6004 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6005 TYPE_MIN_VALUE (b
->type
))));
6007 case FIXED_POINT_TYPE
:
6008 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6011 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6014 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6015 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6016 || (TYPE_ARG_TYPES (a
->type
)
6017 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6018 && TYPE_ARG_TYPES (b
->type
)
6019 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6020 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6021 TYPE_ARG_TYPES (b
->type
)))))
6025 /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6026 where the flag should be inherited from the element type
6027 and can change after ARRAY_TYPEs are created; on non-aggregates
6028 compare it and hash it, scalars will never have that flag set
6029 and we need to differentiate between arrays created by different
6030 front-ends or middle-end created arrays. */
6031 return (TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
)
6032 && (AGGREGATE_TYPE_P (TREE_TYPE (a
->type
))
6033 || (TYPE_TYPELESS_STORAGE (a
->type
)
6034 == TYPE_TYPELESS_STORAGE (b
->type
))));
6038 case QUAL_UNION_TYPE
:
6039 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6040 || (TYPE_FIELDS (a
->type
)
6041 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6042 && TYPE_FIELDS (b
->type
)
6043 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6044 && type_list_equal (TYPE_FIELDS (a
->type
),
6045 TYPE_FIELDS (b
->type
))));
6048 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6049 || (TYPE_ARG_TYPES (a
->type
)
6050 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6051 && TYPE_ARG_TYPES (b
->type
)
6052 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6053 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6054 TYPE_ARG_TYPES (b
->type
))))
6062 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6063 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6068 /* Given TYPE, and HASHCODE its hash code, return the canonical
6069 object for an identical type if one already exists.
6070 Otherwise, return TYPE, and record it as the canonical object.
6072 To use this function, first create a type of the sort you want.
6073 Then compute its hash code from the fields of the type that
6074 make it different from other similar types.
6075 Then call this function and use the value. */
6078 type_hash_canon (unsigned int hashcode
, tree type
)
6083 /* The hash table only contains main variants, so ensure that's what we're
6085 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6087 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6088 must call that routine before comparing TYPE_ALIGNs. */
6094 loc
= type_hash_table
->find_slot_with_hash (&in
, hashcode
, INSERT
);
6097 tree t1
= ((type_hash
*) *loc
)->type
;
6098 gcc_assert (TYPE_MAIN_VARIANT (t1
) == t1
6100 if (TYPE_UID (type
) + 1 == next_type_uid
)
6102 /* Free also min/max values and the cache for integer
6103 types. This can't be done in free_node, as LTO frees
6104 those on its own. */
6105 if (TREE_CODE (type
) == INTEGER_TYPE
)
6107 if (TYPE_MIN_VALUE (type
)
6108 && TREE_TYPE (TYPE_MIN_VALUE (type
)) == type
)
6110 /* Zero is always in TYPE_CACHED_VALUES. */
6111 if (! TYPE_UNSIGNED (type
))
6112 int_cst_hash_table
->remove_elt (TYPE_MIN_VALUE (type
));
6113 ggc_free (TYPE_MIN_VALUE (type
));
6115 if (TYPE_MAX_VALUE (type
)
6116 && TREE_TYPE (TYPE_MAX_VALUE (type
)) == type
)
6118 int_cst_hash_table
->remove_elt (TYPE_MAX_VALUE (type
));
6119 ggc_free (TYPE_MAX_VALUE (type
));
6121 if (TYPE_CACHED_VALUES_P (type
))
6122 ggc_free (TYPE_CACHED_VALUES (type
));
6129 struct type_hash
*h
;
6131 h
= ggc_alloc
<type_hash
> ();
6141 print_type_hash_statistics (void)
6143 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6144 (long) type_hash_table
->size (),
6145 (long) type_hash_table
->elements (),
6146 type_hash_table
->collisions ());
6149 /* Given two lists of types
6150 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6151 return 1 if the lists contain the same types in the same order.
6152 Also, the TREE_PURPOSEs must match. */
6155 type_list_equal (const_tree l1
, const_tree l2
)
6159 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6160 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6161 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6162 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6163 && (TREE_TYPE (TREE_PURPOSE (t1
))
6164 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6170 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6171 given by TYPE. If the argument list accepts variable arguments,
6172 then this function counts only the ordinary arguments. */
6175 type_num_arguments (const_tree fntype
)
6179 for (tree t
= TYPE_ARG_TYPES (fntype
); t
; t
= TREE_CHAIN (t
))
6180 /* If the function does not take a variable number of arguments,
6181 the last element in the list will have type `void'. */
6182 if (VOID_TYPE_P (TREE_VALUE (t
)))
6190 /* Return the type of the function TYPE's argument ARGNO if known.
6191 For vararg function's where ARGNO refers to one of the variadic
6192 arguments return null. Otherwise, return a void_type_node for
6193 out-of-bounds ARGNO. */
6196 type_argument_type (const_tree fntype
, unsigned argno
)
6198 /* Treat zero the same as an out-of-bounds argument number. */
6200 return void_type_node
;
6202 function_args_iterator iter
;
6206 FOREACH_FUNCTION_ARGS (fntype
, argtype
, iter
)
6208 /* A vararg function's argument list ends in a null. Otherwise,
6209 an ordinary function's argument list ends with void. Return
6210 null if ARGNO refers to a vararg argument, void_type_node if
6211 it's out of bounds, and the formal argument type otherwise. */
6215 if (i
== argno
|| VOID_TYPE_P (argtype
))
6224 /* Nonzero if integer constants T1 and T2
6225 represent the same constant value. */
6228 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6233 if (t1
== 0 || t2
== 0)
6236 STRIP_ANY_LOCATION_WRAPPER (t1
);
6237 STRIP_ANY_LOCATION_WRAPPER (t2
);
6239 if (TREE_CODE (t1
) == INTEGER_CST
6240 && TREE_CODE (t2
) == INTEGER_CST
6241 && wi::to_widest (t1
) == wi::to_widest (t2
))
6247 /* Return true if T is an INTEGER_CST whose numerical value (extended
6248 according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6251 tree_fits_shwi_p (const_tree t
)
6253 return (t
!= NULL_TREE
6254 && TREE_CODE (t
) == INTEGER_CST
6255 && wi::fits_shwi_p (wi::to_widest (t
)));
6258 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6259 value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6262 tree_fits_poly_int64_p (const_tree t
)
6266 if (POLY_INT_CST_P (t
))
6268 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; i
++)
6269 if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t
, i
))))
6273 return (TREE_CODE (t
) == INTEGER_CST
6274 && wi::fits_shwi_p (wi::to_widest (t
)));
6277 /* Return true if T is an INTEGER_CST whose numerical value (extended
6278 according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6281 tree_fits_uhwi_p (const_tree t
)
6283 return (t
!= NULL_TREE
6284 && TREE_CODE (t
) == INTEGER_CST
6285 && wi::fits_uhwi_p (wi::to_widest (t
)));
6288 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6289 value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6292 tree_fits_poly_uint64_p (const_tree t
)
6296 if (POLY_INT_CST_P (t
))
6298 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; i
++)
6299 if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t
, i
))))
6303 return (TREE_CODE (t
) == INTEGER_CST
6304 && wi::fits_uhwi_p (wi::to_widest (t
)));
6307 /* T is an INTEGER_CST whose numerical value (extended according to
6308 TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6312 tree_to_shwi (const_tree t
)
6314 gcc_assert (tree_fits_shwi_p (t
));
6315 return TREE_INT_CST_LOW (t
);
6318 /* T is an INTEGER_CST whose numerical value (extended according to
6319 TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6322 unsigned HOST_WIDE_INT
6323 tree_to_uhwi (const_tree t
)
6325 gcc_assert (tree_fits_uhwi_p (t
));
6326 return TREE_INT_CST_LOW (t
);
6329 /* Return the most significant (sign) bit of T. */
6332 tree_int_cst_sign_bit (const_tree t
)
6334 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
6336 return wi::extract_uhwi (wi::to_wide (t
), bitno
, 1);
6339 /* Return an indication of the sign of the integer constant T.
6340 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6341 Note that -1 will never be returned if T's type is unsigned. */
6344 tree_int_cst_sgn (const_tree t
)
6346 if (wi::to_wide (t
) == 0)
6348 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6350 else if (wi::neg_p (wi::to_wide (t
)))
6356 /* Return the minimum number of bits needed to represent VALUE in a
6357 signed or unsigned type, UNSIGNEDP says which. */
6360 tree_int_cst_min_precision (tree value
, signop sgn
)
6362 /* If the value is negative, compute its negative minus 1. The latter
6363 adjustment is because the absolute value of the largest negative value
6364 is one larger than the largest positive value. This is equivalent to
6365 a bit-wise negation, so use that operation instead. */
6367 if (tree_int_cst_sgn (value
) < 0)
6368 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
6370 /* Return the number of bits needed, taking into account the fact
6371 that we need one more bit for a signed than unsigned type.
6372 If value is 0 or -1, the minimum precision is 1 no matter
6373 whether unsignedp is true or false. */
6375 if (integer_zerop (value
))
6378 return tree_floor_log2 (value
) + 1 + (sgn
== SIGNED
? 1 : 0) ;
6381 /* Return truthvalue of whether T1 is the same tree structure as T2.
6382 Return 1 if they are the same.
6383 Return 0 if they are understandably different.
6384 Return -1 if either contains tree structure not understood by
6388 simple_cst_equal (const_tree t1
, const_tree t2
)
6390 enum tree_code code1
, code2
;
6396 if (t1
== 0 || t2
== 0)
6399 /* For location wrappers to be the same, they must be at the same
6400 source location (and wrap the same thing). */
6401 if (location_wrapper_p (t1
) && location_wrapper_p (t2
))
6403 if (EXPR_LOCATION (t1
) != EXPR_LOCATION (t2
))
6405 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6408 code1
= TREE_CODE (t1
);
6409 code2
= TREE_CODE (t2
);
6411 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
6413 if (CONVERT_EXPR_CODE_P (code2
)
6414 || code2
== NON_LVALUE_EXPR
)
6415 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6417 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
6420 else if (CONVERT_EXPR_CODE_P (code2
)
6421 || code2
== NON_LVALUE_EXPR
)
6422 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
6430 return wi::to_widest (t1
) == wi::to_widest (t2
);
6433 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
6436 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
6439 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
6440 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
6441 TREE_STRING_LENGTH (t1
)));
6445 unsigned HOST_WIDE_INT idx
;
6446 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
6447 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
6449 if (vec_safe_length (v1
) != vec_safe_length (v2
))
6452 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
6453 /* ??? Should we handle also fields here? */
6454 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
6460 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6463 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
6466 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
6469 const_tree arg1
, arg2
;
6470 const_call_expr_arg_iterator iter1
, iter2
;
6471 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
6472 arg2
= first_const_call_expr_arg (t2
, &iter2
);
6474 arg1
= next_const_call_expr_arg (&iter1
),
6475 arg2
= next_const_call_expr_arg (&iter2
))
6477 cmp
= simple_cst_equal (arg1
, arg2
);
6481 return arg1
== arg2
;
6485 /* Special case: if either target is an unallocated VAR_DECL,
6486 it means that it's going to be unified with whatever the
6487 TARGET_EXPR is really supposed to initialize, so treat it
6488 as being equivalent to anything. */
6489 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
6490 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
6491 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
6492 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
6493 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
6494 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
6497 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6502 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
6504 case WITH_CLEANUP_EXPR
:
6505 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6509 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
6512 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
6513 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6524 if (POLY_INT_CST_P (t1
))
6525 /* A false return means maybe_ne rather than known_ne. */
6526 return known_eq (poly_widest_int::from (poly_int_cst_value (t1
),
6527 TYPE_SIGN (TREE_TYPE (t1
))),
6528 poly_widest_int::from (poly_int_cst_value (t2
),
6529 TYPE_SIGN (TREE_TYPE (t2
))));
6533 /* This general rule works for most tree codes. All exceptions should be
6534 handled above. If this is a language-specific tree code, we can't
6535 trust what might be in the operand, so say we don't know
6537 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
6540 switch (TREE_CODE_CLASS (code1
))
6544 case tcc_comparison
:
6545 case tcc_expression
:
6549 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
6551 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
6563 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6564 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6565 than U, respectively. */
6568 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
6570 if (tree_int_cst_sgn (t
) < 0)
6572 else if (!tree_fits_uhwi_p (t
))
6574 else if (TREE_INT_CST_LOW (t
) == u
)
6576 else if (TREE_INT_CST_LOW (t
) < u
)
6582 /* Return true if SIZE represents a constant size that is in bounds of
6583 what the middle-end and the backend accepts (covering not more than
6584 half of the address-space).
6585 When PERR is non-null, set *PERR on failure to the description of
6586 why SIZE is not valid. */
6589 valid_constant_size_p (const_tree size
, cst_size_error
*perr
/* = NULL */)
6591 if (POLY_INT_CST_P (size
))
6593 if (TREE_OVERFLOW (size
))
6595 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
6596 if (!valid_constant_size_p (POLY_INT_CST_COEFF (size
, i
)))
6601 cst_size_error error
;
6605 if (TREE_CODE (size
) != INTEGER_CST
)
6607 *perr
= cst_size_not_constant
;
6611 if (TREE_OVERFLOW_P (size
))
6613 *perr
= cst_size_overflow
;
6617 if (tree_int_cst_sgn (size
) < 0)
6619 *perr
= cst_size_negative
;
6622 if (!tree_fits_uhwi_p (size
)
6623 || (wi::to_widest (TYPE_MAX_VALUE (sizetype
))
6624 < wi::to_widest (size
) * 2))
6626 *perr
= cst_size_too_big
;
6633 /* Return the precision of the type, or for a complex or vector type the
6634 precision of the type of its elements. */
6637 element_precision (const_tree type
)
6640 type
= TREE_TYPE (type
);
6641 enum tree_code code
= TREE_CODE (type
);
6642 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
6643 type
= TREE_TYPE (type
);
6645 return TYPE_PRECISION (type
);
6648 /* Return true if CODE represents an associative tree code. Otherwise
6651 associative_tree_code (enum tree_code code
)
6670 /* Return true if CODE represents a commutative tree code. Otherwise
6673 commutative_tree_code (enum tree_code code
)
6679 case MULT_HIGHPART_EXPR
:
6687 case UNORDERED_EXPR
:
6691 case TRUTH_AND_EXPR
:
6692 case TRUTH_XOR_EXPR
:
6694 case WIDEN_MULT_EXPR
:
6695 case VEC_WIDEN_MULT_HI_EXPR
:
6696 case VEC_WIDEN_MULT_LO_EXPR
:
6697 case VEC_WIDEN_MULT_EVEN_EXPR
:
6698 case VEC_WIDEN_MULT_ODD_EXPR
:
6707 /* Return true if CODE represents a ternary tree code for which the
6708 first two operands are commutative. Otherwise return false. */
6710 commutative_ternary_tree_code (enum tree_code code
)
6714 case WIDEN_MULT_PLUS_EXPR
:
6715 case WIDEN_MULT_MINUS_EXPR
:
6725 /* Returns true if CODE can overflow. */
6728 operation_can_overflow (enum tree_code code
)
6736 /* Can overflow in various ways. */
6738 case TRUNC_DIV_EXPR
:
6739 case EXACT_DIV_EXPR
:
6740 case FLOOR_DIV_EXPR
:
6742 /* For INT_MIN / -1. */
6749 /* These operators cannot overflow. */
6754 /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
6755 ftrapv doesn't generate trapping insns for CODE. */
6758 operation_no_trapping_overflow (tree type
, enum tree_code code
)
6760 gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type
));
6762 /* We don't generate instructions that trap on overflow for complex or vector
6764 if (!INTEGRAL_TYPE_P (type
))
6767 if (!TYPE_OVERFLOW_TRAPS (type
))
6777 /* These operators can overflow, and -ftrapv generates trapping code for
6780 case TRUNC_DIV_EXPR
:
6781 case EXACT_DIV_EXPR
:
6782 case FLOOR_DIV_EXPR
:
6785 /* These operators can overflow, but -ftrapv does not generate trapping
6789 /* These operators cannot overflow. */
6794 /* Constructors for pointer, array and function types.
6795 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
6796 constructed by language-dependent code, not here.) */
6798 /* Construct, lay out and return the type of pointers to TO_TYPE with
6799 mode MODE. If MODE is VOIDmode, a pointer mode for the address
6800 space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
6801 indicate this type can reference all of memory. If such a type has
6802 already been constructed, reuse it. */
6805 build_pointer_type_for_mode (tree to_type
, machine_mode mode
,
6809 bool could_alias
= can_alias_all
;
6811 if (to_type
== error_mark_node
)
6812 return error_mark_node
;
6814 if (mode
== VOIDmode
)
6816 addr_space_t as
= TYPE_ADDR_SPACE (to_type
);
6817 mode
= targetm
.addr_space
.pointer_mode (as
);
6820 /* If the pointed-to type has the may_alias attribute set, force
6821 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
6822 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
6823 can_alias_all
= true;
6825 /* In some cases, languages will have things that aren't a POINTER_TYPE
6826 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
6827 In that case, return that type without regard to the rest of our
6830 ??? This is a kludge, but consistent with the way this function has
6831 always operated and there doesn't seem to be a good way to avoid this
6833 if (TYPE_POINTER_TO (to_type
) != 0
6834 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
6835 return TYPE_POINTER_TO (to_type
);
6837 /* First, if we already have a type for pointers to TO_TYPE and it's
6838 the proper mode, use it. */
6839 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
6840 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
6843 t
= make_node (POINTER_TYPE
);
6845 TREE_TYPE (t
) = to_type
;
6846 SET_TYPE_MODE (t
, mode
);
6847 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
6848 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
6849 TYPE_POINTER_TO (to_type
) = t
;
6851 /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
6852 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
) || in_lto_p
)
6853 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6854 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
6856 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
6859 /* Lay out the type. This function has many callers that are concerned
6860 with expression-construction, and this simplifies them all. */
6866 /* By default build pointers in ptr_mode. */
6869 build_pointer_type (tree to_type
)
6871 return build_pointer_type_for_mode (to_type
, VOIDmode
, false);
6874 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
6877 build_reference_type_for_mode (tree to_type
, machine_mode mode
,
6881 bool could_alias
= can_alias_all
;
6883 if (to_type
== error_mark_node
)
6884 return error_mark_node
;
6886 if (mode
== VOIDmode
)
6888 addr_space_t as
= TYPE_ADDR_SPACE (to_type
);
6889 mode
= targetm
.addr_space
.pointer_mode (as
);
6892 /* If the pointed-to type has the may_alias attribute set, force
6893 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
6894 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
6895 can_alias_all
= true;
6897 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
6898 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
6899 In that case, return that type without regard to the rest of our
6902 ??? This is a kludge, but consistent with the way this function has
6903 always operated and there doesn't seem to be a good way to avoid this
6905 if (TYPE_REFERENCE_TO (to_type
) != 0
6906 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
6907 return TYPE_REFERENCE_TO (to_type
);
6909 /* First, if we already have a type for pointers to TO_TYPE and it's
6910 the proper mode, use it. */
6911 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
6912 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
6915 t
= make_node (REFERENCE_TYPE
);
6917 TREE_TYPE (t
) = to_type
;
6918 SET_TYPE_MODE (t
, mode
);
6919 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
6920 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
6921 TYPE_REFERENCE_TO (to_type
) = t
;
6923 /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
6924 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
) || in_lto_p
)
6925 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6926 else if (TYPE_CANONICAL (to_type
) != to_type
|| could_alias
)
6928 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
6937 /* Build the node for the type of references-to-TO_TYPE by default
6941 build_reference_type (tree to_type
)
6943 return build_reference_type_for_mode (to_type
, VOIDmode
, false);
6946 #define MAX_INT_CACHED_PREC \
6947 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
6948 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
6950 /* Builds a signed or unsigned integer type of precision PRECISION.
6951 Used for C bitfields whose precision does not match that of
6952 built-in target types. */
6954 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
6960 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
6962 if (precision
<= MAX_INT_CACHED_PREC
)
6964 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
6969 itype
= make_node (INTEGER_TYPE
);
6970 TYPE_PRECISION (itype
) = precision
;
6973 fixup_unsigned_type (itype
);
6975 fixup_signed_type (itype
);
6977 inchash::hash hstate
;
6978 inchash::add_expr (TYPE_MAX_VALUE (itype
), hstate
);
6979 ret
= type_hash_canon (hstate
.end (), itype
);
6980 if (precision
<= MAX_INT_CACHED_PREC
)
6981 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
6986 #define MAX_BOOL_CACHED_PREC \
6987 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
6988 static GTY(()) tree nonstandard_boolean_type_cache
[MAX_BOOL_CACHED_PREC
+ 1];
6990 /* Builds a boolean type of precision PRECISION.
6991 Used for boolean vectors to choose proper vector element size. */
6993 build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision
)
6997 if (precision
<= MAX_BOOL_CACHED_PREC
)
6999 type
= nonstandard_boolean_type_cache
[precision
];
7004 type
= make_node (BOOLEAN_TYPE
);
7005 TYPE_PRECISION (type
) = precision
;
7006 fixup_signed_type (type
);
7008 if (precision
<= MAX_INT_CACHED_PREC
)
7009 nonstandard_boolean_type_cache
[precision
] = type
;
7014 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7015 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7016 is true, reuse such a type that has already been constructed. */
7019 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7021 tree itype
= make_node (INTEGER_TYPE
);
7023 TREE_TYPE (itype
) = type
;
7025 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7026 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7028 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7029 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7030 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7031 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7032 SET_TYPE_ALIGN (itype
, TYPE_ALIGN (type
));
7033 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7034 SET_TYPE_WARN_IF_NOT_ALIGN (itype
, TYPE_WARN_IF_NOT_ALIGN (type
));
7039 if ((TYPE_MIN_VALUE (itype
)
7040 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7041 || (TYPE_MAX_VALUE (itype
)
7042 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7044 /* Since we cannot reliably merge this type, we need to compare it using
7045 structural equality checks. */
7046 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7050 hashval_t hash
= type_hash_canon_hash (itype
);
7051 itype
= type_hash_canon (hash
, itype
);
7056 /* Wrapper around build_range_type_1 with SHARED set to true. */
7059 build_range_type (tree type
, tree lowval
, tree highval
)
7061 return build_range_type_1 (type
, lowval
, highval
, true);
7064 /* Wrapper around build_range_type_1 with SHARED set to false. */
7067 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7069 return build_range_type_1 (type
, lowval
, highval
, false);
7072 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7073 MAXVAL should be the maximum value in the domain
7074 (one less than the length of the array).
7076 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7077 We don't enforce this limit, that is up to caller (e.g. language front end).
7078 The limit exists because the result is a signed type and we don't handle
7079 sizes that use more than one HOST_WIDE_INT. */
7082 build_index_type (tree maxval
)
7084 return build_range_type (sizetype
, size_zero_node
, maxval
);
7087 /* Return true if the debug information for TYPE, a subtype, should be emitted
7088 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7089 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7090 debug info and doesn't reflect the source code. */
7093 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7095 tree base_type
= TREE_TYPE (type
), low
, high
;
7097 /* Subrange types have a base type which is an integral type. */
7098 if (!INTEGRAL_TYPE_P (base_type
))
7101 /* Get the real bounds of the subtype. */
7102 if (lang_hooks
.types
.get_subrange_bounds
)
7103 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7106 low
= TYPE_MIN_VALUE (type
);
7107 high
= TYPE_MAX_VALUE (type
);
7110 /* If the type and its base type have the same representation and the same
7111 name, then the type is not a subrange but a copy of the base type. */
7112 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7113 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7114 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7115 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7116 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
))
7117 && TYPE_IDENTIFIER (type
) == TYPE_IDENTIFIER (base_type
))
7127 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7128 and number of elements specified by the range of values of INDEX_TYPE.
7129 If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7130 If SHARED is true, reuse such a type that has already been constructed.
7131 If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7134 build_array_type_1 (tree elt_type
, tree index_type
, bool typeless_storage
,
7135 bool shared
, bool set_canonical
)
7139 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7141 error ("arrays of functions are not meaningful");
7142 elt_type
= integer_type_node
;
7145 t
= make_node (ARRAY_TYPE
);
7146 TREE_TYPE (t
) = elt_type
;
7147 TYPE_DOMAIN (t
) = index_type
;
7148 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7149 TYPE_TYPELESS_STORAGE (t
) = typeless_storage
;
7154 hashval_t hash
= type_hash_canon_hash (t
);
7155 t
= type_hash_canon (hash
, t
);
7158 if (TYPE_CANONICAL (t
) == t
&& set_canonical
)
7160 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7161 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
))
7163 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7164 else if (TYPE_CANONICAL (elt_type
) != elt_type
7165 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7167 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7169 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7170 typeless_storage
, shared
, set_canonical
);
7176 /* Wrapper around build_array_type_1 with SHARED set to true. */
7179 build_array_type (tree elt_type
, tree index_type
, bool typeless_storage
)
7182 build_array_type_1 (elt_type
, index_type
, typeless_storage
, true, true);
7185 /* Wrapper around build_array_type_1 with SHARED set to false. */
7188 build_nonshared_array_type (tree elt_type
, tree index_type
)
7190 return build_array_type_1 (elt_type
, index_type
, false, false, true);
7193 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7197 build_array_type_nelts (tree elt_type
, poly_uint64 nelts
)
7199 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
7202 /* Recursively examines the array elements of TYPE, until a non-array
7203 element type is found. */
7206 strip_array_types (tree type
)
7208 while (TREE_CODE (type
) == ARRAY_TYPE
)
7209 type
= TREE_TYPE (type
);
7214 /* Computes the canonical argument types from the argument type list
7217 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7218 on entry to this function, or if any of the ARGTYPES are
7221 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7222 true on entry to this function, or if any of the ARGTYPES are
7225 Returns a canonical argument list, which may be ARGTYPES when the
7226 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7227 true) or would not differ from ARGTYPES. */
7230 maybe_canonicalize_argtypes (tree argtypes
,
7231 bool *any_structural_p
,
7232 bool *any_noncanonical_p
)
7235 bool any_noncanonical_argtypes_p
= false;
7237 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7239 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7240 /* Fail gracefully by stating that the type is structural. */
7241 *any_structural_p
= true;
7242 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7243 *any_structural_p
= true;
7244 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7245 || TREE_PURPOSE (arg
))
7246 /* If the argument has a default argument, we consider it
7247 non-canonical even though the type itself is canonical.
7248 That way, different variants of function and method types
7249 with default arguments will all point to the variant with
7250 no defaults as their canonical type. */
7251 any_noncanonical_argtypes_p
= true;
7254 if (*any_structural_p
)
7257 if (any_noncanonical_argtypes_p
)
7259 /* Build the canonical list of argument types. */
7260 tree canon_argtypes
= NULL_TREE
;
7261 bool is_void
= false;
7263 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7265 if (arg
== void_list_node
)
7268 canon_argtypes
= tree_cons (NULL_TREE
,
7269 TYPE_CANONICAL (TREE_VALUE (arg
)),
7273 canon_argtypes
= nreverse (canon_argtypes
);
7275 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7277 /* There is a non-canonical type. */
7278 *any_noncanonical_p
= true;
7279 return canon_argtypes
;
7282 /* The canonical argument types are the same as ARGTYPES. */
7286 /* Construct, lay out and return
7287 the type of functions returning type VALUE_TYPE
7288 given arguments of types ARG_TYPES.
7289 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7290 are data type nodes for the arguments of the function.
7291 If such a type has already been constructed, reuse it. */
7294 build_function_type (tree value_type
, tree arg_types
)
7297 inchash::hash hstate
;
7298 bool any_structural_p
, any_noncanonical_p
;
7299 tree canon_argtypes
;
7301 gcc_assert (arg_types
!= error_mark_node
);
7303 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
7305 error ("function return type cannot be function");
7306 value_type
= integer_type_node
;
7309 /* Make a node of the sort we want. */
7310 t
= make_node (FUNCTION_TYPE
);
7311 TREE_TYPE (t
) = value_type
;
7312 TYPE_ARG_TYPES (t
) = arg_types
;
7314 /* If we already have such a type, use the old one. */
7315 hashval_t hash
= type_hash_canon_hash (t
);
7316 t
= type_hash_canon (hash
, t
);
7318 /* Set up the canonical type. */
7319 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
7320 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
7321 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
7323 &any_noncanonical_p
);
7324 if (any_structural_p
)
7325 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7326 else if (any_noncanonical_p
)
7327 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
7330 if (!COMPLETE_TYPE_P (t
))
7335 /* Build a function type. The RETURN_TYPE is the type returned by the
7336 function. If VAARGS is set, no void_type_node is appended to the
7337 list. ARGP must be always be terminated be a NULL_TREE. */
7340 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
7344 t
= va_arg (argp
, tree
);
7345 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
7346 args
= tree_cons (NULL_TREE
, t
, args
);
7351 if (args
!= NULL_TREE
)
7352 args
= nreverse (args
);
7353 gcc_assert (last
!= void_list_node
);
7355 else if (args
== NULL_TREE
)
7356 args
= void_list_node
;
7360 args
= nreverse (args
);
7361 TREE_CHAIN (last
) = void_list_node
;
7363 args
= build_function_type (return_type
, args
);
7368 /* Build a function type. The RETURN_TYPE is the type returned by the
7369 function. If additional arguments are provided, they are
7370 additional argument types. The list of argument types must always
7371 be terminated by NULL_TREE. */
7374 build_function_type_list (tree return_type
, ...)
7379 va_start (p
, return_type
);
7380 args
= build_function_type_list_1 (false, return_type
, p
);
7385 /* Build a variable argument function type. The RETURN_TYPE is the
7386 type returned by the function. If additional arguments are provided,
7387 they are additional argument types. The list of argument types must
7388 always be terminated by NULL_TREE. */
7391 build_varargs_function_type_list (tree return_type
, ...)
7396 va_start (p
, return_type
);
7397 args
= build_function_type_list_1 (true, return_type
, p
);
7403 /* Build a function type. RETURN_TYPE is the type returned by the
7404 function; VAARGS indicates whether the function takes varargs. The
7405 function takes N named arguments, the types of which are provided in
7409 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
7413 tree t
= vaargs
? NULL_TREE
: void_list_node
;
7415 for (i
= n
- 1; i
>= 0; i
--)
7416 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
7418 return build_function_type (return_type
, t
);
7421 /* Build a function type. RETURN_TYPE is the type returned by the
7422 function. The function takes N named arguments, the types of which
7423 are provided in ARG_TYPES. */
7426 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
7428 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
7431 /* Build a variable argument function type. RETURN_TYPE is the type
7432 returned by the function. The function takes N named arguments, the
7433 types of which are provided in ARG_TYPES. */
7436 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
7438 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
7441 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7442 and ARGTYPES (a TREE_LIST) are the return type and arguments types
7443 for the method. An implicit additional parameter (of type
7444 pointer-to-BASETYPE) is added to the ARGTYPES. */
7447 build_method_type_directly (tree basetype
,
7453 bool any_structural_p
, any_noncanonical_p
;
7454 tree canon_argtypes
;
7456 /* Make a node of the sort we want. */
7457 t
= make_node (METHOD_TYPE
);
7459 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7460 TREE_TYPE (t
) = rettype
;
7461 ptype
= build_pointer_type (basetype
);
7463 /* The actual arglist for this function includes a "hidden" argument
7464 which is "this". Put it into the list of argument types. */
7465 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
7466 TYPE_ARG_TYPES (t
) = argtypes
;
7468 /* If we already have such a type, use the old one. */
7469 hashval_t hash
= type_hash_canon_hash (t
);
7470 t
= type_hash_canon (hash
, t
);
7472 /* Set up the canonical type. */
7474 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7475 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
7477 = (TYPE_CANONICAL (basetype
) != basetype
7478 || TYPE_CANONICAL (rettype
) != rettype
);
7479 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
7481 &any_noncanonical_p
);
7482 if (any_structural_p
)
7483 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7484 else if (any_noncanonical_p
)
7486 = build_method_type_directly (TYPE_CANONICAL (basetype
),
7487 TYPE_CANONICAL (rettype
),
7489 if (!COMPLETE_TYPE_P (t
))
7495 /* Construct, lay out and return the type of methods belonging to class
7496 BASETYPE and whose arguments and values are described by TYPE.
7497 If that type exists already, reuse it.
7498 TYPE must be a FUNCTION_TYPE node. */
7501 build_method_type (tree basetype
, tree type
)
7503 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
7505 return build_method_type_directly (basetype
,
7507 TYPE_ARG_TYPES (type
));
7510 /* Construct, lay out and return the type of offsets to a value
7511 of type TYPE, within an object of type BASETYPE.
7512 If a suitable offset type exists already, reuse it. */
7515 build_offset_type (tree basetype
, tree type
)
7519 /* Make a node of the sort we want. */
7520 t
= make_node (OFFSET_TYPE
);
7522 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7523 TREE_TYPE (t
) = type
;
7525 /* If we already have such a type, use the old one. */
7526 hashval_t hash
= type_hash_canon_hash (t
);
7527 t
= type_hash_canon (hash
, t
);
7529 if (!COMPLETE_TYPE_P (t
))
7532 if (TYPE_CANONICAL (t
) == t
)
7534 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7535 || TYPE_STRUCTURAL_EQUALITY_P (type
))
7536 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7537 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
7538 || TYPE_CANONICAL (type
) != type
)
7540 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
7541 TYPE_CANONICAL (type
));
7547 /* Create a complex type whose components are COMPONENT_TYPE.
7549 If NAMED is true, the type is given a TYPE_NAME. We do not always
7550 do so because this creates a DECL node and thus make the DECL_UIDs
7551 dependent on the type canonicalization hashtable, which is GC-ed,
7552 so the DECL_UIDs would not be stable wrt garbage collection. */
7555 build_complex_type (tree component_type
, bool named
)
7557 gcc_assert (INTEGRAL_TYPE_P (component_type
)
7558 || SCALAR_FLOAT_TYPE_P (component_type
)
7559 || FIXED_POINT_TYPE_P (component_type
));
7561 /* Make a node of the sort we want. */
7562 tree probe
= make_node (COMPLEX_TYPE
);
7564 TREE_TYPE (probe
) = TYPE_MAIN_VARIANT (component_type
);
7566 /* If we already have such a type, use the old one. */
7567 hashval_t hash
= type_hash_canon_hash (probe
);
7568 tree t
= type_hash_canon (hash
, probe
);
7572 /* We created a new type. The hash insertion will have laid
7573 out the type. We need to check the canonicalization and
7574 maybe set the name. */
7575 gcc_checking_assert (COMPLETE_TYPE_P (t
)
7577 && TYPE_CANONICAL (t
) == t
);
7579 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t
)))
7580 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7581 else if (TYPE_CANONICAL (TREE_TYPE (t
)) != TREE_TYPE (t
))
7583 = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t
)), named
);
7585 /* We need to create a name, since complex is a fundamental type. */
7588 const char *name
= NULL
;
7590 if (TREE_TYPE (t
) == char_type_node
)
7591 name
= "complex char";
7592 else if (TREE_TYPE (t
) == signed_char_type_node
)
7593 name
= "complex signed char";
7594 else if (TREE_TYPE (t
) == unsigned_char_type_node
)
7595 name
= "complex unsigned char";
7596 else if (TREE_TYPE (t
) == short_integer_type_node
)
7597 name
= "complex short int";
7598 else if (TREE_TYPE (t
) == short_unsigned_type_node
)
7599 name
= "complex short unsigned int";
7600 else if (TREE_TYPE (t
) == integer_type_node
)
7601 name
= "complex int";
7602 else if (TREE_TYPE (t
) == unsigned_type_node
)
7603 name
= "complex unsigned int";
7604 else if (TREE_TYPE (t
) == long_integer_type_node
)
7605 name
= "complex long int";
7606 else if (TREE_TYPE (t
) == long_unsigned_type_node
)
7607 name
= "complex long unsigned int";
7608 else if (TREE_TYPE (t
) == long_long_integer_type_node
)
7609 name
= "complex long long int";
7610 else if (TREE_TYPE (t
) == long_long_unsigned_type_node
)
7611 name
= "complex long long unsigned int";
7614 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
7615 get_identifier (name
), t
);
7619 return build_qualified_type (t
, TYPE_QUALS (component_type
));
7622 /* If TYPE is a real or complex floating-point type and the target
7623 does not directly support arithmetic on TYPE then return the wider
7624 type to be used for arithmetic on TYPE. Otherwise, return
7628 excess_precision_type (tree type
)
7630 /* The target can give two different responses to the question of
7631 which excess precision mode it would like depending on whether we
7632 are in -fexcess-precision=standard or -fexcess-precision=fast. */
7634 enum excess_precision_type requested_type
7635 = (flag_excess_precision
== EXCESS_PRECISION_FAST
7636 ? EXCESS_PRECISION_TYPE_FAST
7637 : (flag_excess_precision
== EXCESS_PRECISION_FLOAT16
7638 ? EXCESS_PRECISION_TYPE_FLOAT16
:EXCESS_PRECISION_TYPE_STANDARD
));
7640 enum flt_eval_method target_flt_eval_method
7641 = targetm
.c
.excess_precision (requested_type
);
7643 /* The target should not ask for unpredictable float evaluation (though
7644 it might advertise that implicitly the evaluation is unpredictable,
7645 but we don't care about that here, it will have been reported
7646 elsewhere). If it does ask for unpredictable evaluation, we have
7647 nothing to do here. */
7648 gcc_assert (target_flt_eval_method
!= FLT_EVAL_METHOD_UNPREDICTABLE
);
7650 /* Nothing to do. The target has asked for all types we know about
7651 to be computed with their native precision and range. */
7652 if (target_flt_eval_method
== FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
)
7655 /* The target will promote this type in a target-dependent way, so excess
7656 precision ought to leave it alone. */
7657 if (targetm
.promoted_type (type
) != NULL_TREE
)
7660 machine_mode float16_type_mode
= (float16_type_node
7661 ? TYPE_MODE (float16_type_node
)
7663 machine_mode float_type_mode
= TYPE_MODE (float_type_node
);
7664 machine_mode double_type_mode
= TYPE_MODE (double_type_node
);
7666 switch (TREE_CODE (type
))
7670 machine_mode type_mode
= TYPE_MODE (type
);
7671 switch (target_flt_eval_method
)
7673 case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
:
7674 if (type_mode
== float16_type_mode
)
7675 return float_type_node
;
7677 case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE
:
7678 if (type_mode
== float16_type_mode
7679 || type_mode
== float_type_mode
)
7680 return double_type_node
;
7682 case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE
:
7683 if (type_mode
== float16_type_mode
7684 || type_mode
== float_type_mode
7685 || type_mode
== double_type_mode
)
7686 return long_double_type_node
;
7695 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
7697 machine_mode type_mode
= TYPE_MODE (TREE_TYPE (type
));
7698 switch (target_flt_eval_method
)
7700 case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
:
7701 if (type_mode
== float16_type_mode
)
7702 return complex_float_type_node
;
7704 case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE
:
7705 if (type_mode
== float16_type_mode
7706 || type_mode
== float_type_mode
)
7707 return complex_double_type_node
;
7709 case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE
:
7710 if (type_mode
== float16_type_mode
7711 || type_mode
== float_type_mode
7712 || type_mode
== double_type_mode
)
7713 return complex_long_double_type_node
;
7727 /* Return OP, stripped of any conversions to wider types as much as is safe.
7728 Converting the value back to OP's type makes a value equivalent to OP.
7730 If FOR_TYPE is nonzero, we return a value which, if converted to
7731 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
7733 OP must have integer, real or enumeral type. Pointers are not allowed!
7735 There are some cases where the obvious value we could return
7736 would regenerate to OP if converted to OP's type,
7737 but would not extend like OP to wider types.
7738 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
7739 For example, if OP is (unsigned short)(signed char)-1,
7740 we avoid returning (signed char)-1 if FOR_TYPE is int,
7741 even though extending that to an unsigned short would regenerate OP,
7742 since the result of extending (signed char)-1 to (int)
7743 is different from (int) OP. */
7746 get_unwidened (tree op
, tree for_type
)
7748 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
7749 tree type
= TREE_TYPE (op
);
7751 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
7753 = (for_type
!= 0 && for_type
!= type
7754 && final_prec
> TYPE_PRECISION (type
)
7755 && TYPE_UNSIGNED (type
));
7758 while (CONVERT_EXPR_P (op
))
7762 /* TYPE_PRECISION on vector types has different meaning
7763 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
7764 so avoid them here. */
7765 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
7768 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
7769 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
7771 /* Truncations are many-one so cannot be removed.
7772 Unless we are later going to truncate down even farther. */
7774 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
7777 /* See what's inside this conversion. If we decide to strip it,
7779 op
= TREE_OPERAND (op
, 0);
7781 /* If we have not stripped any zero-extensions (uns is 0),
7782 we can strip any kind of extension.
7783 If we have previously stripped a zero-extension,
7784 only zero-extensions can safely be stripped.
7785 Any extension can be stripped if the bits it would produce
7786 are all going to be discarded later by truncating to FOR_TYPE. */
7790 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
7792 /* TYPE_UNSIGNED says whether this is a zero-extension.
7793 Let's avoid computing it if it does not affect WIN
7794 and if UNS will not be needed again. */
7796 || CONVERT_EXPR_P (op
))
7797 && TYPE_UNSIGNED (TREE_TYPE (op
)))
7805 /* If we finally reach a constant see if it fits in sth smaller and
7806 in that case convert it. */
7807 if (TREE_CODE (win
) == INTEGER_CST
)
7809 tree wtype
= TREE_TYPE (win
);
7810 unsigned prec
= wi::min_precision (wi::to_wide (win
), TYPE_SIGN (wtype
));
7812 prec
= MAX (prec
, final_prec
);
7813 if (prec
< TYPE_PRECISION (wtype
))
7815 tree t
= lang_hooks
.types
.type_for_size (prec
, TYPE_UNSIGNED (wtype
));
7816 if (t
&& TYPE_PRECISION (t
) < TYPE_PRECISION (wtype
))
7817 win
= fold_convert (t
, win
);
7824 /* Return OP or a simpler expression for a narrower value
7825 which can be sign-extended or zero-extended to give back OP.
7826 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
7827 or 0 if the value should be sign-extended. */
7830 get_narrower (tree op
, int *unsignedp_ptr
)
7835 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
7837 if (TREE_CODE (op
) == COMPOUND_EXPR
)
7840 op
= TREE_OPERAND (op
, 1);
7841 while (TREE_CODE (op
) == COMPOUND_EXPR
);
7842 tree ret
= get_narrower (op
, unsignedp_ptr
);
7845 auto_vec
<tree
, 16> v
;
7847 for (op
= win
; TREE_CODE (op
) == COMPOUND_EXPR
;
7848 op
= TREE_OPERAND (op
, 1))
7850 FOR_EACH_VEC_ELT_REVERSE (v
, i
, op
)
7851 ret
= build2_loc (EXPR_LOCATION (op
), COMPOUND_EXPR
,
7852 TREE_TYPE (ret
), TREE_OPERAND (op
, 0),
7856 while (TREE_CODE (op
) == NOP_EXPR
)
7859 = (TYPE_PRECISION (TREE_TYPE (op
))
7860 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
7862 /* Truncations are many-one so cannot be removed. */
7866 /* See what's inside this conversion. If we decide to strip it,
7871 op
= TREE_OPERAND (op
, 0);
7872 /* An extension: the outermost one can be stripped,
7873 but remember whether it is zero or sign extension. */
7875 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
7876 /* Otherwise, if a sign extension has been stripped,
7877 only sign extensions can now be stripped;
7878 if a zero extension has been stripped, only zero-extensions. */
7879 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
7883 else /* bitschange == 0 */
7885 /* A change in nominal type can always be stripped, but we must
7886 preserve the unsignedness. */
7888 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
7890 op
= TREE_OPERAND (op
, 0);
7891 /* Keep trying to narrow, but don't assign op to win if it
7892 would turn an integral type into something else. */
7893 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
7900 if (TREE_CODE (op
) == COMPONENT_REF
7901 /* Since type_for_size always gives an integer type. */
7902 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
7903 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
7904 /* Ensure field is laid out already. */
7905 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
7906 && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op
, 1))))
7908 unsigned HOST_WIDE_INT innerprec
7909 = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op
, 1)));
7910 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
7911 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
7912 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
7914 /* We can get this structure field in a narrower type that fits it,
7915 but the resulting extension to its nominal type (a fullword type)
7916 must satisfy the same conditions as for other extensions.
7918 Do this only for fields that are aligned (not bit-fields),
7919 because when bit-field insns will be used there is no
7920 advantage in doing this. */
7922 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
7923 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
7924 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
7928 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
7929 win
= fold_convert (type
, op
);
7933 *unsignedp_ptr
= uns
;
7937 /* Return true if integer constant C has a value that is permissible
7938 for TYPE, an integral type. */
7941 int_fits_type_p (const_tree c
, const_tree type
)
7943 tree type_low_bound
, type_high_bound
;
7944 bool ok_for_low_bound
, ok_for_high_bound
;
7945 signop sgn_c
= TYPE_SIGN (TREE_TYPE (c
));
7947 /* Non-standard boolean types can have arbitrary precision but various
7948 transformations assume that they can only take values 0 and +/-1. */
7949 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
7950 return wi::fits_to_boolean_p (wi::to_wide (c
), type
);
7953 type_low_bound
= TYPE_MIN_VALUE (type
);
7954 type_high_bound
= TYPE_MAX_VALUE (type
);
7956 /* If at least one bound of the type is a constant integer, we can check
7957 ourselves and maybe make a decision. If no such decision is possible, but
7958 this type is a subtype, try checking against that. Otherwise, use
7959 fits_to_tree_p, which checks against the precision.
7961 Compute the status for each possibly constant bound, and return if we see
7962 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
7963 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
7964 for "constant known to fit". */
7966 /* Check if c >= type_low_bound. */
7967 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
7969 if (tree_int_cst_lt (c
, type_low_bound
))
7971 ok_for_low_bound
= true;
7974 ok_for_low_bound
= false;
7976 /* Check if c <= type_high_bound. */
7977 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
7979 if (tree_int_cst_lt (type_high_bound
, c
))
7981 ok_for_high_bound
= true;
7984 ok_for_high_bound
= false;
7986 /* If the constant fits both bounds, the result is known. */
7987 if (ok_for_low_bound
&& ok_for_high_bound
)
7990 /* Perform some generic filtering which may allow making a decision
7991 even if the bounds are not constant. First, negative integers
7992 never fit in unsigned types, */
7993 if (TYPE_UNSIGNED (type
) && sgn_c
== SIGNED
&& wi::neg_p (wi::to_wide (c
)))
7996 /* Second, narrower types always fit in wider ones. */
7997 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8000 /* Third, unsigned integers with top bit set never fit signed types. */
8001 if (!TYPE_UNSIGNED (type
) && sgn_c
== UNSIGNED
)
8003 int prec
= GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c
))) - 1;
8004 if (prec
< TYPE_PRECISION (TREE_TYPE (c
)))
8006 /* When a tree_cst is converted to a wide-int, the precision
8007 is taken from the type. However, if the precision of the
8008 mode underneath the type is smaller than that, it is
8009 possible that the value will not fit. The test below
8010 fails if any bit is set between the sign bit of the
8011 underlying mode and the top bit of the type. */
8012 if (wi::zext (wi::to_wide (c
), prec
- 1) != wi::to_wide (c
))
8015 else if (wi::neg_p (wi::to_wide (c
)))
8019 /* If we haven't been able to decide at this point, there nothing more we
8020 can check ourselves here. Look at the base type if we have one and it
8021 has the same precision. */
8022 if (TREE_CODE (type
) == INTEGER_TYPE
8023 && TREE_TYPE (type
) != 0
8024 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8026 type
= TREE_TYPE (type
);
8030 /* Or to fits_to_tree_p, if nothing else. */
8031 return wi::fits_to_tree_p (wi::to_wide (c
), type
);
8034 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8035 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8036 represented (assuming two's-complement arithmetic) within the bit
8037 precision of the type are returned instead. */
8040 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8042 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8043 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8044 wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type
)), min
, TYPE_SIGN (type
));
8047 if (TYPE_UNSIGNED (type
))
8048 mpz_set_ui (min
, 0);
8051 wide_int mn
= wi::min_value (TYPE_PRECISION (type
), SIGNED
);
8052 wi::to_mpz (mn
, min
, SIGNED
);
8056 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8057 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8058 wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type
)), max
, TYPE_SIGN (type
));
8061 wide_int mn
= wi::max_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
8062 wi::to_mpz (mn
, max
, TYPE_SIGN (type
));
8066 /* Return true if VAR is an automatic variable. */
8069 auto_var_p (const_tree var
)
8071 return ((((VAR_P (var
) && ! DECL_EXTERNAL (var
))
8072 || TREE_CODE (var
) == PARM_DECL
)
8073 && ! TREE_STATIC (var
))
8074 || TREE_CODE (var
) == RESULT_DECL
);
8077 /* Return true if VAR is an automatic variable defined in function FN. */
8080 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8082 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8083 && (auto_var_p (var
)
8084 || TREE_CODE (var
) == LABEL_DECL
));
8087 /* Subprogram of following function. Called by walk_tree.
8089 Return *TP if it is an automatic variable or parameter of the
8090 function passed in as DATA. */
8093 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8095 tree fn
= (tree
) data
;
8100 else if (DECL_P (*tp
)
8101 && auto_var_in_fn_p (*tp
, fn
))
8107 /* Returns true if T is, contains, or refers to a type with variable
8108 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8109 arguments, but not the return type. If FN is nonzero, only return
8110 true if a modifier of the type or position of FN is a variable or
8111 parameter inside FN.
8113 This concept is more general than that of C99 'variably modified types':
8114 in C99, a struct type is never variably modified because a VLA may not
8115 appear as a structure member. However, in GNU C code like:
8117 struct S { int i[f()]; };
8119 is valid, and other languages may define similar constructs. */
8122 variably_modified_type_p (tree type
, tree fn
)
8126 /* Test if T is either variable (if FN is zero) or an expression containing
8127 a variable in FN. If TYPE isn't gimplified, return true also if
8128 gimplify_one_sizepos would gimplify the expression into a local
8130 #define RETURN_TRUE_IF_VAR(T) \
8131 do { tree _t = (T); \
8132 if (_t != NULL_TREE \
8133 && _t != error_mark_node \
8134 && !CONSTANT_CLASS_P (_t) \
8135 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8137 || (!TYPE_SIZES_GIMPLIFIED (type) \
8138 && (TREE_CODE (_t) != VAR_DECL \
8139 && !CONTAINS_PLACEHOLDER_P (_t))) \
8140 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8141 return true; } while (0)
8143 if (type
== error_mark_node
)
8146 /* If TYPE itself has variable size, it is variably modified. */
8147 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8148 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8150 switch (TREE_CODE (type
))
8153 case REFERENCE_TYPE
:
8155 /* Ada can have pointer types refering to themselves indirectly. */
8156 if (TREE_VISITED (type
))
8158 TREE_VISITED (type
) = true;
8159 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8161 TREE_VISITED (type
) = false;
8164 TREE_VISITED (type
) = false;
8169 /* If TYPE is a function type, it is variably modified if the
8170 return type is variably modified. */
8171 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8177 case FIXED_POINT_TYPE
:
8180 /* Scalar types are variably modified if their end points
8182 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8183 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8188 case QUAL_UNION_TYPE
:
8189 /* We can't see if any of the fields are variably-modified by the
8190 definition we normally use, since that would produce infinite
8191 recursion via pointers. */
8192 /* This is variably modified if some field's type is. */
8193 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8194 if (TREE_CODE (t
) == FIELD_DECL
)
8196 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8197 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8198 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8200 /* If the type is a qualified union, then the DECL_QUALIFIER
8201 of fields can also be an expression containing a variable. */
8202 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8203 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8205 /* If the field is a qualified union, then it's only a container
8206 for what's inside so we look into it. That's necessary in LTO
8207 mode because the sizes of the field tested above have been set
8208 to PLACEHOLDER_EXPRs by free_lang_data. */
8209 if (TREE_CODE (TREE_TYPE (t
)) == QUAL_UNION_TYPE
8210 && variably_modified_type_p (TREE_TYPE (t
), fn
))
8216 /* Do not call ourselves to avoid infinite recursion. This is
8217 variably modified if the element type is. */
8218 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8219 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8226 /* The current language may have other cases to check, but in general,
8227 all other types are not variably modified. */
8228 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8230 #undef RETURN_TRUE_IF_VAR
8233 /* Given a DECL or TYPE, return the scope in which it was declared, or
8234 NULL_TREE if there is no containing scope. */
8237 get_containing_scope (const_tree t
)
8239 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8242 /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8245 get_ultimate_context (const_tree decl
)
8247 while (decl
&& TREE_CODE (decl
) != TRANSLATION_UNIT_DECL
)
8249 if (TREE_CODE (decl
) == BLOCK
)
8250 decl
= BLOCK_SUPERCONTEXT (decl
);
8252 decl
= get_containing_scope (decl
);
8257 /* Return the innermost context enclosing DECL that is
8258 a FUNCTION_DECL, or zero if none. */
8261 decl_function_context (const_tree decl
)
8265 if (TREE_CODE (decl
) == ERROR_MARK
)
8268 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8269 where we look up the function at runtime. Such functions always take
8270 a first argument of type 'pointer to real context'.
8272 C++ should really be fixed to use DECL_CONTEXT for the real context,
8273 and use something else for the "virtual context". */
8274 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
8277 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8279 context
= DECL_CONTEXT (decl
);
8281 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8283 if (TREE_CODE (context
) == BLOCK
)
8284 context
= BLOCK_SUPERCONTEXT (context
);
8286 context
= get_containing_scope (context
);
8292 /* Return the innermost context enclosing DECL that is
8293 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8294 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8297 decl_type_context (const_tree decl
)
8299 tree context
= DECL_CONTEXT (decl
);
8302 switch (TREE_CODE (context
))
8304 case NAMESPACE_DECL
:
8305 case TRANSLATION_UNIT_DECL
:
8310 case QUAL_UNION_TYPE
:
8315 context
= DECL_CONTEXT (context
);
8319 context
= BLOCK_SUPERCONTEXT (context
);
8329 /* CALL is a CALL_EXPR. Return the declaration for the function
8330 called, or NULL_TREE if the called function cannot be
8334 get_callee_fndecl (const_tree call
)
8338 if (call
== error_mark_node
)
8339 return error_mark_node
;
8341 /* It's invalid to call this function with anything but a
8343 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8345 /* The first operand to the CALL is the address of the function
8347 addr
= CALL_EXPR_FN (call
);
8349 /* If there is no function, return early. */
8350 if (addr
== NULL_TREE
)
8355 /* If this is a readonly function pointer, extract its initial value. */
8356 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
8357 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
8358 && DECL_INITIAL (addr
))
8359 addr
= DECL_INITIAL (addr
);
8361 /* If the address is just `&f' for some function `f', then we know
8362 that `f' is being called. */
8363 if (TREE_CODE (addr
) == ADDR_EXPR
8364 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
8365 return TREE_OPERAND (addr
, 0);
8367 /* We couldn't figure out what was being called. */
8371 /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8372 return the associated function code, otherwise return CFN_LAST. */
8375 get_call_combined_fn (const_tree call
)
8377 /* It's invalid to call this function with anything but a CALL_EXPR. */
8378 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8380 if (!CALL_EXPR_FN (call
))
8381 return as_combined_fn (CALL_EXPR_IFN (call
));
8383 tree fndecl
= get_callee_fndecl (call
);
8384 if (fndecl
&& fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
8385 return as_combined_fn (DECL_FUNCTION_CODE (fndecl
));
8390 /* Comparator of indices based on tree_node_counts. */
8393 tree_nodes_cmp (const void *p1
, const void *p2
)
8395 const unsigned *n1
= (const unsigned *)p1
;
8396 const unsigned *n2
= (const unsigned *)p2
;
8398 return tree_node_counts
[*n1
] - tree_node_counts
[*n2
];
8401 /* Comparator of indices based on tree_code_counts. */
8404 tree_codes_cmp (const void *p1
, const void *p2
)
8406 const unsigned *n1
= (const unsigned *)p1
;
8407 const unsigned *n2
= (const unsigned *)p2
;
8409 return tree_code_counts
[*n1
] - tree_code_counts
[*n2
];
8412 #define TREE_MEM_USAGE_SPACES 40
8414 /* Print debugging information about tree nodes generated during the compile,
8415 and any language-specific information. */
8418 dump_tree_statistics (void)
8420 if (GATHER_STATISTICS
)
8422 uint64_t total_nodes
, total_bytes
;
8423 fprintf (stderr
, "\nKind Nodes Bytes\n");
8424 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
8425 total_nodes
= total_bytes
= 0;
8428 auto_vec
<unsigned> indices (all_kinds
);
8429 for (unsigned i
= 0; i
< all_kinds
; i
++)
8430 indices
.quick_push (i
);
8431 indices
.qsort (tree_nodes_cmp
);
8433 for (unsigned i
= 0; i
< (int) all_kinds
; i
++)
8435 unsigned j
= indices
[i
];
8436 fprintf (stderr
, "%-20s %6" PRIu64
"%c %9" PRIu64
"%c\n",
8437 tree_node_kind_names
[j
], SIZE_AMOUNT (tree_node_counts
[j
]),
8438 SIZE_AMOUNT (tree_node_sizes
[j
]));
8439 total_nodes
+= tree_node_counts
[j
];
8440 total_bytes
+= tree_node_sizes
[j
];
8442 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
8443 fprintf (stderr
, "%-20s %6" PRIu64
"%c %9" PRIu64
"%c\n", "Total",
8444 SIZE_AMOUNT (total_nodes
), SIZE_AMOUNT (total_bytes
));
8445 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
8449 fprintf (stderr
, "Code Nodes\n");
8450 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
8452 auto_vec
<unsigned> indices (MAX_TREE_CODES
);
8453 for (unsigned i
= 0; i
< MAX_TREE_CODES
; i
++)
8454 indices
.quick_push (i
);
8455 indices
.qsort (tree_codes_cmp
);
8457 for (unsigned i
= 0; i
< MAX_TREE_CODES
; i
++)
8459 unsigned j
= indices
[i
];
8460 fprintf (stderr
, "%-32s %6" PRIu64
"%c\n",
8461 get_tree_code_name ((enum tree_code
) j
),
8462 SIZE_AMOUNT (tree_code_counts
[j
]));
8464 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES
);
8465 fprintf (stderr
, "\n");
8466 ssanames_print_statistics ();
8467 fprintf (stderr
, "\n");
8468 phinodes_print_statistics ();
8469 fprintf (stderr
, "\n");
8473 fprintf (stderr
, "(No per-node statistics)\n");
8475 print_type_hash_statistics ();
8476 print_debug_expr_statistics ();
8477 print_value_expr_statistics ();
8478 lang_hooks
.print_statistics ();
8481 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8483 /* Generate a crc32 of the low BYTES bytes of VALUE. */
8486 crc32_unsigned_n (unsigned chksum
, unsigned value
, unsigned bytes
)
8488 /* This relies on the raw feedback's top 4 bits being zero. */
8489 #define FEEDBACK(X) ((X) * 0x04c11db7)
8490 #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8491 ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8492 static const unsigned syndromes
[16] =
8494 SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8495 SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8496 SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8497 SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8502 value
<<= (32 - bytes
* 8);
8503 for (unsigned ix
= bytes
* 2; ix
--; value
<<= 4)
8505 unsigned feedback
= syndromes
[((value
^ chksum
) >> 28) & 0xf];
8507 chksum
= (chksum
<< 4) ^ feedback
;
8513 /* Generate a crc32 of a string. */
8516 crc32_string (unsigned chksum
, const char *string
)
8519 chksum
= crc32_byte (chksum
, *string
);
8524 /* P is a string that will be used in a symbol. Mask out any characters
8525 that are not valid in that context. */
8528 clean_symbol_name (char *p
)
8532 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8535 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8542 static GTY(()) unsigned anon_cnt
= 0; /* Saved for PCH. */
8544 /* Create a unique anonymous identifier. The identifier is still a
8545 valid assembly label. */
8551 #if !defined (NO_DOT_IN_LABEL)
8553 #elif !defined (NO_DOLLAR_IN_LABEL)
8561 int len
= snprintf (buf
, sizeof (buf
), fmt
, anon_cnt
++);
8562 gcc_checking_assert (len
< int (sizeof (buf
)));
8564 tree id
= get_identifier_with_length (buf
, len
);
8565 IDENTIFIER_ANON_P (id
) = true;
8570 /* Generate a name for a special-purpose function.
8571 The generated name may need to be unique across the whole link.
8572 Changes to this function may also require corresponding changes to
8573 xstrdup_mask_random.
8574 TYPE is some string to identify the purpose of this function to the
8575 linker or collect2; it must start with an uppercase letter,
8577 I - for constructors
8579 N - for C++ anonymous namespaces
8580 F - for DWARF unwind frame information. */
8583 get_file_function_name (const char *type
)
8589 /* If we already have a name we know to be unique, just use that. */
8590 if (first_global_object_name
)
8591 p
= q
= ASTRDUP (first_global_object_name
);
8592 /* If the target is handling the constructors/destructors, they
8593 will be local to this file and the name is only necessary for
8595 We also assign sub_I and sub_D sufixes to constructors called from
8596 the global static constructors. These are always local. */
8597 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
8598 || (startswith (type
, "sub_")
8599 && (type
[4] == 'I' || type
[4] == 'D')))
8601 const char *file
= main_input_filename
;
8603 file
= LOCATION_FILE (input_location
);
8604 /* Just use the file's basename, because the full pathname
8605 might be quite long. */
8606 p
= q
= ASTRDUP (lbasename (file
));
8610 /* Otherwise, the name must be unique across the entire link.
8611 We don't have anything that we know to be unique to this translation
8612 unit, so use what we do have and throw in some randomness. */
8614 const char *name
= weak_global_object_name
;
8615 const char *file
= main_input_filename
;
8620 file
= LOCATION_FILE (input_location
);
8622 len
= strlen (file
);
8623 q
= (char *) alloca (9 + 19 + len
+ 1);
8624 memcpy (q
, file
, len
+ 1);
8626 snprintf (q
+ len
, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
8627 crc32_string (0, name
), get_random_seed (false));
8632 clean_symbol_name (q
);
8633 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
8636 /* Set up the name of the file-level functions we may need.
8637 Use a global object (which is already required to be unique over
8638 the program) rather than the file name (which imposes extra
8640 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
8642 return get_identifier (buf
);
8645 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
8647 /* Complain that the tree code of NODE does not match the expected 0
8648 terminated list of trailing codes. The trailing code list can be
8649 empty, for a more vague error message. FILE, LINE, and FUNCTION
8650 are of the caller. */
8653 tree_check_failed (const_tree node
, const char *file
,
8654 int line
, const char *function
, ...)
8658 unsigned length
= 0;
8659 enum tree_code code
;
8661 va_start (args
, function
);
8662 while ((code
= (enum tree_code
) va_arg (args
, int)))
8663 length
+= 4 + strlen (get_tree_code_name (code
));
8668 va_start (args
, function
);
8669 length
+= strlen ("expected ");
8670 buffer
= tmp
= (char *) alloca (length
);
8672 while ((code
= (enum tree_code
) va_arg (args
, int)))
8674 const char *prefix
= length
? " or " : "expected ";
8676 strcpy (tmp
+ length
, prefix
);
8677 length
+= strlen (prefix
);
8678 strcpy (tmp
+ length
, get_tree_code_name (code
));
8679 length
+= strlen (get_tree_code_name (code
));
8684 buffer
= "unexpected node";
8686 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8687 buffer
, get_tree_code_name (TREE_CODE (node
)),
8688 function
, trim_filename (file
), line
);
8691 /* Complain that the tree code of NODE does match the expected 0
8692 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
8696 tree_not_check_failed (const_tree node
, const char *file
,
8697 int line
, const char *function
, ...)
8701 unsigned length
= 0;
8702 enum tree_code code
;
8704 va_start (args
, function
);
8705 while ((code
= (enum tree_code
) va_arg (args
, int)))
8706 length
+= 4 + strlen (get_tree_code_name (code
));
8708 va_start (args
, function
);
8709 buffer
= (char *) alloca (length
);
8711 while ((code
= (enum tree_code
) va_arg (args
, int)))
8715 strcpy (buffer
+ length
, " or ");
8718 strcpy (buffer
+ length
, get_tree_code_name (code
));
8719 length
+= strlen (get_tree_code_name (code
));
8723 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
8724 buffer
, get_tree_code_name (TREE_CODE (node
)),
8725 function
, trim_filename (file
), line
);
8728 /* Similar to tree_check_failed, except that we check for a class of tree
8729 code, given in CL. */
8732 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8733 const char *file
, int line
, const char *function
)
8736 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
8737 TREE_CODE_CLASS_STRING (cl
),
8738 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8739 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
8742 /* Similar to tree_check_failed, except that instead of specifying a
8743 dozen codes, use the knowledge that they're all sequential. */
8746 tree_range_check_failed (const_tree node
, const char *file
, int line
,
8747 const char *function
, enum tree_code c1
,
8751 unsigned length
= 0;
8754 for (c
= c1
; c
<= c2
; ++c
)
8755 length
+= 4 + strlen (get_tree_code_name ((enum tree_code
) c
));
8757 length
+= strlen ("expected ");
8758 buffer
= (char *) alloca (length
);
8761 for (c
= c1
; c
<= c2
; ++c
)
8763 const char *prefix
= length
? " or " : "expected ";
8765 strcpy (buffer
+ length
, prefix
);
8766 length
+= strlen (prefix
);
8767 strcpy (buffer
+ length
, get_tree_code_name ((enum tree_code
) c
));
8768 length
+= strlen (get_tree_code_name ((enum tree_code
) c
));
8771 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8772 buffer
, get_tree_code_name (TREE_CODE (node
)),
8773 function
, trim_filename (file
), line
);
8777 /* Similar to tree_check_failed, except that we check that a tree does
8778 not have the specified code, given in CL. */
8781 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8782 const char *file
, int line
, const char *function
)
8785 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
8786 TREE_CODE_CLASS_STRING (cl
),
8787 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8788 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
8792 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
8795 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
8796 const char *function
, enum omp_clause_code code
)
8798 internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
8800 omp_clause_code_name
[code
],
8801 get_tree_code_name (TREE_CODE (node
)),
8802 function
, trim_filename (file
), line
);
8806 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
8809 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
8810 const char *function
, enum omp_clause_code c1
,
8811 enum omp_clause_code c2
)
8814 unsigned length
= 0;
8817 for (c
= c1
; c
<= c2
; ++c
)
8818 length
+= 4 + strlen (omp_clause_code_name
[c
]);
8820 length
+= strlen ("expected ");
8821 buffer
= (char *) alloca (length
);
8824 for (c
= c1
; c
<= c2
; ++c
)
8826 const char *prefix
= length
? " or " : "expected ";
8828 strcpy (buffer
+ length
, prefix
);
8829 length
+= strlen (prefix
);
8830 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
8831 length
+= strlen (omp_clause_code_name
[c
]);
8834 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8835 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
8836 function
, trim_filename (file
), line
);
8840 #undef DEFTREESTRUCT
8841 #define DEFTREESTRUCT(VAL, NAME) NAME,
8843 static const char *ts_enum_names
[] = {
8844 #include "treestruct.def"
8846 #undef DEFTREESTRUCT
8848 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
8850 /* Similar to tree_class_check_failed, except that we check for
8851 whether CODE contains the tree structure identified by EN. */
8854 tree_contains_struct_check_failed (const_tree node
,
8855 const enum tree_node_structure_enum en
,
8856 const char *file
, int line
,
8857 const char *function
)
8860 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
8862 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
8866 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
8867 (dynamically sized) vector. */
8870 tree_int_cst_elt_check_failed (int idx
, int len
, const char *file
, int line
,
8871 const char *function
)
8874 ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
8876 idx
+ 1, len
, function
, trim_filename (file
), line
);
8879 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
8880 (dynamically sized) vector. */
8883 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
8884 const char *function
)
8887 ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
8888 idx
+ 1, len
, function
, trim_filename (file
), line
);
8891 /* Similar to above, except that the check is for the bounds of the operand
8892 vector of an expression node EXP. */
8895 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
8896 int line
, const char *function
)
8898 enum tree_code code
= TREE_CODE (exp
);
8900 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
8901 idx
+ 1, get_tree_code_name (code
), TREE_OPERAND_LENGTH (exp
),
8902 function
, trim_filename (file
), line
);
8905 /* Similar to above, except that the check is for the number of
8906 operands of an OMP_CLAUSE node. */
8909 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
8910 int line
, const char *function
)
8913 ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
8914 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
8915 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
8916 trim_filename (file
), line
);
8918 #endif /* ENABLE_TREE_CHECKING */
8920 /* Create a new vector type node holding NUNITS units of type INNERTYPE,
8921 and mapped to the machine mode MODE. Initialize its fields and build
8922 the information necessary for debugging output. */
8925 make_vector_type (tree innertype
, poly_int64 nunits
, machine_mode mode
)
8928 tree mv_innertype
= TYPE_MAIN_VARIANT (innertype
);
8930 t
= make_node (VECTOR_TYPE
);
8931 TREE_TYPE (t
) = mv_innertype
;
8932 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
8933 SET_TYPE_MODE (t
, mode
);
8935 if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype
) || in_lto_p
)
8936 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8937 else if ((TYPE_CANONICAL (mv_innertype
) != innertype
8938 || mode
!= VOIDmode
)
8939 && !VECTOR_BOOLEAN_TYPE_P (t
))
8941 = make_vector_type (TYPE_CANONICAL (mv_innertype
), nunits
, VOIDmode
);
8945 hashval_t hash
= type_hash_canon_hash (t
);
8946 t
= type_hash_canon (hash
, t
);
8948 /* We have built a main variant, based on the main variant of the
8949 inner type. Use it to build the variant we return. */
8950 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
8951 && TREE_TYPE (t
) != innertype
)
8952 return build_type_attribute_qual_variant (t
,
8953 TYPE_ATTRIBUTES (innertype
),
8954 TYPE_QUALS (innertype
));
8960 make_or_reuse_type (unsigned size
, int unsignedp
)
8964 if (size
== INT_TYPE_SIZE
)
8965 return unsignedp
? unsigned_type_node
: integer_type_node
;
8966 if (size
== CHAR_TYPE_SIZE
)
8967 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
8968 if (size
== SHORT_TYPE_SIZE
)
8969 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
8970 if (size
== LONG_TYPE_SIZE
)
8971 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
8972 if (size
== LONG_LONG_TYPE_SIZE
)
8973 return (unsignedp
? long_long_unsigned_type_node
8974 : long_long_integer_type_node
);
8976 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
8977 if (size
== int_n_data
[i
].bitsize
8978 && int_n_enabled_p
[i
])
8979 return (unsignedp
? int_n_trees
[i
].unsigned_type
8980 : int_n_trees
[i
].signed_type
);
8983 return make_unsigned_type (size
);
8985 return make_signed_type (size
);
8988 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
8991 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
8995 if (size
== SHORT_FRACT_TYPE_SIZE
)
8996 return unsignedp
? sat_unsigned_short_fract_type_node
8997 : sat_short_fract_type_node
;
8998 if (size
== FRACT_TYPE_SIZE
)
8999 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9000 if (size
== LONG_FRACT_TYPE_SIZE
)
9001 return unsignedp
? sat_unsigned_long_fract_type_node
9002 : sat_long_fract_type_node
;
9003 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9004 return unsignedp
? sat_unsigned_long_long_fract_type_node
9005 : sat_long_long_fract_type_node
;
9009 if (size
== SHORT_FRACT_TYPE_SIZE
)
9010 return unsignedp
? unsigned_short_fract_type_node
9011 : short_fract_type_node
;
9012 if (size
== FRACT_TYPE_SIZE
)
9013 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9014 if (size
== LONG_FRACT_TYPE_SIZE
)
9015 return unsignedp
? unsigned_long_fract_type_node
9016 : long_fract_type_node
;
9017 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9018 return unsignedp
? unsigned_long_long_fract_type_node
9019 : long_long_fract_type_node
;
9022 return make_fract_type (size
, unsignedp
, satp
);
9025 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9028 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9032 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9033 return unsignedp
? sat_unsigned_short_accum_type_node
9034 : sat_short_accum_type_node
;
9035 if (size
== ACCUM_TYPE_SIZE
)
9036 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9037 if (size
== LONG_ACCUM_TYPE_SIZE
)
9038 return unsignedp
? sat_unsigned_long_accum_type_node
9039 : sat_long_accum_type_node
;
9040 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9041 return unsignedp
? sat_unsigned_long_long_accum_type_node
9042 : sat_long_long_accum_type_node
;
9046 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9047 return unsignedp
? unsigned_short_accum_type_node
9048 : short_accum_type_node
;
9049 if (size
== ACCUM_TYPE_SIZE
)
9050 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9051 if (size
== LONG_ACCUM_TYPE_SIZE
)
9052 return unsignedp
? unsigned_long_accum_type_node
9053 : long_accum_type_node
;
9054 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9055 return unsignedp
? unsigned_long_long_accum_type_node
9056 : long_long_accum_type_node
;
9059 return make_accum_type (size
, unsignedp
, satp
);
9063 /* Create an atomic variant node for TYPE. This routine is called
9064 during initialization of data types to create the 5 basic atomic
9065 types. The generic build_variant_type function requires these to
9066 already be set up in order to function properly, so cannot be
9067 called from there. If ALIGN is non-zero, then ensure alignment is
9068 overridden to this value. */
9071 build_atomic_base (tree type
, unsigned int align
)
9075 /* Make sure its not already registered. */
9076 if ((t
= get_qualified_type (type
, TYPE_QUAL_ATOMIC
)))
9079 t
= build_variant_type_copy (type
);
9080 set_type_quals (t
, TYPE_QUAL_ATOMIC
);
9083 SET_TYPE_ALIGN (t
, align
);
9088 /* Information about the _FloatN and _FloatNx types. This must be in
9089 the same order as the corresponding TI_* enum values. */
9090 const floatn_type_info floatn_nx_types
[NUM_FLOATN_NX_TYPES
] =
9102 /* Create nodes for all integer types (and error_mark_node) using the sizes
9103 of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9106 build_common_tree_nodes (bool signed_char
)
9110 error_mark_node
= make_node (ERROR_MARK
);
9111 TREE_TYPE (error_mark_node
) = error_mark_node
;
9113 initialize_sizetypes ();
9115 /* Define both `signed char' and `unsigned char'. */
9116 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9117 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9118 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9119 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9121 /* Define `char', which is like either `signed char' or `unsigned char'
9122 but not the same as either. */
9125 ? make_signed_type (CHAR_TYPE_SIZE
)
9126 : make_unsigned_type (CHAR_TYPE_SIZE
));
9127 TYPE_STRING_FLAG (char_type_node
) = 1;
9129 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9130 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9131 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9132 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9133 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9134 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9135 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9136 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9138 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9140 int_n_trees
[i
].signed_type
= make_signed_type (int_n_data
[i
].bitsize
);
9141 int_n_trees
[i
].unsigned_type
= make_unsigned_type (int_n_data
[i
].bitsize
);
9143 if (int_n_enabled_p
[i
])
9145 integer_types
[itk_intN_0
+ i
* 2] = int_n_trees
[i
].signed_type
;
9146 integer_types
[itk_unsigned_intN_0
+ i
* 2] = int_n_trees
[i
].unsigned_type
;
9150 /* Define a boolean type. This type only represents boolean values but
9151 may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9152 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9153 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9154 TYPE_PRECISION (boolean_type_node
) = 1;
9155 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9157 /* Define what type to use for size_t. */
9158 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
9159 size_type_node
= unsigned_type_node
;
9160 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
9161 size_type_node
= long_unsigned_type_node
;
9162 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
9163 size_type_node
= long_long_unsigned_type_node
;
9164 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
9165 size_type_node
= short_unsigned_type_node
;
9170 size_type_node
= NULL_TREE
;
9171 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9172 if (int_n_enabled_p
[i
])
9174 char name
[50], altname
[50];
9175 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
9176 sprintf (altname
, "__int%d__ unsigned", int_n_data
[i
].bitsize
);
9178 if (strcmp (name
, SIZE_TYPE
) == 0
9179 || strcmp (altname
, SIZE_TYPE
) == 0)
9181 size_type_node
= int_n_trees
[i
].unsigned_type
;
9184 if (size_type_node
== NULL_TREE
)
9188 /* Define what type to use for ptrdiff_t. */
9189 if (strcmp (PTRDIFF_TYPE
, "int") == 0)
9190 ptrdiff_type_node
= integer_type_node
;
9191 else if (strcmp (PTRDIFF_TYPE
, "long int") == 0)
9192 ptrdiff_type_node
= long_integer_type_node
;
9193 else if (strcmp (PTRDIFF_TYPE
, "long long int") == 0)
9194 ptrdiff_type_node
= long_long_integer_type_node
;
9195 else if (strcmp (PTRDIFF_TYPE
, "short int") == 0)
9196 ptrdiff_type_node
= short_integer_type_node
;
9199 ptrdiff_type_node
= NULL_TREE
;
9200 for (int i
= 0; i
< NUM_INT_N_ENTS
; i
++)
9201 if (int_n_enabled_p
[i
])
9203 char name
[50], altname
[50];
9204 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
9205 sprintf (altname
, "__int%d__", int_n_data
[i
].bitsize
);
9207 if (strcmp (name
, PTRDIFF_TYPE
) == 0
9208 || strcmp (altname
, PTRDIFF_TYPE
) == 0)
9209 ptrdiff_type_node
= int_n_trees
[i
].signed_type
;
9211 if (ptrdiff_type_node
== NULL_TREE
)
9215 /* Fill in the rest of the sized types. Reuse existing type nodes
9217 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9218 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9219 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9220 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9221 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9223 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9224 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9225 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9226 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9227 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9229 /* Don't call build_qualified type for atomics. That routine does
9230 special processing for atomics, and until they are initialized
9231 it's better not to make that call.
9233 Check to see if there is a target override for atomic types. */
9235 atomicQI_type_node
= build_atomic_base (unsigned_intQI_type_node
,
9236 targetm
.atomic_align_for_mode (QImode
));
9237 atomicHI_type_node
= build_atomic_base (unsigned_intHI_type_node
,
9238 targetm
.atomic_align_for_mode (HImode
));
9239 atomicSI_type_node
= build_atomic_base (unsigned_intSI_type_node
,
9240 targetm
.atomic_align_for_mode (SImode
));
9241 atomicDI_type_node
= build_atomic_base (unsigned_intDI_type_node
,
9242 targetm
.atomic_align_for_mode (DImode
));
9243 atomicTI_type_node
= build_atomic_base (unsigned_intTI_type_node
,
9244 targetm
.atomic_align_for_mode (TImode
));
9246 access_public_node
= get_identifier ("public");
9247 access_protected_node
= get_identifier ("protected");
9248 access_private_node
= get_identifier ("private");
9250 /* Define these next since types below may used them. */
9251 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9252 integer_one_node
= build_int_cst (integer_type_node
, 1);
9253 integer_three_node
= build_int_cst (integer_type_node
, 3);
9254 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9256 size_zero_node
= size_int (0);
9257 size_one_node
= size_int (1);
9258 bitsize_zero_node
= bitsize_int (0);
9259 bitsize_one_node
= bitsize_int (1);
9260 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9262 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9263 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9265 void_type_node
= make_node (VOID_TYPE
);
9266 layout_type (void_type_node
);
9268 /* We are not going to have real types in C with less than byte alignment,
9269 so we might as well not have any types that claim to have it. */
9270 SET_TYPE_ALIGN (void_type_node
, BITS_PER_UNIT
);
9271 TYPE_USER_ALIGN (void_type_node
) = 0;
9273 void_node
= make_node (VOID_CST
);
9274 TREE_TYPE (void_node
) = void_type_node
;
9276 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9277 layout_type (TREE_TYPE (null_pointer_node
));
9279 ptr_type_node
= build_pointer_type (void_type_node
);
9281 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9282 for (unsigned i
= 0;
9283 i
< sizeof (builtin_structptr_types
) / sizeof (builtin_structptr_type
);
9285 builtin_structptr_types
[i
].node
= builtin_structptr_types
[i
].base
;
9287 pointer_sized_int_node
= build_nonstandard_integer_type (POINTER_SIZE
, 1);
9289 float_type_node
= make_node (REAL_TYPE
);
9290 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9291 layout_type (float_type_node
);
9293 double_type_node
= make_node (REAL_TYPE
);
9294 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9295 layout_type (double_type_node
);
9297 long_double_type_node
= make_node (REAL_TYPE
);
9298 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9299 layout_type (long_double_type_node
);
9301 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
9303 int n
= floatn_nx_types
[i
].n
;
9304 bool extended
= floatn_nx_types
[i
].extended
;
9305 scalar_float_mode mode
;
9306 if (!targetm
.floatn_mode (n
, extended
).exists (&mode
))
9308 int precision
= GET_MODE_PRECISION (mode
);
9309 /* Work around the rs6000 KFmode having precision 113 not
9311 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
9312 gcc_assert (fmt
->b
== 2 && fmt
->emin
+ fmt
->emax
== 3);
9313 int min_precision
= fmt
->p
+ ceil_log2 (fmt
->emax
- fmt
->emin
);
9315 gcc_assert (min_precision
== n
);
9316 if (precision
< min_precision
)
9317 precision
= min_precision
;
9318 FLOATN_NX_TYPE_NODE (i
) = make_node (REAL_TYPE
);
9319 TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i
)) = precision
;
9320 layout_type (FLOATN_NX_TYPE_NODE (i
));
9321 SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i
), mode
);
9324 float_ptr_type_node
= build_pointer_type (float_type_node
);
9325 double_ptr_type_node
= build_pointer_type (double_type_node
);
9326 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9327 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9329 /* Fixed size integer types. */
9330 uint16_type_node
= make_or_reuse_type (16, 1);
9331 uint32_type_node
= make_or_reuse_type (32, 1);
9332 uint64_type_node
= make_or_reuse_type (64, 1);
9333 if (targetm
.scalar_mode_supported_p (TImode
))
9334 uint128_type_node
= make_or_reuse_type (128, 1);
9336 /* Decimal float types. */
9337 if (targetm
.decimal_float_supported_p ())
9339 dfloat32_type_node
= make_node (REAL_TYPE
);
9340 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9341 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9342 layout_type (dfloat32_type_node
);
9344 dfloat64_type_node
= make_node (REAL_TYPE
);
9345 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9346 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9347 layout_type (dfloat64_type_node
);
9349 dfloat128_type_node
= make_node (REAL_TYPE
);
9350 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9351 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9352 layout_type (dfloat128_type_node
);
9355 complex_integer_type_node
= build_complex_type (integer_type_node
, true);
9356 complex_float_type_node
= build_complex_type (float_type_node
, true);
9357 complex_double_type_node
= build_complex_type (double_type_node
, true);
9358 complex_long_double_type_node
= build_complex_type (long_double_type_node
,
9361 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
9363 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
9364 COMPLEX_FLOATN_NX_TYPE_NODE (i
)
9365 = build_complex_type (FLOATN_NX_TYPE_NODE (i
));
9368 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9369 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9370 sat_ ## KIND ## _type_node = \
9371 make_sat_signed_ ## KIND ## _type (SIZE); \
9372 sat_unsigned_ ## KIND ## _type_node = \
9373 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9374 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9375 unsigned_ ## KIND ## _type_node = \
9376 make_unsigned_ ## KIND ## _type (SIZE);
9378 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9379 sat_ ## WIDTH ## KIND ## _type_node = \
9380 make_sat_signed_ ## KIND ## _type (SIZE); \
9381 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9382 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9383 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9384 unsigned_ ## WIDTH ## KIND ## _type_node = \
9385 make_unsigned_ ## KIND ## _type (SIZE);
9387 /* Make fixed-point type nodes based on four different widths. */
9388 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9389 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9390 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9391 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9392 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9394 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9395 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9396 NAME ## _type_node = \
9397 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9398 u ## NAME ## _type_node = \
9399 make_or_reuse_unsigned_ ## KIND ## _type \
9400 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9401 sat_ ## NAME ## _type_node = \
9402 make_or_reuse_sat_signed_ ## KIND ## _type \
9403 (GET_MODE_BITSIZE (MODE ## mode)); \
9404 sat_u ## NAME ## _type_node = \
9405 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9406 (GET_MODE_BITSIZE (U ## MODE ## mode));
9408 /* Fixed-point type and mode nodes. */
9409 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9410 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9411 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9412 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9413 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9414 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9415 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9416 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9417 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9418 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9419 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9422 tree t
= targetm
.build_builtin_va_list ();
9424 /* Many back-ends define record types without setting TYPE_NAME.
9425 If we copied the record type here, we'd keep the original
9426 record type without a name. This breaks name mangling. So,
9427 don't copy record types and let c_common_nodes_and_builtins()
9428 declare the type to be __builtin_va_list. */
9429 if (TREE_CODE (t
) != RECORD_TYPE
)
9430 t
= build_variant_type_copy (t
);
9432 va_list_type_node
= t
;
9435 /* SCEV analyzer global shared trees. */
9436 chrec_dont_know
= make_node (SCEV_NOT_KNOWN
);
9437 TREE_TYPE (chrec_dont_know
) = void_type_node
;
9438 chrec_known
= make_node (SCEV_KNOWN
);
9439 TREE_TYPE (chrec_known
) = void_type_node
;
9442 /* Modify DECL for given flags.
9443 TM_PURE attribute is set only on types, so the function will modify
9444 DECL's type when ECF_TM_PURE is used. */
9447 set_call_expr_flags (tree decl
, int flags
)
9449 if (flags
& ECF_NOTHROW
)
9450 TREE_NOTHROW (decl
) = 1;
9451 if (flags
& ECF_CONST
)
9452 TREE_READONLY (decl
) = 1;
9453 if (flags
& ECF_PURE
)
9454 DECL_PURE_P (decl
) = 1;
9455 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
9456 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9457 if (flags
& ECF_NOVOPS
)
9458 DECL_IS_NOVOPS (decl
) = 1;
9459 if (flags
& ECF_NORETURN
)
9460 TREE_THIS_VOLATILE (decl
) = 1;
9461 if (flags
& ECF_MALLOC
)
9462 DECL_IS_MALLOC (decl
) = 1;
9463 if (flags
& ECF_RETURNS_TWICE
)
9464 DECL_IS_RETURNS_TWICE (decl
) = 1;
9465 if (flags
& ECF_LEAF
)
9466 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9467 NULL
, DECL_ATTRIBUTES (decl
));
9468 if (flags
& ECF_COLD
)
9469 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("cold"),
9470 NULL
, DECL_ATTRIBUTES (decl
));
9471 if (flags
& ECF_RET1
)
9472 DECL_ATTRIBUTES (decl
)
9473 = tree_cons (get_identifier ("fn spec"),
9474 build_tree_list (NULL_TREE
, build_string (2, "1 ")),
9475 DECL_ATTRIBUTES (decl
));
9476 if ((flags
& ECF_TM_PURE
) && flag_tm
)
9477 apply_tm_attr (decl
, get_identifier ("transaction_pure"));
9478 /* Looping const or pure is implied by noreturn.
9479 There is currently no way to declare looping const or looping pure alone. */
9480 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
9481 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
9485 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9488 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9489 const char *library_name
, int ecf_flags
)
9493 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9494 library_name
, NULL_TREE
);
9495 set_call_expr_flags (decl
, ecf_flags
);
9497 set_builtin_decl (code
, decl
, true);
9500 /* Call this function after instantiating all builtins that the language
9501 front end cares about. This will build the rest of the builtins
9502 and internal functions that are relied upon by the tree optimizers and
9506 build_common_builtin_nodes (void)
9511 if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING
))
9513 ftype
= build_function_type_list (void_type_node
,
9518 local_define_builtin ("__builtin_clear_padding", ftype
,
9519 BUILT_IN_CLEAR_PADDING
,
9520 "__builtin_clear_padding",
9521 ECF_LEAF
| ECF_NOTHROW
);
9524 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
)
9525 || !builtin_decl_explicit_p (BUILT_IN_ABORT
))
9527 ftype
= build_function_type (void_type_node
, void_list_node
);
9528 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
9529 local_define_builtin ("__builtin_unreachable", ftype
,
9530 BUILT_IN_UNREACHABLE
,
9531 "__builtin_unreachable",
9532 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
9533 | ECF_CONST
| ECF_COLD
);
9534 if (!builtin_decl_explicit_p (BUILT_IN_ABORT
))
9535 local_define_builtin ("__builtin_abort", ftype
, BUILT_IN_ABORT
,
9537 ECF_LEAF
| ECF_NORETURN
| ECF_CONST
| ECF_COLD
);
9540 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
9541 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9543 ftype
= build_function_type_list (ptr_type_node
,
9544 ptr_type_node
, const_ptr_type_node
,
9545 size_type_node
, NULL_TREE
);
9547 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
9548 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9549 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9550 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9551 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9552 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9555 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
9557 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9558 const_ptr_type_node
, size_type_node
,
9560 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9561 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9564 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
9566 ftype
= build_function_type_list (ptr_type_node
,
9567 ptr_type_node
, integer_type_node
,
9568 size_type_node
, NULL_TREE
);
9569 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9570 "memset", ECF_NOTHROW
| ECF_LEAF
);
9573 /* If we're checking the stack, `alloca' can throw. */
9574 const int alloca_flags
9575 = ECF_MALLOC
| ECF_LEAF
| (flag_stack_check
? 0 : ECF_NOTHROW
);
9577 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
9579 ftype
= build_function_type_list (ptr_type_node
,
9580 size_type_node
, NULL_TREE
);
9581 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
9582 "alloca", alloca_flags
);
9585 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
9586 size_type_node
, NULL_TREE
);
9587 local_define_builtin ("__builtin_alloca_with_align", ftype
,
9588 BUILT_IN_ALLOCA_WITH_ALIGN
,
9589 "__builtin_alloca_with_align",
9592 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
9593 size_type_node
, size_type_node
, NULL_TREE
);
9594 local_define_builtin ("__builtin_alloca_with_align_and_max", ftype
,
9595 BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX
,
9596 "__builtin_alloca_with_align_and_max",
9599 ftype
= build_function_type_list (void_type_node
,
9600 ptr_type_node
, ptr_type_node
,
9601 ptr_type_node
, NULL_TREE
);
9602 local_define_builtin ("__builtin_init_trampoline", ftype
,
9603 BUILT_IN_INIT_TRAMPOLINE
,
9604 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
9605 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
9606 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
9607 "__builtin_init_heap_trampoline",
9608 ECF_NOTHROW
| ECF_LEAF
);
9609 local_define_builtin ("__builtin_init_descriptor", ftype
,
9610 BUILT_IN_INIT_DESCRIPTOR
,
9611 "__builtin_init_descriptor", ECF_NOTHROW
| ECF_LEAF
);
9613 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9614 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
9615 BUILT_IN_ADJUST_TRAMPOLINE
,
9616 "__builtin_adjust_trampoline",
9617 ECF_CONST
| ECF_NOTHROW
);
9618 local_define_builtin ("__builtin_adjust_descriptor", ftype
,
9619 BUILT_IN_ADJUST_DESCRIPTOR
,
9620 "__builtin_adjust_descriptor",
9621 ECF_CONST
| ECF_NOTHROW
);
9623 ftype
= build_function_type_list (void_type_node
,
9624 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9625 if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE
))
9626 local_define_builtin ("__builtin___clear_cache", ftype
,
9627 BUILT_IN_CLEAR_CACHE
,
9631 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
9632 BUILT_IN_NONLOCAL_GOTO
,
9633 "__builtin_nonlocal_goto",
9634 ECF_NORETURN
| ECF_NOTHROW
);
9636 ftype
= build_function_type_list (void_type_node
,
9637 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9638 local_define_builtin ("__builtin_setjmp_setup", ftype
,
9639 BUILT_IN_SETJMP_SETUP
,
9640 "__builtin_setjmp_setup", ECF_NOTHROW
);
9642 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9643 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
9644 BUILT_IN_SETJMP_RECEIVER
,
9645 "__builtin_setjmp_receiver", ECF_NOTHROW
| ECF_LEAF
);
9647 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
9648 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
9649 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
9651 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9652 local_define_builtin ("__builtin_stack_restore", ftype
,
9653 BUILT_IN_STACK_RESTORE
,
9654 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
9656 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9657 const_ptr_type_node
, size_type_node
,
9659 local_define_builtin ("__builtin_memcmp_eq", ftype
, BUILT_IN_MEMCMP_EQ
,
9660 "__builtin_memcmp_eq",
9661 ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9663 local_define_builtin ("__builtin_strncmp_eq", ftype
, BUILT_IN_STRNCMP_EQ
,
9664 "__builtin_strncmp_eq",
9665 ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9667 local_define_builtin ("__builtin_strcmp_eq", ftype
, BUILT_IN_STRCMP_EQ
,
9668 "__builtin_strcmp_eq",
9669 ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9671 /* If there's a possibility that we might use the ARM EABI, build the
9672 alternate __cxa_end_cleanup node used to resume from C++. */
9673 if (targetm
.arm_eabi_unwinder
)
9675 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9676 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
9677 BUILT_IN_CXA_END_CLEANUP
,
9678 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
9681 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9682 local_define_builtin ("__builtin_unwind_resume", ftype
,
9683 BUILT_IN_UNWIND_RESUME
,
9684 ((targetm_common
.except_unwind_info (&global_options
)
9686 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9689 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
9691 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
9693 local_define_builtin ("__builtin_return_address", ftype
,
9694 BUILT_IN_RETURN_ADDRESS
,
9695 "__builtin_return_address",
9699 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
9700 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9702 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
9703 ptr_type_node
, NULL_TREE
);
9704 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
9705 local_define_builtin ("__cyg_profile_func_enter", ftype
,
9706 BUILT_IN_PROFILE_FUNC_ENTER
,
9707 "__cyg_profile_func_enter", 0);
9708 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9709 local_define_builtin ("__cyg_profile_func_exit", ftype
,
9710 BUILT_IN_PROFILE_FUNC_EXIT
,
9711 "__cyg_profile_func_exit", 0);
9714 /* The exception object and filter values from the runtime. The argument
9715 must be zero before exception lowering, i.e. from the front end. After
9716 exception lowering, it will be the region number for the exception
9717 landing pad. These functions are PURE instead of CONST to prevent
9718 them from being hoisted past the exception edge that will initialize
9719 its value in the landing pad. */
9720 ftype
= build_function_type_list (ptr_type_node
,
9721 integer_type_node
, NULL_TREE
);
9722 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
9723 /* Only use TM_PURE if we have TM language support. */
9724 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
9725 ecf_flags
|= ECF_TM_PURE
;
9726 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
9727 "__builtin_eh_pointer", ecf_flags
);
9729 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
9730 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
9731 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
9732 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9734 ftype
= build_function_type_list (void_type_node
,
9735 integer_type_node
, integer_type_node
,
9737 local_define_builtin ("__builtin_eh_copy_values", ftype
,
9738 BUILT_IN_EH_COPY_VALUES
,
9739 "__builtin_eh_copy_values", ECF_NOTHROW
);
9741 /* Complex multiplication and division. These are handled as builtins
9742 rather than optabs because emit_library_call_value doesn't support
9743 complex. Further, we can do slightly better with folding these
9744 beasties if the real and complex parts of the arguments are separate. */
9748 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
9750 char mode_name_buf
[4], *q
;
9752 enum built_in_function mcode
, dcode
;
9753 tree type
, inner_type
;
9754 const char *prefix
= "__";
9756 if (targetm
.libfunc_gnu_prefix
)
9759 type
= lang_hooks
.types
.type_for_mode ((machine_mode
) mode
, 0);
9762 inner_type
= TREE_TYPE (type
);
9764 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
9765 inner_type
, inner_type
, NULL_TREE
);
9767 mcode
= ((enum built_in_function
)
9768 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9769 dcode
= ((enum built_in_function
)
9770 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9772 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
9776 /* For -ftrapping-math these should throw from a former
9777 -fnon-call-exception stmt. */
9778 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
9780 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
9781 built_in_names
[mcode
],
9782 ECF_CONST
| ECF_LEAF
);
9784 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
9786 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
9787 built_in_names
[dcode
],
9788 ECF_CONST
| ECF_LEAF
);
9792 init_internal_fns ();
9795 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
9798 If we requested a pointer to a vector, build up the pointers that
9799 we stripped off while looking for the inner type. Similarly for
9800 return values from functions.
9802 The argument TYPE is the top of the chain, and BOTTOM is the
9803 new type which we will point to. */
9806 reconstruct_complex_type (tree type
, tree bottom
)
9810 if (TREE_CODE (type
) == POINTER_TYPE
)
9812 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9813 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
9814 TYPE_REF_CAN_ALIAS_ALL (type
));
9816 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
9818 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9819 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
9820 TYPE_REF_CAN_ALIAS_ALL (type
));
9822 else if (TREE_CODE (type
) == ARRAY_TYPE
)
9824 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9825 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
9827 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9829 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9830 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
9832 else if (TREE_CODE (type
) == METHOD_TYPE
)
9834 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9835 /* The build_method_type_directly() routine prepends 'this' to argument list,
9836 so we must compensate by getting rid of it. */
9838 = build_method_type_directly
9839 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
9841 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
9843 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9845 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9846 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
9851 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
9855 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
9858 build_vector_type_for_mode (tree innertype
, machine_mode mode
)
9861 unsigned int bitsize
;
9863 switch (GET_MODE_CLASS (mode
))
9865 case MODE_VECTOR_BOOL
:
9866 case MODE_VECTOR_INT
:
9867 case MODE_VECTOR_FLOAT
:
9868 case MODE_VECTOR_FRACT
:
9869 case MODE_VECTOR_UFRACT
:
9870 case MODE_VECTOR_ACCUM
:
9871 case MODE_VECTOR_UACCUM
:
9872 nunits
= GET_MODE_NUNITS (mode
);
9876 /* Check that there are no leftover bits. */
9877 bitsize
= GET_MODE_BITSIZE (as_a
<scalar_int_mode
> (mode
));
9878 gcc_assert (bitsize
% TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
9879 nunits
= bitsize
/ TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
9886 return make_vector_type (innertype
, nunits
, mode
);
9889 /* Similarly, but takes the inner type and number of units, which must be
9893 build_vector_type (tree innertype
, poly_int64 nunits
)
9895 return make_vector_type (innertype
, nunits
, VOIDmode
);
9898 /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
9901 build_truth_vector_type_for_mode (poly_uint64 nunits
, machine_mode mask_mode
)
9903 gcc_assert (mask_mode
!= BLKmode
);
9905 unsigned HOST_WIDE_INT esize
;
9906 if (VECTOR_MODE_P (mask_mode
))
9908 poly_uint64 vsize
= GET_MODE_BITSIZE (mask_mode
);
9909 esize
= vector_element_size (vsize
, nunits
);
9914 tree bool_type
= build_nonstandard_boolean_type (esize
);
9916 return make_vector_type (bool_type
, nunits
, mask_mode
);
9919 /* Build a vector type that holds one boolean result for each element of
9920 vector type VECTYPE. The public interface for this operation is
9924 build_truth_vector_type_for (tree vectype
)
9926 machine_mode vector_mode
= TYPE_MODE (vectype
);
9927 poly_uint64 nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
9929 machine_mode mask_mode
;
9930 if (VECTOR_MODE_P (vector_mode
)
9931 && targetm
.vectorize
.get_mask_mode (vector_mode
).exists (&mask_mode
))
9932 return build_truth_vector_type_for_mode (nunits
, mask_mode
);
9934 poly_uint64 vsize
= tree_to_poly_uint64 (TYPE_SIZE (vectype
));
9935 unsigned HOST_WIDE_INT esize
= vector_element_size (vsize
, nunits
);
9936 tree bool_type
= build_nonstandard_boolean_type (esize
);
9938 return make_vector_type (bool_type
, nunits
, VOIDmode
);
9941 /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
9945 build_opaque_vector_type (tree innertype
, poly_int64 nunits
)
9947 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
9949 /* We always build the non-opaque variant before the opaque one,
9950 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
9951 cand
= TYPE_NEXT_VARIANT (t
);
9953 && TYPE_VECTOR_OPAQUE (cand
)
9954 && check_qualified_type (cand
, t
, TYPE_QUALS (t
)))
9956 /* Othewise build a variant type and make sure to queue it after
9957 the non-opaque type. */
9958 cand
= build_distinct_type_copy (t
);
9959 TYPE_VECTOR_OPAQUE (cand
) = true;
9960 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
9961 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
9962 TYPE_NEXT_VARIANT (t
) = cand
;
9963 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
9967 /* Return the value of element I of VECTOR_CST T as a wide_int. */
9969 static poly_wide_int
9970 vector_cst_int_elt (const_tree t
, unsigned int i
)
9972 /* First handle elements that are directly encoded. */
9973 unsigned int encoded_nelts
= vector_cst_encoded_nelts (t
);
9974 if (i
< encoded_nelts
)
9975 return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t
, i
));
9977 /* Identify the pattern that contains element I and work out the index of
9978 the last encoded element for that pattern. */
9979 unsigned int npatterns
= VECTOR_CST_NPATTERNS (t
);
9980 unsigned int pattern
= i
% npatterns
;
9981 unsigned int count
= i
/ npatterns
;
9982 unsigned int final_i
= encoded_nelts
- npatterns
+ pattern
;
9984 /* If there are no steps, the final encoded value is the right one. */
9985 if (!VECTOR_CST_STEPPED_P (t
))
9986 return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t
, final_i
));
9988 /* Otherwise work out the value from the last two encoded elements. */
9989 tree v1
= VECTOR_CST_ENCODED_ELT (t
, final_i
- npatterns
);
9990 tree v2
= VECTOR_CST_ENCODED_ELT (t
, final_i
);
9991 poly_wide_int diff
= wi::to_poly_wide (v2
) - wi::to_poly_wide (v1
);
9992 return wi::to_poly_wide (v2
) + (count
- 2) * diff
;
9995 /* Return the value of element I of VECTOR_CST T. */
9998 vector_cst_elt (const_tree t
, unsigned int i
)
10000 /* First handle elements that are directly encoded. */
10001 unsigned int encoded_nelts
= vector_cst_encoded_nelts (t
);
10002 if (i
< encoded_nelts
)
10003 return VECTOR_CST_ENCODED_ELT (t
, i
);
10005 /* If there are no steps, the final encoded value is the right one. */
10006 if (!VECTOR_CST_STEPPED_P (t
))
10008 /* Identify the pattern that contains element I and work out the index of
10009 the last encoded element for that pattern. */
10010 unsigned int npatterns
= VECTOR_CST_NPATTERNS (t
);
10011 unsigned int pattern
= i
% npatterns
;
10012 unsigned int final_i
= encoded_nelts
- npatterns
+ pattern
;
10013 return VECTOR_CST_ENCODED_ELT (t
, final_i
);
10016 /* Otherwise work out the value from the last two encoded elements. */
10017 return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t
)),
10018 vector_cst_int_elt (t
, i
));
10021 /* Given an initializer INIT, return TRUE if INIT is zero or some
10022 aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10023 null, set *NONZERO if and only if INIT is known not to be all
10024 zeros. The combination of return value of false and *NONZERO
10025 false implies that INIT may but need not be all zeros. Other
10026 combinations indicate definitive answers. */
10029 initializer_zerop (const_tree init
, bool *nonzero
/* = NULL */)
10035 /* Conservatively clear NONZERO and set it only if INIT is definitely
10041 unsigned HOST_WIDE_INT off
= 0;
10043 switch (TREE_CODE (init
))
10046 if (integer_zerop (init
))
10053 /* ??? Note that this is not correct for C4X float formats. There,
10054 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10055 negative exponent. */
10056 if (real_zerop (init
)
10057 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
)))
10064 if (fixed_zerop (init
))
10071 if (integer_zerop (init
)
10072 || (real_zerop (init
)
10073 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10074 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
)))))
10081 if (VECTOR_CST_NPATTERNS (init
) == 1
10082 && VECTOR_CST_DUPLICATE_P (init
)
10083 && initializer_zerop (VECTOR_CST_ENCODED_ELT (init
, 0)))
10091 if (TREE_CLOBBER_P (init
))
10094 unsigned HOST_WIDE_INT idx
;
10097 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10098 if (!initializer_zerop (elt
, nonzero
))
10106 tree arg
= TREE_OPERAND (init
, 0);
10107 if (TREE_CODE (arg
) != ADDR_EXPR
)
10109 tree offset
= TREE_OPERAND (init
, 1);
10110 if (TREE_CODE (offset
) != INTEGER_CST
10111 || !tree_fits_uhwi_p (offset
))
10113 off
= tree_to_uhwi (offset
);
10116 arg
= TREE_OPERAND (arg
, 0);
10117 if (TREE_CODE (arg
) != STRING_CST
)
10121 /* Fall through. */
10125 gcc_assert (off
<= INT_MAX
);
10128 int n
= TREE_STRING_LENGTH (init
);
10132 /* We need to loop through all elements to handle cases like
10133 "\0" and "\0foobar". */
10134 for (i
= 0; i
< n
; ++i
)
10135 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10149 /* Return true if EXPR is an initializer expression in which every element
10150 is a constant that is numerically equal to 0 or 1. The elements do not
10151 need to be equal to each other. */
10154 initializer_each_zero_or_onep (const_tree expr
)
10156 STRIP_ANY_LOCATION_WRAPPER (expr
);
10158 switch (TREE_CODE (expr
))
10161 return integer_zerop (expr
) || integer_onep (expr
);
10164 return real_zerop (expr
) || real_onep (expr
);
10168 unsigned HOST_WIDE_INT nelts
= vector_cst_encoded_nelts (expr
);
10169 if (VECTOR_CST_STEPPED_P (expr
)
10170 && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr
)).is_constant (&nelts
))
10173 for (unsigned int i
= 0; i
< nelts
; ++i
)
10175 tree elt
= vector_cst_elt (expr
, i
);
10176 if (!initializer_each_zero_or_onep (elt
))
10188 /* Check if vector VEC consists of all the equal elements and
10189 that the number of elements corresponds to the type of VEC.
10190 The function returns first element of the vector
10191 or NULL_TREE if the vector is not uniform. */
10193 uniform_vector_p (const_tree vec
)
10196 unsigned HOST_WIDE_INT i
, nelts
;
10198 if (vec
== NULL_TREE
)
10201 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10203 if (TREE_CODE (vec
) == VEC_DUPLICATE_EXPR
)
10204 return TREE_OPERAND (vec
, 0);
10206 else if (TREE_CODE (vec
) == VECTOR_CST
)
10208 if (VECTOR_CST_NPATTERNS (vec
) == 1 && VECTOR_CST_DUPLICATE_P (vec
))
10209 return VECTOR_CST_ENCODED_ELT (vec
, 0);
10213 else if (TREE_CODE (vec
) == CONSTRUCTOR
10214 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)).is_constant (&nelts
))
10216 first
= error_mark_node
;
10218 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10225 if (!operand_equal_p (first
, t
, 0))
10237 /* If the argument is INTEGER_CST, return it. If the argument is vector
10238 with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10240 Look through location wrappers. */
10243 uniform_integer_cst_p (tree t
)
10245 STRIP_ANY_LOCATION_WRAPPER (t
);
10247 if (TREE_CODE (t
) == INTEGER_CST
)
10250 if (VECTOR_TYPE_P (TREE_TYPE (t
)))
10252 t
= uniform_vector_p (t
);
10253 if (t
&& TREE_CODE (t
) == INTEGER_CST
)
10260 /* Checks to see if T is a constant or a constant vector and if each element E
10261 adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10264 bitmask_inv_cst_vector_p (tree t
)
10267 tree_code code
= TREE_CODE (t
);
10268 tree type
= TREE_TYPE (t
);
10270 if (!INTEGRAL_TYPE_P (type
)
10271 && !VECTOR_INTEGER_TYPE_P (type
))
10274 unsigned HOST_WIDE_INT nelts
= 1;
10276 unsigned int idx
= 0;
10277 bool uniform
= uniform_integer_cst_p (t
);
10278 tree newtype
= unsigned_type_for (type
);
10279 tree_vector_builder builder
;
10280 if (code
== INTEGER_CST
)
10284 if (!VECTOR_CST_NELTS (t
).is_constant (&nelts
))
10287 cst
= vector_cst_elt (t
, 0);
10288 builder
.new_vector (newtype
, nelts
, 1);
10291 tree ty
= unsigned_type_for (TREE_TYPE (cst
));
10296 cst
= vector_cst_elt (t
, idx
);
10297 wide_int icst
= wi::to_wide (cst
);
10298 wide_int inv
= wi::bit_not (icst
);
10299 icst
= wi::add (1, inv
);
10300 if (wi::popcount (icst
) != 1)
10303 tree newcst
= wide_int_to_tree (ty
, inv
);
10306 return build_uniform_cst (newtype
, newcst
);
10308 builder
.quick_push (newcst
);
10310 while (++idx
< nelts
);
10312 return builder
.build ();
10315 /* If VECTOR_CST T has a single nonzero element, return the index of that
10316 element, otherwise return -1. */
10319 single_nonzero_element (const_tree t
)
10321 unsigned HOST_WIDE_INT nelts
;
10322 unsigned int repeat_nelts
;
10323 if (VECTOR_CST_NELTS (t
).is_constant (&nelts
))
10324 repeat_nelts
= nelts
;
10325 else if (VECTOR_CST_NELTS_PER_PATTERN (t
) == 2)
10327 nelts
= vector_cst_encoded_nelts (t
);
10328 repeat_nelts
= VECTOR_CST_NPATTERNS (t
);
10334 for (unsigned int i
= 0; i
< nelts
; ++i
)
10336 tree elt
= vector_cst_elt (t
, i
);
10337 if (!integer_zerop (elt
) && !real_zerop (elt
))
10339 if (res
>= 0 || i
>= repeat_nelts
)
10347 /* Build an empty statement at location LOC. */
10350 build_empty_stmt (location_t loc
)
10352 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10353 SET_EXPR_LOCATION (t
, loc
);
10358 /* Build an OMP clause with code CODE. LOC is the location of the
10362 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10367 length
= omp_clause_num_ops
[code
];
10368 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10370 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10372 t
= (tree
) ggc_internal_alloc (size
);
10373 memset (t
, 0, size
);
10374 TREE_SET_CODE (t
, OMP_CLAUSE
);
10375 OMP_CLAUSE_SET_CODE (t
, code
);
10376 OMP_CLAUSE_LOCATION (t
) = loc
;
10381 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10382 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10383 Except for the CODE and operand count field, other storage for the
10384 object is initialized to zeros. */
10387 build_vl_exp (enum tree_code code
, int len MEM_STAT_DECL
)
10390 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10392 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10393 gcc_assert (len
>= 1);
10395 record_node_allocation_statistics (code
, length
);
10397 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10399 TREE_SET_CODE (t
, code
);
10401 /* Can't use TREE_OPERAND to store the length because if checking is
10402 enabled, it will try to check the length before we store it. :-P */
10403 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10408 /* Helper function for build_call_* functions; build a CALL_EXPR with
10409 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10410 the argument slots. */
10413 build_call_1 (tree return_type
, tree fn
, int nargs
)
10417 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10418 TREE_TYPE (t
) = return_type
;
10419 CALL_EXPR_FN (t
) = fn
;
10420 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10425 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10426 FN and a null static chain slot. NARGS is the number of call arguments
10427 which are specified as "..." arguments. */
10430 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10434 va_start (args
, nargs
);
10435 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10440 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10441 FN and a null static chain slot. NARGS is the number of call arguments
10442 which are specified as a va_list ARGS. */
10445 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10450 t
= build_call_1 (return_type
, fn
, nargs
);
10451 for (i
= 0; i
< nargs
; i
++)
10452 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10453 process_call_operands (t
);
10457 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10458 FN and a null static chain slot. NARGS is the number of call arguments
10459 which are specified as a tree array ARGS. */
10462 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10463 int nargs
, const tree
*args
)
10468 t
= build_call_1 (return_type
, fn
, nargs
);
10469 for (i
= 0; i
< nargs
; i
++)
10470 CALL_EXPR_ARG (t
, i
) = args
[i
];
10471 process_call_operands (t
);
10472 SET_EXPR_LOCATION (t
, loc
);
10476 /* Like build_call_array, but takes a vec. */
10479 build_call_vec (tree return_type
, tree fn
, const vec
<tree
, va_gc
> *args
)
10484 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10485 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10486 CALL_EXPR_ARG (ret
, ix
) = t
;
10487 process_call_operands (ret
);
10491 /* Conveniently construct a function call expression. FNDECL names the
10492 function to be called and N arguments are passed in the array
10496 build_call_expr_loc_array (location_t loc
, tree fndecl
, int n
, tree
*argarray
)
10498 tree fntype
= TREE_TYPE (fndecl
);
10499 tree fn
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), fndecl
);
10501 return fold_build_call_array_loc (loc
, TREE_TYPE (fntype
), fn
, n
, argarray
);
10504 /* Conveniently construct a function call expression. FNDECL names the
10505 function to be called and the arguments are passed in the vector
10509 build_call_expr_loc_vec (location_t loc
, tree fndecl
, vec
<tree
, va_gc
> *vec
)
10511 return build_call_expr_loc_array (loc
, fndecl
, vec_safe_length (vec
),
10512 vec_safe_address (vec
));
10516 /* Conveniently construct a function call expression. FNDECL names the
10517 function to be called, N is the number of arguments, and the "..."
10518 parameters are the argument expressions. */
10521 build_call_expr_loc (location_t loc
, tree fndecl
, int n
, ...)
10524 tree
*argarray
= XALLOCAVEC (tree
, n
);
10528 for (i
= 0; i
< n
; i
++)
10529 argarray
[i
] = va_arg (ap
, tree
);
10531 return build_call_expr_loc_array (loc
, fndecl
, n
, argarray
);
10534 /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
10535 varargs macros aren't supported by all bootstrap compilers. */
10538 build_call_expr (tree fndecl
, int n
, ...)
10541 tree
*argarray
= XALLOCAVEC (tree
, n
);
10545 for (i
= 0; i
< n
; i
++)
10546 argarray
[i
] = va_arg (ap
, tree
);
10548 return build_call_expr_loc_array (UNKNOWN_LOCATION
, fndecl
, n
, argarray
);
10551 /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
10552 type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
10553 It will get gimplified later into an ordinary internal function. */
10556 build_call_expr_internal_loc_array (location_t loc
, internal_fn ifn
,
10557 tree type
, int n
, const tree
*args
)
10559 tree t
= build_call_1 (type
, NULL_TREE
, n
);
10560 for (int i
= 0; i
< n
; ++i
)
10561 CALL_EXPR_ARG (t
, i
) = args
[i
];
10562 SET_EXPR_LOCATION (t
, loc
);
10563 CALL_EXPR_IFN (t
) = ifn
;
10564 process_call_operands (t
);
10568 /* Build internal call expression. This is just like CALL_EXPR, except
10569 its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
10570 internal function. */
10573 build_call_expr_internal_loc (location_t loc
, enum internal_fn ifn
,
10574 tree type
, int n
, ...)
10577 tree
*argarray
= XALLOCAVEC (tree
, n
);
10581 for (i
= 0; i
< n
; i
++)
10582 argarray
[i
] = va_arg (ap
, tree
);
10584 return build_call_expr_internal_loc_array (loc
, ifn
, type
, n
, argarray
);
10587 /* Return a function call to FN, if the target is guaranteed to support it,
10590 N is the number of arguments, passed in the "...", and TYPE is the
10591 type of the return value. */
10594 maybe_build_call_expr_loc (location_t loc
, combined_fn fn
, tree type
,
10598 tree
*argarray
= XALLOCAVEC (tree
, n
);
10602 for (i
= 0; i
< n
; i
++)
10603 argarray
[i
] = va_arg (ap
, tree
);
10605 if (internal_fn_p (fn
))
10607 internal_fn ifn
= as_internal_fn (fn
);
10608 if (direct_internal_fn_p (ifn
))
10610 tree_pair types
= direct_internal_fn_types (ifn
, type
, argarray
);
10611 if (!direct_internal_fn_supported_p (ifn
, types
,
10612 OPTIMIZE_FOR_BOTH
))
10615 return build_call_expr_internal_loc_array (loc
, ifn
, type
, n
, argarray
);
10619 tree fndecl
= builtin_decl_implicit (as_builtin_fn (fn
));
10622 return build_call_expr_loc_array (loc
, fndecl
, n
, argarray
);
10626 /* Return a function call to the appropriate builtin alloca variant.
10628 SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
10629 alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
10630 bound for SIZE in case it is not a fixed value. */
10633 build_alloca_call_expr (tree size
, unsigned int align
, HOST_WIDE_INT max_size
)
10637 tree t
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX
);
10639 build_call_expr (t
, 3, size
, size_int (align
), size_int (max_size
));
10641 else if (align
> 0)
10643 tree t
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
10644 return build_call_expr (t
, 2, size
, size_int (align
));
10648 tree t
= builtin_decl_explicit (BUILT_IN_ALLOCA
);
10649 return build_call_expr (t
, 1, size
);
10653 /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
10654 if SIZE == -1) and return a tree node representing char* pointer to
10655 it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
10656 the STRING_CST value is the LEN bytes at STR (the representation
10657 of the string, which may be wide). Otherwise it's all zeros. */
10660 build_string_literal (unsigned len
, const char *str
/* = NULL */,
10661 tree eltype
/* = char_type_node */,
10662 unsigned HOST_WIDE_INT size
/* = -1 */)
10664 tree t
= build_string (len
, str
);
10665 /* Set the maximum valid index based on the string length or SIZE. */
10666 unsigned HOST_WIDE_INT maxidx
10667 = (size
== HOST_WIDE_INT_M1U
? len
: size
) - 1;
10669 tree index
= build_index_type (size_int (maxidx
));
10670 eltype
= build_type_variant (eltype
, 1, 0);
10671 tree type
= build_array_type (eltype
, index
);
10672 TREE_TYPE (t
) = type
;
10673 TREE_CONSTANT (t
) = 1;
10674 TREE_READONLY (t
) = 1;
10675 TREE_STATIC (t
) = 1;
10677 type
= build_pointer_type (eltype
);
10678 t
= build1 (ADDR_EXPR
, type
,
10679 build4 (ARRAY_REF
, eltype
,
10680 t
, integer_zero_node
, NULL_TREE
, NULL_TREE
));
10686 /* Return true if T (assumed to be a DECL) must be assigned a memory
10690 needs_to_live_in_memory (const_tree t
)
10692 return (TREE_ADDRESSABLE (t
)
10693 || is_global_var (t
)
10694 || (TREE_CODE (t
) == RESULT_DECL
10695 && !DECL_BY_REFERENCE (t
)
10696 && aggregate_value_p (t
, current_function_decl
)));
10699 /* Return value of a constant X and sign-extend it. */
10702 int_cst_value (const_tree x
)
10704 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10705 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
10707 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10708 gcc_assert (cst_and_fits_in_hwi (x
));
10710 if (bits
< HOST_BITS_PER_WIDE_INT
)
10712 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10714 val
|= HOST_WIDE_INT_M1U
<< (bits
- 1) << 1;
10716 val
&= ~(HOST_WIDE_INT_M1U
<< (bits
- 1) << 1);
10722 /* If TYPE is an integral or pointer type, return an integer type with
10723 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10724 if TYPE is already an integer type of signedness UNSIGNEDP.
10725 If TYPE is a floating-point type, return an integer type with the same
10726 bitsize and with the signedness given by UNSIGNEDP; this is useful
10727 when doing bit-level operations on a floating-point value. */
10730 signed_or_unsigned_type_for (int unsignedp
, tree type
)
10732 if (ANY_INTEGRAL_TYPE_P (type
) && TYPE_UNSIGNED (type
) == unsignedp
)
10735 if (TREE_CODE (type
) == VECTOR_TYPE
)
10737 tree inner
= TREE_TYPE (type
);
10738 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
10741 if (inner
== inner2
)
10743 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
10746 if (TREE_CODE (type
) == COMPLEX_TYPE
)
10748 tree inner
= TREE_TYPE (type
);
10749 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
10752 if (inner
== inner2
)
10754 return build_complex_type (inner2
);
10758 if (INTEGRAL_TYPE_P (type
)
10759 || POINTER_TYPE_P (type
)
10760 || TREE_CODE (type
) == OFFSET_TYPE
)
10761 bits
= TYPE_PRECISION (type
);
10762 else if (TREE_CODE (type
) == REAL_TYPE
)
10763 bits
= GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type
));
10767 return build_nonstandard_integer_type (bits
, unsignedp
);
10770 /* If TYPE is an integral or pointer type, return an integer type with
10771 the same precision which is unsigned, or itself if TYPE is already an
10772 unsigned integer type. If TYPE is a floating-point type, return an
10773 unsigned integer type with the same bitsize as TYPE. */
10776 unsigned_type_for (tree type
)
10778 return signed_or_unsigned_type_for (1, type
);
10781 /* If TYPE is an integral or pointer type, return an integer type with
10782 the same precision which is signed, or itself if TYPE is already a
10783 signed integer type. If TYPE is a floating-point type, return a
10784 signed integer type with the same bitsize as TYPE. */
10787 signed_type_for (tree type
)
10789 return signed_or_unsigned_type_for (0, type
);
10792 /* - For VECTOR_TYPEs:
10793 - The truth type must be a VECTOR_BOOLEAN_TYPE.
10794 - The number of elements must match (known_eq).
10795 - targetm.vectorize.get_mask_mode exists, and exactly
10796 the same mode as the truth type.
10797 - Otherwise, the truth type must be a BOOLEAN_TYPE
10798 or useless_type_conversion_p to BOOLEAN_TYPE. */
10800 is_truth_type_for (tree type
, tree truth_type
)
10802 machine_mode mask_mode
= TYPE_MODE (truth_type
);
10803 machine_mode vmode
= TYPE_MODE (type
);
10804 machine_mode tmask_mode
;
10806 if (TREE_CODE (type
) == VECTOR_TYPE
)
10808 if (VECTOR_BOOLEAN_TYPE_P (truth_type
)
10809 && known_eq (TYPE_VECTOR_SUBPARTS (type
),
10810 TYPE_VECTOR_SUBPARTS (truth_type
))
10811 && targetm
.vectorize
.get_mask_mode (vmode
).exists (&tmask_mode
)
10812 && tmask_mode
== mask_mode
)
10818 return useless_type_conversion_p (boolean_type_node
, truth_type
);
10821 /* If TYPE is a vector type, return a signed integer vector type with the
10822 same width and number of subparts. Otherwise return boolean_type_node. */
10825 truth_type_for (tree type
)
10827 if (TREE_CODE (type
) == VECTOR_TYPE
)
10829 if (VECTOR_BOOLEAN_TYPE_P (type
))
10831 return build_truth_vector_type_for (type
);
10834 return boolean_type_node
;
10837 /* Returns the largest value obtainable by casting something in INNER type to
10841 upper_bound_in_type (tree outer
, tree inner
)
10843 unsigned int det
= 0;
10844 unsigned oprec
= TYPE_PRECISION (outer
);
10845 unsigned iprec
= TYPE_PRECISION (inner
);
10848 /* Compute a unique number for every combination. */
10849 det
|= (oprec
> iprec
) ? 4 : 0;
10850 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10851 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10853 /* Determine the exponent to use. */
10858 /* oprec <= iprec, outer: signed, inner: don't care. */
10863 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10867 /* oprec > iprec, outer: signed, inner: signed. */
10871 /* oprec > iprec, outer: signed, inner: unsigned. */
10875 /* oprec > iprec, outer: unsigned, inner: signed. */
10879 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10883 gcc_unreachable ();
10886 return wide_int_to_tree (outer
,
10887 wi::mask (prec
, false, TYPE_PRECISION (outer
)));
10890 /* Returns the smallest value obtainable by casting something in INNER type to
10894 lower_bound_in_type (tree outer
, tree inner
)
10896 unsigned oprec
= TYPE_PRECISION (outer
);
10897 unsigned iprec
= TYPE_PRECISION (inner
);
10899 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10901 if (TYPE_UNSIGNED (outer
)
10902 /* If we are widening something of an unsigned type, OUTER type
10903 contains all values of INNER type. In particular, both INNER
10904 and OUTER types have zero in common. */
10905 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10906 return build_int_cst (outer
, 0);
10909 /* If we are widening a signed type to another signed type, we
10910 want to obtain -2^^(iprec-1). If we are keeping the
10911 precision or narrowing to a signed type, we want to obtain
10913 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10914 return wide_int_to_tree (outer
,
10915 wi::mask (prec
- 1, true,
10916 TYPE_PRECISION (outer
)));
10920 /* Return nonzero if two operands that are suitable for PHI nodes are
10921 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10922 SSA_NAME or invariant. Note that this is strictly an optimization.
10923 That is, callers of this function can directly call operand_equal_p
10924 and get the same result, only slower. */
10927 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10931 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10933 return operand_equal_p (arg0
, arg1
, 0);
10936 /* Returns number of zeros at the end of binary representation of X. */
10939 num_ending_zeros (const_tree x
)
10941 return build_int_cst (TREE_TYPE (x
), wi::ctz (wi::to_wide (x
)));
10945 #define WALK_SUBTREE(NODE) \
10948 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10954 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10955 be walked whenever a type is seen in the tree. Rest of operands and return
10956 value are as for walk_tree. */
10959 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10960 hash_set
<tree
> *pset
, walk_tree_lh lh
)
10962 tree result
= NULL_TREE
;
10964 switch (TREE_CODE (type
))
10967 case REFERENCE_TYPE
:
10969 /* We have to worry about mutually recursive pointers. These can't
10970 be written in C. They can in Ada. It's pathological, but
10971 there's an ACATS test (c38102a) that checks it. Deal with this
10972 by checking if we're pointing to another pointer, that one
10973 points to another pointer, that one does too, and we have no htab.
10974 If so, get a hash table. We check three levels deep to avoid
10975 the cost of the hash table if we don't need one. */
10976 if (POINTER_TYPE_P (TREE_TYPE (type
))
10977 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10978 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10981 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10992 WALK_SUBTREE (TREE_TYPE (type
));
10996 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10998 /* Fall through. */
11000 case FUNCTION_TYPE
:
11001 WALK_SUBTREE (TREE_TYPE (type
));
11005 /* We never want to walk into default arguments. */
11006 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
11007 WALK_SUBTREE (TREE_VALUE (arg
));
11012 /* Don't follow this nodes's type if a pointer for fear that
11013 we'll have infinite recursion. If we have a PSET, then we
11016 || (!POINTER_TYPE_P (TREE_TYPE (type
))
11017 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
11018 WALK_SUBTREE (TREE_TYPE (type
));
11019 WALK_SUBTREE (TYPE_DOMAIN (type
));
11023 WALK_SUBTREE (TREE_TYPE (type
));
11024 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
11034 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11035 called with the DATA and the address of each sub-tree. If FUNC returns a
11036 non-NULL value, the traversal is stopped, and the value returned by FUNC
11037 is returned. If PSET is non-NULL it is used to record the nodes visited,
11038 and to avoid visiting a node more than once. */
11041 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11042 hash_set
<tree
> *pset
, walk_tree_lh lh
)
11044 enum tree_code code
;
11048 #define WALK_SUBTREE_TAIL(NODE) \
11052 goto tail_recurse; \
11057 /* Skip empty subtrees. */
11061 /* Don't walk the same tree twice, if the user has requested
11062 that we avoid doing so. */
11063 if (pset
&& pset
->add (*tp
))
11066 /* Call the function. */
11068 result
= (*func
) (tp
, &walk_subtrees
, data
);
11070 /* If we found something, return it. */
11074 code
= TREE_CODE (*tp
);
11076 /* Even if we didn't, FUNC may have decided that there was nothing
11077 interesting below this point in the tree. */
11078 if (!walk_subtrees
)
11080 /* But we still need to check our siblings. */
11081 if (code
== TREE_LIST
)
11082 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11083 else if (code
== OMP_CLAUSE
)
11084 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11091 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
11092 if (result
|| !walk_subtrees
)
11099 case IDENTIFIER_NODE
:
11105 case PLACEHOLDER_EXPR
:
11109 /* None of these have subtrees other than those already walked
11114 WALK_SUBTREE (TREE_VALUE (*tp
));
11115 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11119 int len
= TREE_VEC_LENGTH (*tp
);
11124 /* Walk all elements but the first. */
11126 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
11128 /* Now walk the first one as a tail call. */
11129 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
11134 unsigned len
= vector_cst_encoded_nelts (*tp
);
11137 /* Walk all elements but the first. */
11139 WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (*tp
, len
));
11140 /* Now walk the first one as a tail call. */
11141 WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (*tp
, 0));
11145 WALK_SUBTREE (TREE_REALPART (*tp
));
11146 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
11150 unsigned HOST_WIDE_INT idx
;
11151 constructor_elt
*ce
;
11153 for (idx
= 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*tp
), idx
, &ce
);
11155 WALK_SUBTREE (ce
->value
);
11160 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
11165 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
11167 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11168 into declarations that are just mentioned, rather than
11169 declared; they don't really belong to this part of the tree.
11170 And, we can see cycles: the initializer for a declaration
11171 can refer to the declaration itself. */
11172 WALK_SUBTREE (DECL_INITIAL (decl
));
11173 WALK_SUBTREE (DECL_SIZE (decl
));
11174 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
11176 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
11179 case STATEMENT_LIST
:
11181 tree_stmt_iterator i
;
11182 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
11183 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11189 int len
= omp_clause_num_ops
[OMP_CLAUSE_CODE (*tp
)];
11190 for (int i
= 0; i
< len
; i
++)
11191 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11192 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11199 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11200 But, we only want to walk once. */
11201 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11202 for (i
= 0; i
< len
; ++i
)
11203 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11204 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11208 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11209 defining. We only want to walk into these fields of a type in this
11210 case and not in the general case of a mere reference to the type.
11212 The criterion is as follows: if the field can be an expression, it
11213 must be walked only here. This should be in keeping with the fields
11214 that are directly gimplified in gimplify_type_sizes in order for the
11215 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11216 variable-sized types.
11218 Note that DECLs get walked as part of processing the BIND_EXPR. */
11219 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11221 /* Call the function for the decl so e.g. copy_tree_body_r can
11222 replace it with the remapped one. */
11223 result
= (*func
) (&DECL_EXPR_DECL (*tp
), &walk_subtrees
, data
);
11224 if (result
|| !walk_subtrees
)
11227 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11228 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11231 /* Call the function for the type. See if it returns anything or
11232 doesn't want us to continue. If we are to continue, walk both
11233 the normal fields and those for the declaration case. */
11234 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11235 if (result
|| !walk_subtrees
)
11238 /* But do not walk a pointed-to type since it may itself need to
11239 be walked in the declaration case if it isn't anonymous. */
11240 if (!POINTER_TYPE_P (*type_p
))
11242 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11247 /* If this is a record type, also walk the fields. */
11248 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11252 for (field
= TYPE_FIELDS (*type_p
); field
;
11253 field
= DECL_CHAIN (field
))
11255 /* We'd like to look at the type of the field, but we can
11256 easily get infinite recursion. So assume it's pointed
11257 to elsewhere in the tree. Also, ignore things that
11259 if (TREE_CODE (field
) != FIELD_DECL
)
11262 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11263 WALK_SUBTREE (DECL_SIZE (field
));
11264 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11265 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11266 WALK_SUBTREE (DECL_QUALIFIER (field
));
11270 /* Same for scalar types. */
11271 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11272 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11273 || TREE_CODE (*type_p
) == INTEGER_TYPE
11274 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11275 || TREE_CODE (*type_p
) == REAL_TYPE
)
11277 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11278 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11281 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11282 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11287 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11291 /* Walk over all the sub-trees of this operand. */
11292 len
= TREE_OPERAND_LENGTH (*tp
);
11294 /* Go through the subtrees. We need to do this in forward order so
11295 that the scope of a FOR_EXPR is handled properly. */
11298 for (i
= 0; i
< len
- 1; ++i
)
11299 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11300 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11303 /* If this is a type, walk the needed fields in the type. */
11304 else if (TYPE_P (*tp
))
11305 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11309 /* We didn't find what we were looking for. */
11312 #undef WALK_SUBTREE_TAIL
11314 #undef WALK_SUBTREE
11316 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11319 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11324 hash_set
<tree
> pset
;
11325 result
= walk_tree_1 (tp
, func
, data
, &pset
, lh
);
11331 tree_block (tree t
)
11333 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11335 if (IS_EXPR_CODE_CLASS (c
))
11336 return LOCATION_BLOCK (t
->exp
.locus
);
11337 gcc_unreachable ();
11342 tree_set_block (tree t
, tree b
)
11344 const enum tree_code_class c
= TREE_CODE_CLASS (TREE_CODE (t
));
11346 if (IS_EXPR_CODE_CLASS (c
))
11348 t
->exp
.locus
= set_block (t
->exp
.locus
, b
);
11351 gcc_unreachable ();
11354 /* Create a nameless artificial label and put it in the current
11355 function context. The label has a location of LOC. Returns the
11356 newly created label. */
11359 create_artificial_label (location_t loc
)
11361 tree lab
= build_decl (loc
,
11362 LABEL_DECL
, NULL_TREE
, void_type_node
);
11364 DECL_ARTIFICIAL (lab
) = 1;
11365 DECL_IGNORED_P (lab
) = 1;
11366 DECL_CONTEXT (lab
) = current_function_decl
;
11370 /* Given a tree, try to return a useful variable name that we can use
11371 to prefix a temporary that is being assigned the value of the tree.
11372 I.E. given <temp> = &A, return A. */
11377 tree stripped_decl
;
11380 STRIP_NOPS (stripped_decl
);
11381 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11382 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11383 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11385 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11388 return IDENTIFIER_POINTER (name
);
11392 switch (TREE_CODE (stripped_decl
))
11395 return get_name (TREE_OPERAND (stripped_decl
, 0));
11402 /* Return true if TYPE has a variable argument list. */
11405 stdarg_p (const_tree fntype
)
11407 function_args_iterator args_iter
;
11408 tree n
= NULL_TREE
, t
;
11413 FOREACH_FUNCTION_ARGS (fntype
, t
, args_iter
)
11418 return n
!= NULL_TREE
&& n
!= void_type_node
;
11421 /* Return true if TYPE has a prototype. */
11424 prototype_p (const_tree fntype
)
11428 gcc_assert (fntype
!= NULL_TREE
);
11430 t
= TYPE_ARG_TYPES (fntype
);
11431 return (t
!= NULL_TREE
);
11434 /* If BLOCK is inlined from an __attribute__((__artificial__))
11435 routine, return pointer to location from where it has been
11438 block_nonartificial_location (tree block
)
11440 location_t
*ret
= NULL
;
11442 while (block
&& TREE_CODE (block
) == BLOCK
11443 && BLOCK_ABSTRACT_ORIGIN (block
))
11445 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11446 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11448 /* If AO is an artificial inline, point RET to the
11449 call site locus at which it has been inlined and continue
11450 the loop, in case AO's caller is also an artificial
11452 if (DECL_DECLARED_INLINE_P (ao
)
11453 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11454 ret
= &BLOCK_SOURCE_LOCATION (block
);
11458 else if (TREE_CODE (ao
) != BLOCK
)
11461 block
= BLOCK_SUPERCONTEXT (block
);
11467 /* If EXP is inlined from an __attribute__((__artificial__))
11468 function, return the location of the original call expression. */
11471 tree_nonartificial_location (tree exp
)
11473 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11478 return EXPR_LOCATION (exp
);
11481 /* Return the location into which EXP has been inlined. Analogous
11482 to tree_nonartificial_location() above but not limited to artificial
11483 functions declared inline. If SYSTEM_HEADER is true, return
11484 the macro expansion point of the location if it's in a system header */
11487 tree_inlined_location (tree exp
, bool system_header
/* = true */)
11489 location_t loc
= UNKNOWN_LOCATION
;
11491 tree block
= TREE_BLOCK (exp
);
11493 while (block
&& TREE_CODE (block
) == BLOCK
11494 && BLOCK_ABSTRACT_ORIGIN (block
))
11496 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11497 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11498 loc
= BLOCK_SOURCE_LOCATION (block
);
11499 else if (TREE_CODE (ao
) != BLOCK
)
11502 block
= BLOCK_SUPERCONTEXT (block
);
11505 if (loc
== UNKNOWN_LOCATION
)
11507 loc
= EXPR_LOCATION (exp
);
11509 /* Only consider macro expansion when the block traversal failed
11510 to find a location. Otherwise it's not relevant. */
11511 return expansion_point_location_if_in_system_header (loc
);
11517 /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
11520 /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11523 cl_option_hasher::hash (tree x
)
11525 const_tree
const t
= x
;
11527 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11528 return cl_optimization_hash (TREE_OPTIMIZATION (t
));
11529 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11530 return cl_target_option_hash (TREE_TARGET_OPTION (t
));
11532 gcc_unreachable ();
11535 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11536 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11540 cl_option_hasher::equal (tree x
, tree y
)
11542 const_tree
const xt
= x
;
11543 const_tree
const yt
= y
;
11545 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11548 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11549 return cl_optimization_option_eq (TREE_OPTIMIZATION (xt
),
11550 TREE_OPTIMIZATION (yt
));
11551 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11552 return cl_target_option_eq (TREE_TARGET_OPTION (xt
),
11553 TREE_TARGET_OPTION (yt
));
11555 gcc_unreachable ();
11558 /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
11561 build_optimization_node (struct gcc_options
*opts
,
11562 struct gcc_options
*opts_set
)
11566 /* Use the cache of optimization nodes. */
11568 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
11571 tree
*slot
= cl_option_hash_table
->find_slot (cl_optimization_node
, INSERT
);
11575 /* Insert this one into the hash table. */
11576 t
= cl_optimization_node
;
11579 /* Make a new node for next time round. */
11580 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
11586 /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
11589 build_target_option_node (struct gcc_options
*opts
,
11590 struct gcc_options
*opts_set
)
11594 /* Use the cache of optimization nodes. */
11596 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
11599 tree
*slot
= cl_option_hash_table
->find_slot (cl_target_option_node
, INSERT
);
11603 /* Insert this one into the hash table. */
11604 t
= cl_target_option_node
;
11607 /* Make a new node for next time round. */
11608 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
11614 /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
11615 so that they aren't saved during PCH writing. */
11618 prepare_target_option_nodes_for_pch (void)
11620 hash_table
<cl_option_hasher
>::iterator iter
= cl_option_hash_table
->begin ();
11621 for (; iter
!= cl_option_hash_table
->end (); ++iter
)
11622 if (TREE_CODE (*iter
) == TARGET_OPTION_NODE
)
11623 TREE_TARGET_GLOBALS (*iter
) = NULL
;
11626 /* Determine the "ultimate origin" of a block. */
11629 block_ultimate_origin (const_tree block
)
11631 tree origin
= BLOCK_ABSTRACT_ORIGIN (block
);
11633 if (origin
== NULL_TREE
)
11637 gcc_checking_assert ((DECL_P (origin
)
11638 && DECL_ORIGIN (origin
) == origin
)
11639 || BLOCK_ORIGIN (origin
) == origin
);
11644 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
11648 tree_nop_conversion_p (const_tree outer_type
, const_tree inner_type
)
11650 /* Do not strip casts into or out of differing address spaces. */
11651 if (POINTER_TYPE_P (outer_type
)
11652 && TYPE_ADDR_SPACE (TREE_TYPE (outer_type
)) != ADDR_SPACE_GENERIC
)
11654 if (!POINTER_TYPE_P (inner_type
)
11655 || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type
))
11656 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type
))))
11659 else if (POINTER_TYPE_P (inner_type
)
11660 && TYPE_ADDR_SPACE (TREE_TYPE (inner_type
)) != ADDR_SPACE_GENERIC
)
11662 /* We already know that outer_type is not a pointer with
11663 a non-generic address space. */
11667 /* Use precision rather then machine mode when we can, which gives
11668 the correct answer even for submode (bit-field) types. */
11669 if ((INTEGRAL_TYPE_P (outer_type
)
11670 || POINTER_TYPE_P (outer_type
)
11671 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
11672 && (INTEGRAL_TYPE_P (inner_type
)
11673 || POINTER_TYPE_P (inner_type
)
11674 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
11675 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
11677 /* Otherwise fall back on comparing machine modes (e.g. for
11678 aggregate types, floats). */
11679 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
11682 /* Return true iff conversion in EXP generates no instruction. Mark
11683 it inline so that we fully inline into the stripping functions even
11684 though we have two uses of this function. */
11687 tree_nop_conversion (const_tree exp
)
11689 tree outer_type
, inner_type
;
11691 if (location_wrapper_p (exp
))
11693 if (!CONVERT_EXPR_P (exp
)
11694 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
11697 outer_type
= TREE_TYPE (exp
);
11698 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11699 if (!inner_type
|| inner_type
== error_mark_node
)
11702 return tree_nop_conversion_p (outer_type
, inner_type
);
11705 /* Return true iff conversion in EXP generates no instruction. Don't
11706 consider conversions changing the signedness. */
11709 tree_sign_nop_conversion (const_tree exp
)
11711 tree outer_type
, inner_type
;
11713 if (!tree_nop_conversion (exp
))
11716 outer_type
= TREE_TYPE (exp
);
11717 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11719 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
11720 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
11723 /* Strip conversions from EXP according to tree_nop_conversion and
11724 return the resulting expression. */
11727 tree_strip_nop_conversions (tree exp
)
11729 while (tree_nop_conversion (exp
))
11730 exp
= TREE_OPERAND (exp
, 0);
11734 /* Strip conversions from EXP according to tree_sign_nop_conversion
11735 and return the resulting expression. */
11738 tree_strip_sign_nop_conversions (tree exp
)
11740 while (tree_sign_nop_conversion (exp
))
11741 exp
= TREE_OPERAND (exp
, 0);
11745 /* Avoid any floating point extensions from EXP. */
11747 strip_float_extensions (tree exp
)
11749 tree sub
, expt
, subt
;
11751 /* For floating point constant look up the narrowest type that can hold
11752 it properly and handle it like (type)(narrowest_type)constant.
11753 This way we can optimize for instance a=a*2.0 where "a" is float
11754 but 2.0 is double constant. */
11755 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
11757 REAL_VALUE_TYPE orig
;
11760 orig
= TREE_REAL_CST (exp
);
11761 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
11762 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
11763 type
= float_type_node
;
11764 else if (TYPE_PRECISION (TREE_TYPE (exp
))
11765 > TYPE_PRECISION (double_type_node
)
11766 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
11767 type
= double_type_node
;
11769 return build_real_truncate (type
, orig
);
11772 if (!CONVERT_EXPR_P (exp
))
11775 sub
= TREE_OPERAND (exp
, 0);
11776 subt
= TREE_TYPE (sub
);
11777 expt
= TREE_TYPE (exp
);
11779 if (!FLOAT_TYPE_P (subt
))
11782 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
11785 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
11788 return strip_float_extensions (sub
);
11791 /* Strip out all handled components that produce invariant
11795 strip_invariant_refs (const_tree op
)
11797 while (handled_component_p (op
))
11799 switch (TREE_CODE (op
))
11802 case ARRAY_RANGE_REF
:
11803 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
11804 || TREE_OPERAND (op
, 2) != NULL_TREE
11805 || TREE_OPERAND (op
, 3) != NULL_TREE
)
11809 case COMPONENT_REF
:
11810 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
11816 op
= TREE_OPERAND (op
, 0);
11822 static GTY(()) tree gcc_eh_personality_decl
;
11824 /* Return the GCC personality function decl. */
11827 lhd_gcc_personality (void)
11829 if (!gcc_eh_personality_decl
)
11830 gcc_eh_personality_decl
= build_personality_function ("gcc");
11831 return gcc_eh_personality_decl
;
11834 /* TARGET is a call target of GIMPLE call statement
11835 (obtained by gimple_call_fn). Return true if it is
11836 OBJ_TYPE_REF representing an virtual call of C++ method.
11837 (As opposed to OBJ_TYPE_REF representing objc calls
11838 through a cast where middle-end devirtualization machinery
11839 can't apply.) FOR_DUMP_P is true when being called from
11840 the dump routines. */
11843 virtual_method_call_p (const_tree target
, bool for_dump_p
)
11845 if (TREE_CODE (target
) != OBJ_TYPE_REF
)
11847 tree t
= TREE_TYPE (target
);
11848 gcc_checking_assert (TREE_CODE (t
) == POINTER_TYPE
);
11850 if (TREE_CODE (t
) == FUNCTION_TYPE
)
11852 gcc_checking_assert (TREE_CODE (t
) == METHOD_TYPE
);
11853 /* If we do not have BINFO associated, it means that type was built
11854 without devirtualization enabled. Do not consider this a virtual
11856 if (!TYPE_BINFO (obj_type_ref_class (target
, for_dump_p
)))
11861 /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
11864 lookup_binfo_at_offset (tree binfo
, tree type
, HOST_WIDE_INT pos
)
11867 tree base_binfo
, b
;
11869 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11870 if (pos
== tree_to_shwi (BINFO_OFFSET (base_binfo
))
11871 && types_same_for_odr (TREE_TYPE (base_binfo
), type
))
11873 else if ((b
= lookup_binfo_at_offset (base_binfo
, type
, pos
)) != NULL
)
11878 /* Try to find a base info of BINFO that would have its field decl at offset
11879 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
11880 found, return, otherwise return NULL_TREE. */
11883 get_binfo_at_offset (tree binfo
, poly_int64 offset
, tree expected_type
)
11885 tree type
= BINFO_TYPE (binfo
);
11889 HOST_WIDE_INT pos
, size
;
11893 if (types_same_for_odr (type
, expected_type
))
11895 if (maybe_lt (offset
, 0))
11898 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
11900 if (TREE_CODE (fld
) != FIELD_DECL
|| !DECL_ARTIFICIAL (fld
))
11903 pos
= int_bit_position (fld
);
11904 size
= tree_to_uhwi (DECL_SIZE (fld
));
11905 if (known_in_range_p (offset
, pos
, size
))
11908 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
11911 /* Offset 0 indicates the primary base, whose vtable contents are
11912 represented in the binfo for the derived class. */
11913 else if (maybe_ne (offset
, 0))
11915 tree found_binfo
= NULL
, base_binfo
;
11916 /* Offsets in BINFO are in bytes relative to the whole structure
11917 while POS is in bits relative to the containing field. */
11918 int binfo_offset
= (tree_to_shwi (BINFO_OFFSET (binfo
)) + pos
11921 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11922 if (tree_to_shwi (BINFO_OFFSET (base_binfo
)) == binfo_offset
11923 && types_same_for_odr (TREE_TYPE (base_binfo
), TREE_TYPE (fld
)))
11925 found_binfo
= base_binfo
;
11929 binfo
= found_binfo
;
11931 binfo
= lookup_binfo_at_offset (binfo
, TREE_TYPE (fld
),
11935 type
= TREE_TYPE (fld
);
11940 /* Returns true if X is a typedef decl. */
11943 is_typedef_decl (const_tree x
)
11945 return (x
&& TREE_CODE (x
) == TYPE_DECL
11946 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
11949 /* Returns true iff TYPE is a type variant created for a typedef. */
11952 typedef_variant_p (const_tree type
)
11954 return is_typedef_decl (TYPE_NAME (type
));
11957 /* PR 84195: Replace control characters in "unescaped" with their
11958 escaped equivalents. Allow newlines if -fmessage-length has
11959 been set to a non-zero value. This is done here, rather than
11960 where the attribute is recorded as the message length can
11961 change between these two locations. */
11964 escaped_string::escape (const char *unescaped
)
11967 size_t i
, new_i
, len
;
11972 m_str
= const_cast<char *> (unescaped
);
11975 if (unescaped
== NULL
|| *unescaped
== 0)
11978 len
= strlen (unescaped
);
11982 for (i
= 0; i
< len
; i
++)
11984 char c
= unescaped
[i
];
11989 escaped
[new_i
++] = c
;
11993 if (c
!= '\n' || !pp_is_wrapping_line (global_dc
->printer
))
11995 if (escaped
== NULL
)
11997 /* We only allocate space for a new string if we
11998 actually encounter a control character that
11999 needs replacing. */
12000 escaped
= (char *) xmalloc (len
* 2 + 1);
12001 strncpy (escaped
, unescaped
, i
);
12005 escaped
[new_i
++] = '\\';
12009 case '\a': escaped
[new_i
++] = 'a'; break;
12010 case '\b': escaped
[new_i
++] = 'b'; break;
12011 case '\f': escaped
[new_i
++] = 'f'; break;
12012 case '\n': escaped
[new_i
++] = 'n'; break;
12013 case '\r': escaped
[new_i
++] = 'r'; break;
12014 case '\t': escaped
[new_i
++] = 't'; break;
12015 case '\v': escaped
[new_i
++] = 'v'; break;
12016 default: escaped
[new_i
++] = '?'; break;
12020 escaped
[new_i
++] = c
;
12025 escaped
[new_i
] = 0;
12031 /* Warn about a use of an identifier which was marked deprecated. Returns
12032 whether a warning was given. */
12035 warn_deprecated_use (tree node
, tree attr
)
12037 escaped_string msg
;
12039 if (node
== 0 || !warn_deprecated_decl
)
12045 attr
= DECL_ATTRIBUTES (node
);
12046 else if (TYPE_P (node
))
12048 tree decl
= TYPE_STUB_DECL (node
);
12050 attr
= lookup_attribute ("deprecated",
12051 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
12056 attr
= lookup_attribute ("deprecated", attr
);
12059 msg
.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
12064 auto_diagnostic_group d
;
12066 w
= warning (OPT_Wdeprecated_declarations
,
12067 "%qD is deprecated: %s", node
, (const char *) msg
);
12069 w
= warning (OPT_Wdeprecated_declarations
,
12070 "%qD is deprecated", node
);
12072 inform (DECL_SOURCE_LOCATION (node
), "declared here");
12074 else if (TYPE_P (node
))
12076 tree what
= NULL_TREE
;
12077 tree decl
= TYPE_STUB_DECL (node
);
12079 if (TYPE_NAME (node
))
12081 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
12082 what
= TYPE_NAME (node
);
12083 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
12084 && DECL_NAME (TYPE_NAME (node
)))
12085 what
= DECL_NAME (TYPE_NAME (node
));
12088 auto_diagnostic_group d
;
12092 w
= warning (OPT_Wdeprecated_declarations
,
12093 "%qE is deprecated: %s", what
, (const char *) msg
);
12095 w
= warning (OPT_Wdeprecated_declarations
,
12096 "%qE is deprecated", what
);
12101 w
= warning (OPT_Wdeprecated_declarations
,
12102 "type is deprecated: %s", (const char *) msg
);
12104 w
= warning (OPT_Wdeprecated_declarations
,
12105 "type is deprecated");
12109 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
12115 /* Error out with an identifier which was marked 'unavailable'. */
12117 error_unavailable_use (tree node
, tree attr
)
12119 escaped_string msg
;
12127 attr
= DECL_ATTRIBUTES (node
);
12128 else if (TYPE_P (node
))
12130 tree decl
= TYPE_STUB_DECL (node
);
12132 attr
= lookup_attribute ("unavailable",
12133 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
12138 attr
= lookup_attribute ("unavailable", attr
);
12141 msg
.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
12145 auto_diagnostic_group d
;
12147 error ("%qD is unavailable: %s", node
, (const char *) msg
);
12149 error ("%qD is unavailable", node
);
12150 inform (DECL_SOURCE_LOCATION (node
), "declared here");
12152 else if (TYPE_P (node
))
12154 tree what
= NULL_TREE
;
12155 tree decl
= TYPE_STUB_DECL (node
);
12157 if (TYPE_NAME (node
))
12159 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
12160 what
= TYPE_NAME (node
);
12161 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
12162 && DECL_NAME (TYPE_NAME (node
)))
12163 what
= DECL_NAME (TYPE_NAME (node
));
12166 auto_diagnostic_group d
;
12170 error ("%qE is unavailable: %s", what
, (const char *) msg
);
12172 error ("%qE is unavailable", what
);
12177 error ("type is unavailable: %s", (const char *) msg
);
12179 error ("type is unavailable");
12183 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
12187 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12188 somewhere in it. */
12191 contains_bitfld_component_ref_p (const_tree ref
)
12193 while (handled_component_p (ref
))
12195 if (TREE_CODE (ref
) == COMPONENT_REF
12196 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
12198 ref
= TREE_OPERAND (ref
, 0);
12204 /* Try to determine whether a TRY_CATCH expression can fall through.
12205 This is a subroutine of block_may_fallthru. */
12208 try_catch_may_fallthru (const_tree stmt
)
12210 tree_stmt_iterator i
;
12212 /* If the TRY block can fall through, the whole TRY_CATCH can
12214 if (block_may_fallthru (TREE_OPERAND (stmt
, 0)))
12217 i
= tsi_start (TREE_OPERAND (stmt
, 1));
12218 switch (TREE_CODE (tsi_stmt (i
)))
12221 /* We expect to see a sequence of CATCH_EXPR trees, each with a
12222 catch expression and a body. The whole TRY_CATCH may fall
12223 through iff any of the catch bodies falls through. */
12224 for (; !tsi_end_p (i
); tsi_next (&i
))
12226 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i
))))
12231 case EH_FILTER_EXPR
:
12232 /* The exception filter expression only matters if there is an
12233 exception. If the exception does not match EH_FILTER_TYPES,
12234 we will execute EH_FILTER_FAILURE, and we will fall through
12235 if that falls through. If the exception does match
12236 EH_FILTER_TYPES, the stack unwinder will continue up the
12237 stack, so we will not fall through. We don't know whether we
12238 will throw an exception which matches EH_FILTER_TYPES or not,
12239 so we just ignore EH_FILTER_TYPES and assume that we might
12240 throw an exception which doesn't match. */
12241 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i
)));
12244 /* This case represents statements to be executed when an
12245 exception occurs. Those statements are implicitly followed
12246 by a RESX statement to resume execution after the exception.
12247 So in this case the TRY_CATCH never falls through. */
12252 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12253 need not be 100% accurate; simply be conservative and return true if we
12254 don't know. This is used only to avoid stupidly generating extra code.
12255 If we're wrong, we'll just delete the extra code later. */
12258 block_may_fallthru (const_tree block
)
12260 /* This CONST_CAST is okay because expr_last returns its argument
12261 unmodified and we assign it to a const_tree. */
12262 const_tree stmt
= expr_last (CONST_CAST_TREE (block
));
12264 switch (stmt
? TREE_CODE (stmt
) : ERROR_MARK
)
12268 /* Easy cases. If the last statement of the block implies
12269 control transfer, then we can't fall through. */
12273 /* If there is a default: label or case labels cover all possible
12274 SWITCH_COND values, then the SWITCH_EXPR will transfer control
12275 to some case label in all cases and all we care is whether the
12276 SWITCH_BODY falls through. */
12277 if (SWITCH_ALL_CASES_P (stmt
))
12278 return block_may_fallthru (SWITCH_BODY (stmt
));
12282 if (block_may_fallthru (COND_EXPR_THEN (stmt
)))
12284 return block_may_fallthru (COND_EXPR_ELSE (stmt
));
12287 return block_may_fallthru (BIND_EXPR_BODY (stmt
));
12289 case TRY_CATCH_EXPR
:
12290 return try_catch_may_fallthru (stmt
);
12292 case TRY_FINALLY_EXPR
:
12293 /* The finally clause is always executed after the try clause,
12294 so if it does not fall through, then the try-finally will not
12295 fall through. Otherwise, if the try clause does not fall
12296 through, then when the finally clause falls through it will
12297 resume execution wherever the try clause was going. So the
12298 whole try-finally will only fall through if both the try
12299 clause and the finally clause fall through. */
12300 return (block_may_fallthru (TREE_OPERAND (stmt
, 0))
12301 && block_may_fallthru (TREE_OPERAND (stmt
, 1)));
12304 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
12307 if (TREE_CODE (TREE_OPERAND (stmt
, 1)) == CALL_EXPR
)
12308 stmt
= TREE_OPERAND (stmt
, 1);
12314 /* Functions that do not return do not fall through. */
12315 return (call_expr_flags (stmt
) & ECF_NORETURN
) == 0;
12317 case CLEANUP_POINT_EXPR
:
12318 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
12321 return block_may_fallthru (TREE_OPERAND (stmt
, 1));
12327 return lang_hooks
.block_may_fallthru (stmt
);
12331 /* True if we are using EH to handle cleanups. */
12332 static bool using_eh_for_cleanups_flag
= false;
12334 /* This routine is called from front ends to indicate eh should be used for
12337 using_eh_for_cleanups (void)
12339 using_eh_for_cleanups_flag
= true;
12342 /* Query whether EH is used for cleanups. */
12344 using_eh_for_cleanups_p (void)
12346 return using_eh_for_cleanups_flag
;
12349 /* Wrapper for tree_code_name to ensure that tree code is valid */
12351 get_tree_code_name (enum tree_code code
)
12353 const char *invalid
= "<invalid tree code>";
12355 /* The tree_code enum promotes to signed, but we could be getting
12356 invalid values, so force an unsigned comparison. */
12357 if (unsigned (code
) >= MAX_TREE_CODES
)
12359 if ((unsigned)code
== 0xa5a5)
12360 return "ggc_freed";
12364 return tree_code_name
[code
];
12367 /* Drops the TREE_OVERFLOW flag from T. */
12370 drop_tree_overflow (tree t
)
12372 gcc_checking_assert (TREE_OVERFLOW (t
));
12374 /* For tree codes with a sharing machinery re-build the result. */
12375 if (poly_int_tree_p (t
))
12376 return wide_int_to_tree (TREE_TYPE (t
), wi::to_poly_wide (t
));
12378 /* For VECTOR_CST, remove the overflow bits from the encoded elements
12379 and canonicalize the result. */
12380 if (TREE_CODE (t
) == VECTOR_CST
)
12382 tree_vector_builder builder
;
12383 builder
.new_unary_operation (TREE_TYPE (t
), t
, true);
12384 unsigned int count
= builder
.encoded_nelts ();
12385 for (unsigned int i
= 0; i
< count
; ++i
)
12387 tree elt
= VECTOR_CST_ELT (t
, i
);
12388 if (TREE_OVERFLOW (elt
))
12389 elt
= drop_tree_overflow (elt
);
12390 builder
.quick_push (elt
);
12392 return builder
.build ();
12395 /* Otherwise, as all tcc_constants are possibly shared, copy the node
12396 and drop the flag. */
12398 TREE_OVERFLOW (t
) = 0;
12400 /* For constants that contain nested constants, drop the flag
12401 from those as well. */
12402 if (TREE_CODE (t
) == COMPLEX_CST
)
12404 if (TREE_OVERFLOW (TREE_REALPART (t
)))
12405 TREE_REALPART (t
) = drop_tree_overflow (TREE_REALPART (t
));
12406 if (TREE_OVERFLOW (TREE_IMAGPART (t
)))
12407 TREE_IMAGPART (t
) = drop_tree_overflow (TREE_IMAGPART (t
));
12413 /* Given a memory reference expression T, return its base address.
12414 The base address of a memory reference expression is the main
12415 object being referenced. For instance, the base address for
12416 'array[i].fld[j]' is 'array'. You can think of this as stripping
12417 away the offset part from a memory address.
12419 This function calls handled_component_p to strip away all the inner
12420 parts of the memory reference until it reaches the base object. */
12423 get_base_address (tree t
)
12425 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
12426 t
= TREE_OPERAND (t
, 0);
12427 while (handled_component_p (t
))
12428 t
= TREE_OPERAND (t
, 0);
12430 if ((TREE_CODE (t
) == MEM_REF
12431 || TREE_CODE (t
) == TARGET_MEM_REF
)
12432 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
12433 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
12438 /* Return a tree of sizetype representing the size, in bytes, of the element
12439 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12442 array_ref_element_size (tree exp
)
12444 tree aligned_size
= TREE_OPERAND (exp
, 3);
12445 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12446 location_t loc
= EXPR_LOCATION (exp
);
12448 /* If a size was specified in the ARRAY_REF, it's the size measured
12449 in alignment units of the element type. So multiply by that value. */
12452 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12453 sizetype from another type of the same width and signedness. */
12454 if (TREE_TYPE (aligned_size
) != sizetype
)
12455 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
12456 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
12457 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
12460 /* Otherwise, take the size from that of the element type. Substitute
12461 any PLACEHOLDER_EXPR that we have. */
12463 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
12466 /* Return a tree representing the lower bound of the array mentioned in
12467 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12470 array_ref_low_bound (tree exp
)
12472 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12474 /* If a lower bound is specified in EXP, use it. */
12475 if (TREE_OPERAND (exp
, 2))
12476 return TREE_OPERAND (exp
, 2);
12478 /* Otherwise, if there is a domain type and it has a lower bound, use it,
12479 substituting for a PLACEHOLDER_EXPR as needed. */
12480 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
12481 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
12483 /* Otherwise, return a zero of the appropriate type. */
12484 tree idxtype
= TREE_TYPE (TREE_OPERAND (exp
, 1));
12485 return (idxtype
== error_mark_node
12486 ? integer_zero_node
: build_int_cst (idxtype
, 0));
12489 /* Return a tree representing the upper bound of the array mentioned in
12490 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
12493 array_ref_up_bound (tree exp
)
12495 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
12497 /* If there is a domain type and it has an upper bound, use it, substituting
12498 for a PLACEHOLDER_EXPR as needed. */
12499 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
12500 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
12502 /* Otherwise fail. */
12506 /* Returns true if REF is an array reference, component reference,
12507 or memory reference to an array at the end of a structure.
12508 If this is the case, the array may be allocated larger
12509 than its upper bound implies. */
12512 array_at_struct_end_p (tree ref
)
12516 if (TREE_CODE (ref
) == ARRAY_REF
12517 || TREE_CODE (ref
) == ARRAY_RANGE_REF
)
12519 atype
= TREE_TYPE (TREE_OPERAND (ref
, 0));
12520 ref
= TREE_OPERAND (ref
, 0);
12522 else if (TREE_CODE (ref
) == COMPONENT_REF
12523 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 1))) == ARRAY_TYPE
)
12524 atype
= TREE_TYPE (TREE_OPERAND (ref
, 1));
12525 else if (TREE_CODE (ref
) == MEM_REF
)
12527 tree arg
= TREE_OPERAND (ref
, 0);
12528 if (TREE_CODE (arg
) == ADDR_EXPR
)
12529 arg
= TREE_OPERAND (arg
, 0);
12530 tree argtype
= TREE_TYPE (arg
);
12531 if (TREE_CODE (argtype
) == RECORD_TYPE
)
12533 if (tree fld
= last_field (argtype
))
12535 atype
= TREE_TYPE (fld
);
12536 if (TREE_CODE (atype
) != ARRAY_TYPE
)
12538 if (VAR_P (arg
) && DECL_SIZE (fld
))
12550 if (TREE_CODE (ref
) == STRING_CST
)
12553 tree ref_to_array
= ref
;
12554 while (handled_component_p (ref
))
12556 /* If the reference chain contains a component reference to a
12557 non-union type and there follows another field the reference
12558 is not at the end of a structure. */
12559 if (TREE_CODE (ref
) == COMPONENT_REF
)
12561 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
12563 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
12564 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
12565 nextf
= DECL_CHAIN (nextf
);
12570 /* If we have a multi-dimensional array we do not consider
12571 a non-innermost dimension as flex array if the whole
12572 multi-dimensional array is at struct end.
12573 Same for an array of aggregates with a trailing array
12575 else if (TREE_CODE (ref
) == ARRAY_REF
)
12577 else if (TREE_CODE (ref
) == ARRAY_RANGE_REF
)
12579 /* If we view an underlying object as sth else then what we
12580 gathered up to now is what we have to rely on. */
12581 else if (TREE_CODE (ref
) == VIEW_CONVERT_EXPR
)
12584 gcc_unreachable ();
12586 ref
= TREE_OPERAND (ref
, 0);
12589 /* The array now is at struct end. Treat flexible arrays as
12590 always subject to extend, even into just padding constrained by
12591 an underlying decl. */
12592 if (! TYPE_SIZE (atype
)
12593 || ! TYPE_DOMAIN (atype
)
12594 || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype
)))
12597 /* If the reference is based on a declared entity, the size of the array
12598 is constrained by its given domain. (Do not trust commons PR/69368). */
12599 ref
= get_base_address (ref
);
12602 && !(flag_unconstrained_commons
12603 && VAR_P (ref
) && DECL_COMMON (ref
))
12604 && DECL_SIZE_UNIT (ref
)
12605 && TREE_CODE (DECL_SIZE_UNIT (ref
)) == INTEGER_CST
)
12607 /* Check whether the array domain covers all of the available
12610 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype
))) != INTEGER_CST
12611 || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype
))) != INTEGER_CST
12612 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype
))) != INTEGER_CST
)
12614 if (! get_addr_base_and_unit_offset (ref_to_array
, &offset
))
12617 /* If at least one extra element fits it is a flexarray. */
12618 if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype
)))
12619 - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype
)))
12621 * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype
))),
12622 wi::to_offset (DECL_SIZE_UNIT (ref
)) - offset
))
12631 /* Return a tree representing the offset, in bytes, of the field referenced
12632 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
12635 component_ref_field_offset (tree exp
)
12637 tree aligned_offset
= TREE_OPERAND (exp
, 2);
12638 tree field
= TREE_OPERAND (exp
, 1);
12639 location_t loc
= EXPR_LOCATION (exp
);
12641 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
12642 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
12644 if (aligned_offset
)
12646 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
12647 sizetype from another type of the same width and signedness. */
12648 if (TREE_TYPE (aligned_offset
) != sizetype
)
12649 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
12650 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
12651 size_int (DECL_OFFSET_ALIGN (field
)
12655 /* Otherwise, take the offset from that of the field. Substitute
12656 any PLACEHOLDER_EXPR that we have. */
12658 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
12661 /* Given the initializer INIT, return the initializer for the field
12662 DECL if it exists, otherwise null. Used to obtain the initializer
12663 for a flexible array member and determine its size. */
12666 get_initializer_for (tree init
, tree decl
)
12670 tree fld
, fld_init
;
12671 unsigned HOST_WIDE_INT i
;
12672 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), i
, fld
, fld_init
)
12677 if (TREE_CODE (fld
) == CONSTRUCTOR
)
12679 fld_init
= get_initializer_for (fld_init
, decl
);
12688 /* Determines the size of the member referenced by the COMPONENT_REF
12689 REF, using its initializer expression if necessary in order to
12690 determine the size of an initialized flexible array member.
12691 If non-null, set *ARK when REF refers to an interior zero-length
12692 array or a trailing one-element array.
12693 Returns the size as sizetype (which might be zero for an object
12694 with an uninitialized flexible array member) or null if the size
12695 cannot be determined. */
12698 component_ref_size (tree ref
, special_array_member
*sam
/* = NULL */)
12700 gcc_assert (TREE_CODE (ref
) == COMPONENT_REF
);
12702 special_array_member sambuf
;
12705 *sam
= special_array_member::none
;
12707 /* The object/argument referenced by the COMPONENT_REF and its type. */
12708 tree arg
= TREE_OPERAND (ref
, 0);
12709 tree argtype
= TREE_TYPE (arg
);
12710 /* The referenced member. */
12711 tree member
= TREE_OPERAND (ref
, 1);
12713 tree memsize
= DECL_SIZE_UNIT (member
);
12716 tree memtype
= TREE_TYPE (member
);
12717 if (TREE_CODE (memtype
) != ARRAY_TYPE
)
12718 /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
12719 to the type of a class with a virtual base which doesn't
12720 reflect the size of the virtual's members (see pr97595).
12721 If that's the case fail for now and implement something
12722 more robust in the future. */
12723 return (tree_int_cst_equal (memsize
, TYPE_SIZE_UNIT (memtype
))
12724 ? memsize
: NULL_TREE
);
12726 bool trailing
= array_at_struct_end_p (ref
);
12727 bool zero_length
= integer_zerop (memsize
);
12728 if (!trailing
&& !zero_length
)
12729 /* MEMBER is either an interior array or is an array with
12730 more than one element. */
12736 *sam
= special_array_member::trail_0
;
12739 *sam
= special_array_member::int_0
;
12740 memsize
= NULL_TREE
;
12745 if (tree dom
= TYPE_DOMAIN (memtype
))
12746 if (tree min
= TYPE_MIN_VALUE (dom
))
12747 if (tree max
= TYPE_MAX_VALUE (dom
))
12748 if (TREE_CODE (min
) == INTEGER_CST
12749 && TREE_CODE (max
) == INTEGER_CST
)
12751 offset_int minidx
= wi::to_offset (min
);
12752 offset_int maxidx
= wi::to_offset (max
);
12753 offset_int neltsm1
= maxidx
- minidx
;
12755 /* MEMBER is an array with more than one element. */
12759 *sam
= special_array_member::trail_1
;
12762 /* For a reference to a zero- or one-element array member of a union
12763 use the size of the union instead of the size of the member. */
12764 if (TREE_CODE (argtype
) == UNION_TYPE
)
12765 memsize
= TYPE_SIZE_UNIT (argtype
);
12768 /* MEMBER is either a bona fide flexible array member, or a zero-length
12769 array member, or an array of length one treated as such. */
12771 /* If the reference is to a declared object and the member a true
12772 flexible array, try to determine its size from its initializer. */
12773 poly_int64 baseoff
= 0;
12774 tree base
= get_addr_base_and_unit_offset (ref
, &baseoff
);
12775 if (!base
|| !VAR_P (base
))
12777 if (*sam
!= special_array_member::int_0
)
12780 if (TREE_CODE (arg
) != COMPONENT_REF
)
12784 while (TREE_CODE (base
) == COMPONENT_REF
)
12785 base
= TREE_OPERAND (base
, 0);
12786 baseoff
= tree_to_poly_int64 (byte_position (TREE_OPERAND (ref
, 1)));
12789 /* BASE is the declared object of which MEMBER is either a member
12790 or that is cast to ARGTYPE (e.g., a char buffer used to store
12791 an ARGTYPE object). */
12792 tree basetype
= TREE_TYPE (base
);
12794 /* Determine the base type of the referenced object. If it's
12795 the same as ARGTYPE and MEMBER has a known size, return it. */
12796 tree bt
= basetype
;
12797 if (*sam
!= special_array_member::int_0
)
12798 while (TREE_CODE (bt
) == ARRAY_TYPE
)
12799 bt
= TREE_TYPE (bt
);
12800 bool typematch
= useless_type_conversion_p (argtype
, bt
);
12801 if (memsize
&& typematch
)
12804 memsize
= NULL_TREE
;
12807 /* MEMBER is a true flexible array member. Compute its size from
12808 the initializer of the BASE object if it has one. */
12809 if (tree init
= DECL_P (base
) ? DECL_INITIAL (base
) : NULL_TREE
)
12810 if (init
!= error_mark_node
)
12812 init
= get_initializer_for (init
, member
);
12815 memsize
= TYPE_SIZE_UNIT (TREE_TYPE (init
));
12816 if (tree refsize
= TYPE_SIZE_UNIT (argtype
))
12818 /* Use the larger of the initializer size and the tail
12819 padding in the enclosing struct. */
12820 poly_int64 rsz
= tree_to_poly_int64 (refsize
);
12822 if (known_lt (tree_to_poly_int64 (memsize
), rsz
))
12823 memsize
= wide_int_to_tree (TREE_TYPE (memsize
), rsz
);
12835 && DECL_EXTERNAL (base
)
12837 && *sam
!= special_array_member::int_0
)
12838 /* The size of a flexible array member of an extern struct
12839 with no initializer cannot be determined (it's defined
12840 in another translation unit and can have an initializer
12841 with an arbitrary number of elements). */
12844 /* Use the size of the base struct or, for interior zero-length
12845 arrays, the size of the enclosing type. */
12846 memsize
= TYPE_SIZE_UNIT (bt
);
12848 else if (DECL_P (base
))
12849 /* Use the size of the BASE object (possibly an array of some
12850 other type such as char used to store the struct). */
12851 memsize
= DECL_SIZE_UNIT (base
);
12856 /* If the flexible array member has a known size use the greater
12857 of it and the tail padding in the enclosing struct.
12858 Otherwise, when the size of the flexible array member is unknown
12859 and the referenced object is not a struct, use the size of its
12860 type when known. This detects sizes of array buffers when cast
12861 to struct types with flexible array members. */
12864 poly_int64 memsz64
= memsize
? tree_to_poly_int64 (memsize
) : 0;
12865 if (known_lt (baseoff
, memsz64
))
12867 memsz64
-= baseoff
;
12868 return wide_int_to_tree (TREE_TYPE (memsize
), memsz64
);
12870 return size_zero_node
;
12873 /* Return "don't know" for an external non-array object since its
12874 flexible array member can be initialized to have any number of
12875 elements. Otherwise, return zero because the flexible array
12876 member has no elements. */
12877 return (DECL_P (base
)
12878 && DECL_EXTERNAL (base
)
12880 || TREE_CODE (basetype
) != ARRAY_TYPE
)
12881 ? NULL_TREE
: size_zero_node
);
12884 /* Return the machine mode of T. For vectors, returns the mode of the
12885 inner type. The main use case is to feed the result to HONOR_NANS,
12886 avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
12889 element_mode (const_tree t
)
12893 if (VECTOR_TYPE_P (t
) || TREE_CODE (t
) == COMPLEX_TYPE
)
12895 return TYPE_MODE (t
);
12898 /* Vector types need to re-check the target flags each time we report
12899 the machine mode. We need to do this because attribute target can
12900 change the result of vector_mode_supported_p and have_regs_of_mode
12901 on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
12902 change on a per-function basis. */
12903 /* ??? Possibly a better solution is to run through all the types
12904 referenced by a function and re-compute the TYPE_MODE once, rather
12905 than make the TYPE_MODE macro call a function. */
12908 vector_type_mode (const_tree t
)
12912 gcc_assert (TREE_CODE (t
) == VECTOR_TYPE
);
12914 mode
= t
->type_common
.mode
;
12915 if (VECTOR_MODE_P (mode
)
12916 && (!targetm
.vector_mode_supported_p (mode
)
12917 || !have_regs_of_mode
[mode
]))
12919 scalar_int_mode innermode
;
12921 /* For integers, try mapping it to a same-sized scalar mode. */
12922 if (is_int_mode (TREE_TYPE (t
)->type_common
.mode
, &innermode
))
12924 poly_int64 size
= (TYPE_VECTOR_SUBPARTS (t
)
12925 * GET_MODE_BITSIZE (innermode
));
12926 scalar_int_mode mode
;
12927 if (int_mode_for_size (size
, 0).exists (&mode
)
12928 && have_regs_of_mode
[mode
])
12938 /* Return the size in bits of each element of vector type TYPE. */
12941 vector_element_bits (const_tree type
)
12943 gcc_checking_assert (VECTOR_TYPE_P (type
));
12944 if (VECTOR_BOOLEAN_TYPE_P (type
))
12945 return TYPE_PRECISION (TREE_TYPE (type
));
12946 return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type
)));
12949 /* Calculate the size in bits of each element of vector type TYPE
12950 and return the result as a tree of type bitsizetype. */
12953 vector_element_bits_tree (const_tree type
)
12955 gcc_checking_assert (VECTOR_TYPE_P (type
));
12956 if (VECTOR_BOOLEAN_TYPE_P (type
))
12957 return bitsize_int (vector_element_bits (type
));
12958 return TYPE_SIZE (TREE_TYPE (type
));
12961 /* Verify that basic properties of T match TV and thus T can be a variant of
12962 TV. TV should be the more specified variant (i.e. the main variant). */
12965 verify_type_variant (const_tree t
, tree tv
)
12967 /* Type variant can differ by:
12969 - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
12970 ENCODE_QUAL_ADDR_SPACE.
12971 - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
12972 in this case some values may not be set in the variant types
12973 (see TYPE_COMPLETE_P checks).
12974 - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
12975 - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
12976 - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
12977 - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
12978 - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
12979 this is necessary to make it possible to merge types form different TUs
12980 - arrays, pointers and references may have TREE_TYPE that is a variant
12981 of TREE_TYPE of their main variants.
12982 - aggregates may have new TYPE_FIELDS list that list variants of
12983 the main variant TYPE_FIELDS.
12984 - vector types may differ by TYPE_VECTOR_OPAQUE
12987 /* Convenience macro for matching individual fields. */
12988 #define verify_variant_match(flag) \
12990 if (flag (tv) != flag (t)) \
12992 error ("type variant differs by %s", #flag); \
12998 /* tree_base checks. */
13000 verify_variant_match (TREE_CODE
);
13001 /* FIXME: Ada builds non-artificial variants of artificial types. */
13003 if (TYPE_ARTIFICIAL (tv
))
13004 verify_variant_match (TYPE_ARTIFICIAL
);
13006 if (POINTER_TYPE_P (tv
))
13007 verify_variant_match (TYPE_REF_CAN_ALIAS_ALL
);
13008 /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13009 verify_variant_match (TYPE_UNSIGNED
);
13010 verify_variant_match (TYPE_PACKED
);
13011 if (TREE_CODE (t
) == REFERENCE_TYPE
)
13012 verify_variant_match (TYPE_REF_IS_RVALUE
);
13013 if (AGGREGATE_TYPE_P (t
))
13014 verify_variant_match (TYPE_REVERSE_STORAGE_ORDER
);
13016 verify_variant_match (TYPE_SATURATING
);
13017 /* FIXME: This check trigger during libstdc++ build. */
13019 if (RECORD_OR_UNION_TYPE_P (t
) && COMPLETE_TYPE_P (t
))
13020 verify_variant_match (TYPE_FINAL_P
);
13023 /* tree_type_common checks. */
13025 if (COMPLETE_TYPE_P (t
))
13027 verify_variant_match (TYPE_MODE
);
13028 if (TREE_CODE (TYPE_SIZE (t
)) != PLACEHOLDER_EXPR
13029 && TREE_CODE (TYPE_SIZE (tv
)) != PLACEHOLDER_EXPR
)
13030 verify_variant_match (TYPE_SIZE
);
13031 if (TREE_CODE (TYPE_SIZE_UNIT (t
)) != PLACEHOLDER_EXPR
13032 && TREE_CODE (TYPE_SIZE_UNIT (tv
)) != PLACEHOLDER_EXPR
13033 && TYPE_SIZE_UNIT (t
) != TYPE_SIZE_UNIT (tv
))
13035 gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t
),
13036 TYPE_SIZE_UNIT (tv
), 0));
13037 error ("type variant has different %<TYPE_SIZE_UNIT%>");
13039 error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13040 debug_tree (TYPE_SIZE_UNIT (tv
));
13041 error ("type%'s %<TYPE_SIZE_UNIT%>");
13042 debug_tree (TYPE_SIZE_UNIT (t
));
13045 verify_variant_match (TYPE_NEEDS_CONSTRUCTING
);
13047 verify_variant_match (TYPE_PRECISION
);
13048 if (RECORD_OR_UNION_TYPE_P (t
))
13049 verify_variant_match (TYPE_TRANSPARENT_AGGR
);
13050 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13051 verify_variant_match (TYPE_NONALIASED_COMPONENT
);
13052 /* During LTO we merge variant lists from diferent translation units
13053 that may differ BY TYPE_CONTEXT that in turn may point
13054 to TRANSLATION_UNIT_DECL.
13055 Ada also builds variants of types with different TYPE_CONTEXT. */
13057 if (!in_lto_p
|| !TYPE_FILE_SCOPE_P (t
))
13058 verify_variant_match (TYPE_CONTEXT
);
13060 if (TREE_CODE (t
) == ARRAY_TYPE
|| TREE_CODE (t
) == INTEGER_TYPE
)
13061 verify_variant_match (TYPE_STRING_FLAG
);
13062 if (TREE_CODE (t
) == RECORD_TYPE
|| TREE_CODE (t
) == UNION_TYPE
)
13063 verify_variant_match (TYPE_CXX_ODR_P
);
13064 if (TYPE_ALIAS_SET_KNOWN_P (t
))
13066 error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13071 /* tree_type_non_common checks. */
13073 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13074 and dangle the pointer from time to time. */
13075 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_VFIELD (t
) != TYPE_VFIELD (tv
)
13076 && (in_lto_p
|| !TYPE_VFIELD (tv
)
13077 || TREE_CODE (TYPE_VFIELD (tv
)) != TREE_LIST
))
13079 error ("type variant has different %<TYPE_VFIELD%>");
13083 if ((TREE_CODE (t
) == ENUMERAL_TYPE
&& COMPLETE_TYPE_P (t
))
13084 || TREE_CODE (t
) == INTEGER_TYPE
13085 || TREE_CODE (t
) == BOOLEAN_TYPE
13086 || TREE_CODE (t
) == REAL_TYPE
13087 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13089 verify_variant_match (TYPE_MAX_VALUE
);
13090 verify_variant_match (TYPE_MIN_VALUE
);
13092 if (TREE_CODE (t
) == METHOD_TYPE
)
13093 verify_variant_match (TYPE_METHOD_BASETYPE
);
13094 if (TREE_CODE (t
) == OFFSET_TYPE
)
13095 verify_variant_match (TYPE_OFFSET_BASETYPE
);
13096 if (TREE_CODE (t
) == ARRAY_TYPE
)
13097 verify_variant_match (TYPE_ARRAY_MAX_SIZE
);
13098 /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13099 or even type's main variant. This is needed to make bootstrap pass
13100 and the bug seems new in GCC 5.
13101 C++ FE should be updated to make this consistent and we should check
13102 that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13103 is a match with main variant.
13105 Also disable the check for Java for now because of parser hack that builds
13106 first an dummy BINFO and then sometimes replace it by real BINFO in some
13108 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
) && TYPE_BINFO (tv
)
13109 && TYPE_BINFO (t
) != TYPE_BINFO (tv
)
13110 /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13111 Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13112 at LTO time only. */
13113 && (in_lto_p
&& odr_type_p (t
)))
13115 error ("type variant has different %<TYPE_BINFO%>");
13117 error ("type variant%'s %<TYPE_BINFO%>");
13118 debug_tree (TYPE_BINFO (tv
));
13119 error ("type%'s %<TYPE_BINFO%>");
13120 debug_tree (TYPE_BINFO (t
));
13124 /* Check various uses of TYPE_VALUES_RAW. */
13125 if (TREE_CODE (t
) == ENUMERAL_TYPE
13126 && TYPE_VALUES (t
))
13127 verify_variant_match (TYPE_VALUES
);
13128 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13129 verify_variant_match (TYPE_DOMAIN
);
13130 /* Permit incomplete variants of complete type. While FEs may complete
13131 all variants, this does not happen for C++ templates in all cases. */
13132 else if (RECORD_OR_UNION_TYPE_P (t
)
13133 && COMPLETE_TYPE_P (t
)
13134 && TYPE_FIELDS (t
) != TYPE_FIELDS (tv
))
13138 /* Fortran builds qualified variants as new records with items of
13139 qualified type. Verify that they looks same. */
13140 for (f1
= TYPE_FIELDS (t
), f2
= TYPE_FIELDS (tv
);
13142 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
13143 if (TREE_CODE (f1
) != FIELD_DECL
|| TREE_CODE (f2
) != FIELD_DECL
13144 || (TYPE_MAIN_VARIANT (TREE_TYPE (f1
))
13145 != TYPE_MAIN_VARIANT (TREE_TYPE (f2
))
13146 /* FIXME: gfc_nonrestricted_type builds all types as variants
13147 with exception of pointer types. It deeply copies the type
13148 which means that we may end up with a variant type
13149 referring non-variant pointer. We may change it to
13150 produce types as variants, too, like
13151 objc_get_protocol_qualified_type does. */
13152 && !POINTER_TYPE_P (TREE_TYPE (f1
)))
13153 || DECL_FIELD_OFFSET (f1
) != DECL_FIELD_OFFSET (f2
)
13154 || DECL_FIELD_BIT_OFFSET (f1
) != DECL_FIELD_BIT_OFFSET (f2
))
13158 error ("type variant has different %<TYPE_FIELDS%>");
13160 error ("first mismatch is field");
13162 error ("and field");
13167 else if ((TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
))
13168 verify_variant_match (TYPE_ARG_TYPES
);
13169 /* For C++ the qualified variant of array type is really an array type
13170 of qualified TREE_TYPE.
13171 objc builds variants of pointer where pointer to type is a variant, too
13172 in objc_get_protocol_qualified_type. */
13173 if (TREE_TYPE (t
) != TREE_TYPE (tv
)
13174 && ((TREE_CODE (t
) != ARRAY_TYPE
13175 && !POINTER_TYPE_P (t
))
13176 || TYPE_MAIN_VARIANT (TREE_TYPE (t
))
13177 != TYPE_MAIN_VARIANT (TREE_TYPE (tv
))))
13179 error ("type variant has different %<TREE_TYPE%>");
13181 error ("type variant%'s %<TREE_TYPE%>");
13182 debug_tree (TREE_TYPE (tv
));
13183 error ("type%'s %<TREE_TYPE%>");
13184 debug_tree (TREE_TYPE (t
));
13187 if (type_with_alias_set_p (t
)
13188 && !gimple_canonical_types_compatible_p (t
, tv
, false))
13190 error ("type is not compatible with its variant");
13192 error ("type variant%'s %<TREE_TYPE%>");
13193 debug_tree (TREE_TYPE (tv
));
13194 error ("type%'s %<TREE_TYPE%>");
13195 debug_tree (TREE_TYPE (t
));
13199 #undef verify_variant_match
13203 /* The TYPE_CANONICAL merging machinery. It should closely resemble
13204 the middle-end types_compatible_p function. It needs to avoid
13205 claiming types are different for types that should be treated
13206 the same with respect to TBAA. Canonical types are also used
13207 for IL consistency checks via the useless_type_conversion_p
13208 predicate which does not handle all type kinds itself but falls
13209 back to pointer-comparison of TYPE_CANONICAL for aggregates
13212 /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13213 type calculation because we need to allow inter-operability between signed
13214 and unsigned variants. */
13217 type_with_interoperable_signedness (const_tree type
)
13219 /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13220 signed char and unsigned char. Similarly fortran FE builds
13221 C_SIZE_T as signed type, while C defines it unsigned. */
13223 return tree_code_for_canonical_type_merging (TREE_CODE (type
))
13225 && (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
)
13226 || TYPE_PRECISION (type
) == TYPE_PRECISION (size_type_node
));
13229 /* Return true iff T1 and T2 are structurally identical for what
13231 This function is used both by lto.cc canonical type merging and by the
13232 verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13233 that have TYPE_CANONICAL defined and assume them equivalent. This is useful
13234 only for LTO because only in these cases TYPE_CANONICAL equivalence
13235 correspond to one defined by gimple_canonical_types_compatible_p. */
13238 gimple_canonical_types_compatible_p (const_tree t1
, const_tree t2
,
13239 bool trust_type_canonical
)
13241 /* Type variants should be same as the main variant. When not doing sanity
13242 checking to verify this fact, go to main variants and save some work. */
13243 if (trust_type_canonical
)
13245 t1
= TYPE_MAIN_VARIANT (t1
);
13246 t2
= TYPE_MAIN_VARIANT (t2
);
13249 /* Check first for the obvious case of pointer identity. */
13253 /* Check that we have two types to compare. */
13254 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
13257 /* We consider complete types always compatible with incomplete type.
13258 This does not make sense for canonical type calculation and thus we
13259 need to ensure that we are never called on it.
13261 FIXME: For more correctness the function probably should have three modes
13262 1) mode assuming that types are complete mathcing their structure
13263 2) mode allowing incomplete types but producing equivalence classes
13264 and thus ignoring all info from complete types
13265 3) mode allowing incomplete types to match complete but checking
13266 compatibility between complete types.
13268 1 and 2 can be used for canonical type calculation. 3 is the real
13269 definition of type compatibility that can be used i.e. for warnings during
13270 declaration merging. */
13272 gcc_assert (!trust_type_canonical
13273 || (type_with_alias_set_p (t1
) && type_with_alias_set_p (t2
)));
13275 /* If the types have been previously registered and found equal
13278 if (TYPE_CANONICAL (t1
) && TYPE_CANONICAL (t2
)
13279 && trust_type_canonical
)
13281 /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
13282 they are always NULL, but they are set to non-NULL for types
13283 constructed by build_pointer_type and variants. In this case the
13284 TYPE_CANONICAL is more fine grained than the equivalnce we test (where
13285 all pointers are considered equal. Be sure to not return false
13287 gcc_checking_assert (canonical_type_used_p (t1
)
13288 && canonical_type_used_p (t2
));
13289 return TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
);
13292 /* For types where we do ODR based TBAA the canonical type is always
13293 set correctly, so we know that types are different if their
13294 canonical types does not match. */
13295 if (trust_type_canonical
13296 && (odr_type_p (t1
) && odr_based_tbaa_p (t1
))
13297 != (odr_type_p (t2
) && odr_based_tbaa_p (t2
)))
13300 /* Can't be the same type if the types don't have the same code. */
13301 enum tree_code code
= tree_code_for_canonical_type_merging (TREE_CODE (t1
));
13302 if (code
!= tree_code_for_canonical_type_merging (TREE_CODE (t2
)))
13305 /* Qualifiers do not matter for canonical type comparison purposes. */
13307 /* Void types and nullptr types are always the same. */
13308 if (TREE_CODE (t1
) == VOID_TYPE
13309 || TREE_CODE (t1
) == NULLPTR_TYPE
)
13312 /* Can't be the same type if they have different mode. */
13313 if (TYPE_MODE (t1
) != TYPE_MODE (t2
))
13316 /* Non-aggregate types can be handled cheaply. */
13317 if (INTEGRAL_TYPE_P (t1
)
13318 || SCALAR_FLOAT_TYPE_P (t1
)
13319 || FIXED_POINT_TYPE_P (t1
)
13320 || TREE_CODE (t1
) == VECTOR_TYPE
13321 || TREE_CODE (t1
) == COMPLEX_TYPE
13322 || TREE_CODE (t1
) == OFFSET_TYPE
13323 || POINTER_TYPE_P (t1
))
13325 /* Can't be the same type if they have different recision. */
13326 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
))
13329 /* In some cases the signed and unsigned types are required to be
13331 if (TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
)
13332 && !type_with_interoperable_signedness (t1
))
13335 /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
13336 interoperable with "signed char". Unless all frontends are revisited
13337 to agree on these types, we must ignore the flag completely. */
13339 /* Fortran standard define C_PTR type that is compatible with every
13340 C pointer. For this reason we need to glob all pointers into one.
13341 Still pointers in different address spaces are not compatible. */
13342 if (POINTER_TYPE_P (t1
))
13344 if (TYPE_ADDR_SPACE (TREE_TYPE (t1
))
13345 != TYPE_ADDR_SPACE (TREE_TYPE (t2
)))
13349 /* Tail-recurse to components. */
13350 if (TREE_CODE (t1
) == VECTOR_TYPE
13351 || TREE_CODE (t1
) == COMPLEX_TYPE
)
13352 return gimple_canonical_types_compatible_p (TREE_TYPE (t1
),
13354 trust_type_canonical
);
13359 /* Do type-specific comparisons. */
13360 switch (TREE_CODE (t1
))
13363 /* Array types are the same if the element types are the same and
13364 the number of elements are the same. */
13365 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13366 trust_type_canonical
)
13367 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
13368 || TYPE_REVERSE_STORAGE_ORDER (t1
) != TYPE_REVERSE_STORAGE_ORDER (t2
)
13369 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
13373 tree i1
= TYPE_DOMAIN (t1
);
13374 tree i2
= TYPE_DOMAIN (t2
);
13376 /* For an incomplete external array, the type domain can be
13377 NULL_TREE. Check this condition also. */
13378 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
13380 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
13384 tree min1
= TYPE_MIN_VALUE (i1
);
13385 tree min2
= TYPE_MIN_VALUE (i2
);
13386 tree max1
= TYPE_MAX_VALUE (i1
);
13387 tree max2
= TYPE_MAX_VALUE (i2
);
13389 /* The minimum/maximum values have to be the same. */
13392 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
13393 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
13394 || operand_equal_p (min1
, min2
, 0))))
13397 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
13398 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
13399 || operand_equal_p (max1
, max2
, 0)))))
13407 case FUNCTION_TYPE
:
13408 /* Function types are the same if the return type and arguments types
13410 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
),
13411 trust_type_canonical
))
13414 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
13418 tree parms1
, parms2
;
13420 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
13422 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
13424 if (!gimple_canonical_types_compatible_p
13425 (TREE_VALUE (parms1
), TREE_VALUE (parms2
),
13426 trust_type_canonical
))
13430 if (parms1
|| parms2
)
13438 case QUAL_UNION_TYPE
:
13442 /* Don't try to compare variants of an incomplete type, before
13443 TYPE_FIELDS has been copied around. */
13444 if (!COMPLETE_TYPE_P (t1
) && !COMPLETE_TYPE_P (t2
))
13448 if (TYPE_REVERSE_STORAGE_ORDER (t1
) != TYPE_REVERSE_STORAGE_ORDER (t2
))
13451 /* For aggregate types, all the fields must be the same. */
13452 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
13454 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
13456 /* Skip non-fields and zero-sized fields. */
13457 while (f1
&& (TREE_CODE (f1
) != FIELD_DECL
13459 && integer_zerop (DECL_SIZE (f1
)))))
13460 f1
= TREE_CHAIN (f1
);
13461 while (f2
&& (TREE_CODE (f2
) != FIELD_DECL
13463 && integer_zerop (DECL_SIZE (f2
)))))
13464 f2
= TREE_CHAIN (f2
);
13467 /* The fields must have the same name, offset and type. */
13468 if (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
13469 || !gimple_compare_field_offset (f1
, f2
)
13470 || !gimple_canonical_types_compatible_p
13471 (TREE_TYPE (f1
), TREE_TYPE (f2
),
13472 trust_type_canonical
))
13476 /* If one aggregate has more fields than the other, they
13477 are not the same. */
13485 /* Consider all types with language specific trees in them mutually
13486 compatible. This is executed only from verify_type and false
13487 positives can be tolerated. */
13488 gcc_assert (!in_lto_p
);
13493 /* Verify type T. */
13496 verify_type (const_tree t
)
13498 bool error_found
= false;
13499 tree mv
= TYPE_MAIN_VARIANT (t
);
13502 error ("main variant is not defined");
13503 error_found
= true;
13505 else if (mv
!= TYPE_MAIN_VARIANT (mv
))
13507 error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
13509 error_found
= true;
13511 else if (t
!= mv
&& !verify_type_variant (t
, mv
))
13512 error_found
= true;
13514 tree ct
= TYPE_CANONICAL (t
);
13517 else if (TYPE_CANONICAL (ct
) != ct
)
13519 error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
13521 error_found
= true;
13523 /* Method and function types cannot be used to address memory and thus
13524 TYPE_CANONICAL really matters only for determining useless conversions.
13526 FIXME: C++ FE produce declarations of builtin functions that are not
13527 compatible with main variants. */
13528 else if (TREE_CODE (t
) == FUNCTION_TYPE
)
13531 /* FIXME: gimple_canonical_types_compatible_p cannot compare types
13532 with variably sized arrays because their sizes possibly
13533 gimplified to different variables. */
13534 && !variably_modified_type_p (ct
, NULL
)
13535 && !gimple_canonical_types_compatible_p (t
, ct
, false)
13536 && COMPLETE_TYPE_P (t
))
13538 error ("%<TYPE_CANONICAL%> is not compatible");
13540 error_found
= true;
13543 if (COMPLETE_TYPE_P (t
) && TYPE_CANONICAL (t
)
13544 && TYPE_MODE (t
) != TYPE_MODE (TYPE_CANONICAL (t
)))
13546 error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
13548 error_found
= true;
13550 if (TYPE_MAIN_VARIANT (t
) == t
&& ct
&& TYPE_MAIN_VARIANT (ct
) != ct
)
13552 error ("%<TYPE_CANONICAL%> of main variant is not main variant");
13554 debug_tree (TYPE_MAIN_VARIANT (ct
));
13555 error_found
= true;
13559 /* Check various uses of TYPE_MIN_VALUE_RAW. */
13560 if (RECORD_OR_UNION_TYPE_P (t
))
13562 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13563 and danagle the pointer from time to time. */
13564 if (TYPE_VFIELD (t
)
13565 && TREE_CODE (TYPE_VFIELD (t
)) != FIELD_DECL
13566 && TREE_CODE (TYPE_VFIELD (t
)) != TREE_LIST
)
13568 error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
13569 debug_tree (TYPE_VFIELD (t
));
13570 error_found
= true;
13573 else if (TREE_CODE (t
) == POINTER_TYPE
)
13575 if (TYPE_NEXT_PTR_TO (t
)
13576 && TREE_CODE (TYPE_NEXT_PTR_TO (t
)) != POINTER_TYPE
)
13578 error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
13579 debug_tree (TYPE_NEXT_PTR_TO (t
));
13580 error_found
= true;
13583 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
13585 if (TYPE_NEXT_REF_TO (t
)
13586 && TREE_CODE (TYPE_NEXT_REF_TO (t
)) != REFERENCE_TYPE
)
13588 error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
13589 debug_tree (TYPE_NEXT_REF_TO (t
));
13590 error_found
= true;
13593 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13594 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13596 /* FIXME: The following check should pass:
13597 useless_type_conversion_p (const_cast <tree> (t),
13598 TREE_TYPE (TYPE_MIN_VALUE (t))
13599 but does not for C sizetypes in LTO. */
13602 /* Check various uses of TYPE_MAXVAL_RAW. */
13603 if (RECORD_OR_UNION_TYPE_P (t
))
13605 if (!TYPE_BINFO (t
))
13607 else if (TREE_CODE (TYPE_BINFO (t
)) != TREE_BINFO
)
13609 error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
13610 debug_tree (TYPE_BINFO (t
));
13611 error_found
= true;
13613 else if (TREE_TYPE (TYPE_BINFO (t
)) != TYPE_MAIN_VARIANT (t
))
13615 error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
13616 debug_tree (TREE_TYPE (TYPE_BINFO (t
)));
13617 error_found
= true;
13620 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13622 if (TYPE_METHOD_BASETYPE (t
)
13623 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != RECORD_TYPE
13624 && TREE_CODE (TYPE_METHOD_BASETYPE (t
)) != UNION_TYPE
)
13626 error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
13627 debug_tree (TYPE_METHOD_BASETYPE (t
));
13628 error_found
= true;
13631 else if (TREE_CODE (t
) == OFFSET_TYPE
)
13633 if (TYPE_OFFSET_BASETYPE (t
)
13634 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != RECORD_TYPE
13635 && TREE_CODE (TYPE_OFFSET_BASETYPE (t
)) != UNION_TYPE
)
13637 error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
13638 debug_tree (TYPE_OFFSET_BASETYPE (t
));
13639 error_found
= true;
13642 else if (INTEGRAL_TYPE_P (t
) || TREE_CODE (t
) == REAL_TYPE
13643 || TREE_CODE (t
) == FIXED_POINT_TYPE
)
13645 /* FIXME: The following check should pass:
13646 useless_type_conversion_p (const_cast <tree> (t),
13647 TREE_TYPE (TYPE_MAX_VALUE (t))
13648 but does not for C sizetypes in LTO. */
13650 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13652 if (TYPE_ARRAY_MAX_SIZE (t
)
13653 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t
)) != INTEGER_CST
)
13655 error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
13656 debug_tree (TYPE_ARRAY_MAX_SIZE (t
));
13657 error_found
= true;
13660 else if (TYPE_MAX_VALUE_RAW (t
))
13662 error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
13663 debug_tree (TYPE_MAX_VALUE_RAW (t
));
13664 error_found
= true;
13667 if (TYPE_LANG_SLOT_1 (t
) && in_lto_p
)
13669 error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
13670 debug_tree (TYPE_LANG_SLOT_1 (t
));
13671 error_found
= true;
13674 /* Check various uses of TYPE_VALUES_RAW. */
13675 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
13676 for (tree l
= TYPE_VALUES (t
); l
; l
= TREE_CHAIN (l
))
13678 tree value
= TREE_VALUE (l
);
13679 tree name
= TREE_PURPOSE (l
);
13681 /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
13682 CONST_DECL of ENUMERAL TYPE. */
13683 if (TREE_CODE (value
) != INTEGER_CST
&& TREE_CODE (value
) != CONST_DECL
)
13685 error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
13686 debug_tree (value
);
13688 error_found
= true;
13690 if (TREE_CODE (TREE_TYPE (value
)) != INTEGER_TYPE
13691 && TREE_CODE (TREE_TYPE (value
)) != BOOLEAN_TYPE
13692 && !useless_type_conversion_p (const_cast <tree
> (t
), TREE_TYPE (value
)))
13694 error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
13696 debug_tree (value
);
13698 error_found
= true;
13700 if (TREE_CODE (name
) != IDENTIFIER_NODE
)
13702 error ("enum value name is not %<IDENTIFIER_NODE%>");
13703 debug_tree (value
);
13705 error_found
= true;
13708 else if (TREE_CODE (t
) == ARRAY_TYPE
)
13710 if (TYPE_DOMAIN (t
) && TREE_CODE (TYPE_DOMAIN (t
)) != INTEGER_TYPE
)
13712 error ("array %<TYPE_DOMAIN%> is not integer type");
13713 debug_tree (TYPE_DOMAIN (t
));
13714 error_found
= true;
13717 else if (RECORD_OR_UNION_TYPE_P (t
))
13719 if (TYPE_FIELDS (t
) && !COMPLETE_TYPE_P (t
) && in_lto_p
)
13721 error ("%<TYPE_FIELDS%> defined in incomplete type");
13722 error_found
= true;
13724 for (tree fld
= TYPE_FIELDS (t
); fld
; fld
= TREE_CHAIN (fld
))
13726 /* TODO: verify properties of decls. */
13727 if (TREE_CODE (fld
) == FIELD_DECL
)
13729 else if (TREE_CODE (fld
) == TYPE_DECL
)
13731 else if (TREE_CODE (fld
) == CONST_DECL
)
13733 else if (VAR_P (fld
))
13735 else if (TREE_CODE (fld
) == TEMPLATE_DECL
)
13737 else if (TREE_CODE (fld
) == USING_DECL
)
13739 else if (TREE_CODE (fld
) == FUNCTION_DECL
)
13743 error ("wrong tree in %<TYPE_FIELDS%> list");
13745 error_found
= true;
13749 else if (TREE_CODE (t
) == INTEGER_TYPE
13750 || TREE_CODE (t
) == BOOLEAN_TYPE
13751 || TREE_CODE (t
) == OFFSET_TYPE
13752 || TREE_CODE (t
) == REFERENCE_TYPE
13753 || TREE_CODE (t
) == NULLPTR_TYPE
13754 || TREE_CODE (t
) == POINTER_TYPE
)
13756 if (TYPE_CACHED_VALUES_P (t
) != (TYPE_CACHED_VALUES (t
) != NULL
))
13758 error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
13760 TYPE_CACHED_VALUES_P (t
), (void *)TYPE_CACHED_VALUES (t
));
13761 error_found
= true;
13763 else if (TYPE_CACHED_VALUES_P (t
) && TREE_CODE (TYPE_CACHED_VALUES (t
)) != TREE_VEC
)
13765 error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
13766 debug_tree (TYPE_CACHED_VALUES (t
));
13767 error_found
= true;
13769 /* Verify just enough of cache to ensure that no one copied it to new type.
13770 All copying should go by copy_node that should clear it. */
13771 else if (TYPE_CACHED_VALUES_P (t
))
13774 for (i
= 0; i
< TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t
)); i
++)
13775 if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)
13776 && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
)) != t
)
13778 error ("wrong %<TYPE_CACHED_VALUES%> entry");
13779 debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t
), i
));
13780 error_found
= true;
13785 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
13786 for (tree l
= TYPE_ARG_TYPES (t
); l
; l
= TREE_CHAIN (l
))
13788 /* C++ FE uses TREE_PURPOSE to store initial values. */
13789 if (TREE_PURPOSE (l
) && in_lto_p
)
13791 error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
13793 error_found
= true;
13795 if (!TYPE_P (TREE_VALUE (l
)))
13797 error ("wrong entry in %<TYPE_ARG_TYPES%> list");
13799 error_found
= true;
13802 else if (!is_lang_specific (t
) && TYPE_VALUES_RAW (t
))
13804 error ("%<TYPE_VALUES_RAW%> field is non-NULL");
13805 debug_tree (TYPE_VALUES_RAW (t
));
13806 error_found
= true;
13808 if (TREE_CODE (t
) != INTEGER_TYPE
13809 && TREE_CODE (t
) != BOOLEAN_TYPE
13810 && TREE_CODE (t
) != OFFSET_TYPE
13811 && TREE_CODE (t
) != REFERENCE_TYPE
13812 && TREE_CODE (t
) != NULLPTR_TYPE
13813 && TREE_CODE (t
) != POINTER_TYPE
13814 && TYPE_CACHED_VALUES_P (t
))
13816 error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
13817 error_found
= true;
13820 /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
13821 TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
13823 if (TREE_CODE (t
) == METHOD_TYPE
13824 && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t
)) != TYPE_METHOD_BASETYPE (t
))
13826 error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
13827 error_found
= true;
13832 debug_tree (const_cast <tree
> (t
));
13833 internal_error ("%qs failed", __func__
);
13838 /* Return 1 if ARG interpreted as signed in its precision is known to be
13839 always positive or 2 if ARG is known to be always negative, or 3 if
13840 ARG may be positive or negative. */
13843 get_range_pos_neg (tree arg
)
13845 if (arg
== error_mark_node
)
13848 int prec
= TYPE_PRECISION (TREE_TYPE (arg
));
13850 if (TREE_CODE (arg
) == INTEGER_CST
)
13852 wide_int w
= wi::sext (wi::to_wide (arg
), prec
);
13858 while (CONVERT_EXPR_P (arg
)
13859 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg
, 0)))
13860 && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg
, 0))) <= prec
)
13862 arg
= TREE_OPERAND (arg
, 0);
13863 /* Narrower value zero extended into wider type
13864 will always result in positive values. */
13865 if (TYPE_UNSIGNED (TREE_TYPE (arg
))
13866 && TYPE_PRECISION (TREE_TYPE (arg
)) < prec
)
13868 prec
= TYPE_PRECISION (TREE_TYPE (arg
));
13873 if (TREE_CODE (arg
) != SSA_NAME
)
13876 while (!get_global_range_query ()->range_of_expr (r
, arg
) || r
.kind () != VR_RANGE
)
13878 gimple
*g
= SSA_NAME_DEF_STMT (arg
);
13879 if (is_gimple_assign (g
)
13880 && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g
)))
13882 tree t
= gimple_assign_rhs1 (g
);
13883 if (INTEGRAL_TYPE_P (TREE_TYPE (t
))
13884 && TYPE_PRECISION (TREE_TYPE (t
)) <= prec
)
13886 if (TYPE_UNSIGNED (TREE_TYPE (t
))
13887 && TYPE_PRECISION (TREE_TYPE (t
)) < prec
)
13889 prec
= TYPE_PRECISION (TREE_TYPE (t
));
13898 if (TYPE_UNSIGNED (TREE_TYPE (arg
)))
13900 /* For unsigned values, the "positive" range comes
13901 below the "negative" range. */
13902 if (!wi::neg_p (wi::sext (r
.upper_bound (), prec
), SIGNED
))
13904 if (wi::neg_p (wi::sext (r
.lower_bound (), prec
), SIGNED
))
13909 if (!wi::neg_p (wi::sext (r
.lower_bound (), prec
), SIGNED
))
13911 if (wi::neg_p (wi::sext (r
.upper_bound (), prec
), SIGNED
))
13920 /* Return true if ARG is marked with the nonnull attribute in the
13921 current function signature. */
13924 nonnull_arg_p (const_tree arg
)
13926 tree t
, attrs
, fntype
;
13927 unsigned HOST_WIDE_INT arg_num
;
13929 gcc_assert (TREE_CODE (arg
) == PARM_DECL
13930 && (POINTER_TYPE_P (TREE_TYPE (arg
))
13931 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
));
13933 /* The static chain decl is always non null. */
13934 if (arg
== cfun
->static_chain_decl
)
13937 /* THIS argument of method is always non-NULL. */
13938 if (TREE_CODE (TREE_TYPE (cfun
->decl
)) == METHOD_TYPE
13939 && arg
== DECL_ARGUMENTS (cfun
->decl
)
13940 && flag_delete_null_pointer_checks
)
13943 /* Values passed by reference are always non-NULL. */
13944 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
13945 && flag_delete_null_pointer_checks
)
13948 fntype
= TREE_TYPE (cfun
->decl
);
13949 for (attrs
= TYPE_ATTRIBUTES (fntype
); attrs
; attrs
= TREE_CHAIN (attrs
))
13951 attrs
= lookup_attribute ("nonnull", attrs
);
13953 /* If "nonnull" wasn't specified, we know nothing about the argument. */
13954 if (attrs
== NULL_TREE
)
13957 /* If "nonnull" applies to all the arguments, then ARG is non-null. */
13958 if (TREE_VALUE (attrs
) == NULL_TREE
)
13961 /* Get the position number for ARG in the function signature. */
13962 for (arg_num
= 1, t
= DECL_ARGUMENTS (cfun
->decl
);
13964 t
= DECL_CHAIN (t
), arg_num
++)
13970 gcc_assert (t
== arg
);
13972 /* Now see if ARG_NUM is mentioned in the nonnull list. */
13973 for (t
= TREE_VALUE (attrs
); t
; t
= TREE_CHAIN (t
))
13975 if (compare_tree_int (TREE_VALUE (t
), arg_num
) == 0)
13983 /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
13987 set_block (location_t loc
, tree block
)
13989 location_t pure_loc
= get_pure_location (loc
);
13990 source_range src_range
= get_range_from_loc (line_table
, loc
);
13991 return COMBINE_LOCATION_DATA (line_table
, pure_loc
, src_range
, block
);
13995 set_source_range (tree expr
, location_t start
, location_t finish
)
13997 source_range src_range
;
13998 src_range
.m_start
= start
;
13999 src_range
.m_finish
= finish
;
14000 return set_source_range (expr
, src_range
);
14004 set_source_range (tree expr
, source_range src_range
)
14006 if (!EXPR_P (expr
))
14007 return UNKNOWN_LOCATION
;
14009 location_t pure_loc
= get_pure_location (EXPR_LOCATION (expr
));
14010 location_t adhoc
= COMBINE_LOCATION_DATA (line_table
,
14014 SET_EXPR_LOCATION (expr
, adhoc
);
14018 /* Return EXPR, potentially wrapped with a node expression LOC,
14019 if !CAN_HAVE_LOCATION_P (expr).
14021 NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14022 VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14024 Wrapper nodes can be identified using location_wrapper_p. */
14027 maybe_wrap_with_location (tree expr
, location_t loc
)
14031 if (loc
== UNKNOWN_LOCATION
)
14033 if (CAN_HAVE_LOCATION_P (expr
))
14035 /* We should only be adding wrappers for constants and for decls,
14036 or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14037 gcc_assert (CONSTANT_CLASS_P (expr
)
14039 || EXCEPTIONAL_CLASS_P (expr
));
14041 /* For now, don't add wrappers to exceptional tree nodes, to minimize
14042 any impact of the wrapper nodes. */
14043 if (EXCEPTIONAL_CLASS_P (expr
))
14046 /* Compiler-generated temporary variables don't need a wrapper. */
14047 if (DECL_P (expr
) && DECL_ARTIFICIAL (expr
) && DECL_IGNORED_P (expr
))
14050 /* If any auto_suppress_location_wrappers are active, don't create
14052 if (suppress_location_wrappers
> 0)
14056 = (((CONSTANT_CLASS_P (expr
) && TREE_CODE (expr
) != STRING_CST
)
14057 || (TREE_CODE (expr
) == CONST_DECL
&& !TREE_STATIC (expr
)))
14058 ? NON_LVALUE_EXPR
: VIEW_CONVERT_EXPR
);
14059 tree wrapper
= build1_loc (loc
, code
, TREE_TYPE (expr
), expr
);
14060 /* Mark this node as being a wrapper. */
14061 EXPR_LOCATION_WRAPPER_P (wrapper
) = 1;
14065 int suppress_location_wrappers
;
14067 /* Return the name of combined function FN, for debugging purposes. */
14070 combined_fn_name (combined_fn fn
)
14072 if (builtin_fn_p (fn
))
14074 tree fndecl
= builtin_decl_explicit (as_builtin_fn (fn
));
14075 return IDENTIFIER_POINTER (DECL_NAME (fndecl
));
14078 return internal_fn_name (as_internal_fn (fn
));
14081 /* Return a bitmap with a bit set corresponding to each argument in
14082 a function call type FNTYPE declared with attribute nonnull,
14083 or null if none of the function's argument are nonnull. The caller
14084 must free the bitmap. */
14087 get_nonnull_args (const_tree fntype
)
14089 if (fntype
== NULL_TREE
)
14092 bitmap argmap
= NULL
;
14093 if (TREE_CODE (fntype
) == METHOD_TYPE
)
14095 /* The this pointer in C++ non-static member functions is
14096 implicitly nonnull whether or not it's declared as such. */
14097 argmap
= BITMAP_ALLOC (NULL
);
14098 bitmap_set_bit (argmap
, 0);
14101 tree attrs
= TYPE_ATTRIBUTES (fntype
);
14105 /* A function declaration can specify multiple attribute nonnull,
14106 each with zero or more arguments. The loop below creates a bitmap
14107 representing a union of all the arguments. An empty (but non-null)
14108 bitmap means that all arguments have been declaraed nonnull. */
14109 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
14111 attrs
= lookup_attribute ("nonnull", attrs
);
14116 argmap
= BITMAP_ALLOC (NULL
);
14118 if (!TREE_VALUE (attrs
))
14120 /* Clear the bitmap in case a previous attribute nonnull
14121 set it and this one overrides it for all arguments. */
14122 bitmap_clear (argmap
);
14126 /* Iterate over the indices of the format arguments declared nonnull
14127 and set a bit for each. */
14128 for (tree idx
= TREE_VALUE (attrs
); idx
; idx
= TREE_CHAIN (idx
))
14130 unsigned int val
= TREE_INT_CST_LOW (TREE_VALUE (idx
)) - 1;
14131 bitmap_set_bit (argmap
, val
);
14138 /* Returns true if TYPE is a type where it and all of its subobjects
14139 (recursively) are of structure, union, or array type. */
14142 is_empty_type (const_tree type
)
14144 if (RECORD_OR_UNION_TYPE_P (type
))
14146 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
14147 if (TREE_CODE (field
) == FIELD_DECL
14148 && !DECL_PADDING_P (field
)
14149 && !is_empty_type (TREE_TYPE (field
)))
14153 else if (TREE_CODE (type
) == ARRAY_TYPE
)
14154 return (integer_minus_onep (array_type_nelts (type
))
14155 || TYPE_DOMAIN (type
) == NULL_TREE
14156 || is_empty_type (TREE_TYPE (type
)));
14160 /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
14161 that shouldn't be passed via stack. */
14164 default_is_empty_record (const_tree type
)
14166 if (!abi_version_at_least (12))
14169 if (type
== error_mark_node
)
14172 if (TREE_ADDRESSABLE (type
))
14175 return is_empty_type (TYPE_MAIN_VARIANT (type
));
14178 /* Determine whether TYPE is a structure with a flexible array member,
14179 or a union containing such a structure (possibly recursively). */
14182 flexible_array_type_p (const_tree type
)
14185 switch (TREE_CODE (type
))
14189 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= DECL_CHAIN (x
))
14190 if (TREE_CODE (x
) == FIELD_DECL
)
14192 if (last
== NULL_TREE
)
14194 if (TREE_CODE (TREE_TYPE (last
)) == ARRAY_TYPE
14195 && TYPE_SIZE (TREE_TYPE (last
)) == NULL_TREE
14196 && TYPE_DOMAIN (TREE_TYPE (last
)) != NULL_TREE
14197 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last
))) == NULL_TREE
)
14201 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= DECL_CHAIN (x
))
14203 if (TREE_CODE (x
) == FIELD_DECL
14204 && flexible_array_type_p (TREE_TYPE (x
)))
14213 /* Like int_size_in_bytes, but handle empty records specially. */
14216 arg_int_size_in_bytes (const_tree type
)
14218 return TYPE_EMPTY_P (type
) ? 0 : int_size_in_bytes (type
);
14221 /* Like size_in_bytes, but handle empty records specially. */
14224 arg_size_in_bytes (const_tree type
)
14226 return TYPE_EMPTY_P (type
) ? size_zero_node
: size_in_bytes (type
);
14229 /* Return true if an expression with CODE has to have the same result type as
14230 its first operand. */
14233 expr_type_first_operand_type_p (tree_code code
)
14246 case TRUNC_DIV_EXPR
:
14247 case CEIL_DIV_EXPR
:
14248 case FLOOR_DIV_EXPR
:
14249 case ROUND_DIV_EXPR
:
14250 case TRUNC_MOD_EXPR
:
14251 case CEIL_MOD_EXPR
:
14252 case FLOOR_MOD_EXPR
:
14253 case ROUND_MOD_EXPR
:
14255 case EXACT_DIV_EXPR
:
14273 /* Return a typenode for the "standard" C type with a given name. */
14275 get_typenode_from_name (const char *name
)
14277 if (name
== NULL
|| *name
== '\0')
14280 if (strcmp (name
, "char") == 0)
14281 return char_type_node
;
14282 if (strcmp (name
, "unsigned char") == 0)
14283 return unsigned_char_type_node
;
14284 if (strcmp (name
, "signed char") == 0)
14285 return signed_char_type_node
;
14287 if (strcmp (name
, "short int") == 0)
14288 return short_integer_type_node
;
14289 if (strcmp (name
, "short unsigned int") == 0)
14290 return short_unsigned_type_node
;
14292 if (strcmp (name
, "int") == 0)
14293 return integer_type_node
;
14294 if (strcmp (name
, "unsigned int") == 0)
14295 return unsigned_type_node
;
14297 if (strcmp (name
, "long int") == 0)
14298 return long_integer_type_node
;
14299 if (strcmp (name
, "long unsigned int") == 0)
14300 return long_unsigned_type_node
;
14302 if (strcmp (name
, "long long int") == 0)
14303 return long_long_integer_type_node
;
14304 if (strcmp (name
, "long long unsigned int") == 0)
14305 return long_long_unsigned_type_node
;
14307 gcc_unreachable ();
14310 /* List of pointer types used to declare builtins before we have seen their
14313 Keep the size up to date in tree.h ! */
14314 const builtin_structptr_type builtin_structptr_types
[6] =
14316 { fileptr_type_node
, ptr_type_node
, "FILE" },
14317 { const_tm_ptr_type_node
, const_ptr_type_node
, "tm" },
14318 { fenv_t_ptr_type_node
, ptr_type_node
, "fenv_t" },
14319 { const_fenv_t_ptr_type_node
, const_ptr_type_node
, "fenv_t" },
14320 { fexcept_t_ptr_type_node
, ptr_type_node
, "fexcept_t" },
14321 { const_fexcept_t_ptr_type_node
, const_ptr_type_node
, "fexcept_t" }
14324 /* Return the maximum object size. */
14327 max_object_size (void)
14329 /* To do: Make this a configurable parameter. */
14330 return TYPE_MAX_VALUE (ptrdiff_type_node
);
14333 /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
14334 parameter default to false and that weeds out error_mark_node. */
14337 verify_type_context (location_t loc
, type_context_kind context
,
14338 const_tree type
, bool silent_p
)
14340 if (type
== error_mark_node
)
14343 gcc_assert (TYPE_P (type
));
14344 return (!targetm
.verify_type_context
14345 || targetm
.verify_type_context (loc
, context
, type
, silent_p
));
14348 /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
14349 delete operators. Return false if they may or may not name such
14350 a pair and, when nonnull, set *PCERTAIN to true if they certainly
14354 valid_new_delete_pair_p (tree new_asm
, tree delete_asm
,
14355 bool *pcertain
/* = NULL */)
14359 pcertain
= &certain
;
14361 const char *new_name
= IDENTIFIER_POINTER (new_asm
);
14362 const char *delete_name
= IDENTIFIER_POINTER (delete_asm
);
14363 unsigned int new_len
= IDENTIFIER_LENGTH (new_asm
);
14364 unsigned int delete_len
= IDENTIFIER_LENGTH (delete_asm
);
14366 /* The following failures are due to invalid names so they're not
14367 considered certain mismatches. */
14370 if (new_len
< 5 || delete_len
< 6)
14372 if (new_name
[0] == '_')
14373 ++new_name
, --new_len
;
14374 if (new_name
[0] == '_')
14375 ++new_name
, --new_len
;
14376 if (delete_name
[0] == '_')
14377 ++delete_name
, --delete_len
;
14378 if (delete_name
[0] == '_')
14379 ++delete_name
, --delete_len
;
14380 if (new_len
< 4 || delete_len
< 5)
14383 /* The following failures are due to names of user-defined operators
14384 so they're also not considered certain mismatches. */
14386 /* *_len is now just the length after initial underscores. */
14387 if (new_name
[0] != 'Z' || new_name
[1] != 'n')
14389 if (delete_name
[0] != 'Z' || delete_name
[1] != 'd')
14392 /* The following failures are certain mismatches. */
14395 /* _Znw must match _Zdl, _Zna must match _Zda. */
14396 if ((new_name
[2] != 'w' || delete_name
[2] != 'l')
14397 && (new_name
[2] != 'a' || delete_name
[2] != 'a'))
14399 /* 'j', 'm' and 'y' correspond to size_t. */
14400 if (new_name
[3] != 'j' && new_name
[3] != 'm' && new_name
[3] != 'y')
14402 if (delete_name
[3] != 'P' || delete_name
[4] != 'v')
14405 || (new_len
== 18 && !memcmp (new_name
+ 4, "RKSt9nothrow_t", 14)))
14407 /* _ZnXY or _ZnXYRKSt9nothrow_t matches
14408 _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
14409 if (delete_len
== 5)
14411 if (delete_len
== 6 && delete_name
[5] == new_name
[3])
14413 if (delete_len
== 19 && !memcmp (delete_name
+ 5, "RKSt9nothrow_t", 14))
14416 else if ((new_len
== 19 && !memcmp (new_name
+ 4, "St11align_val_t", 15))
14418 && !memcmp (new_name
+ 4, "St11align_val_tRKSt9nothrow_t", 29)))
14420 /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
14421 _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or or
14422 _ZdXPvSt11align_val_tRKSt9nothrow_t. */
14423 if (delete_len
== 20 && !memcmp (delete_name
+ 5, "St11align_val_t", 15))
14425 if (delete_len
== 21
14426 && delete_name
[5] == new_name
[3]
14427 && !memcmp (delete_name
+ 6, "St11align_val_t", 15))
14429 if (delete_len
== 34
14430 && !memcmp (delete_name
+ 5, "St11align_val_tRKSt9nothrow_t", 29))
14434 /* The negative result is conservative. */
14439 /* Return the zero-based number corresponding to the argument being
14440 deallocated if FNDECL is a deallocation function or an out-of-bounds
14441 value if it isn't. */
14444 fndecl_dealloc_argno (tree fndecl
)
14446 /* A call to operator delete isn't recognized as one to a built-in. */
14447 if (DECL_IS_OPERATOR_DELETE_P (fndecl
))
14449 if (DECL_IS_REPLACEABLE_OPERATOR (fndecl
))
14452 /* Avoid placement delete that's not been inlined. */
14453 tree fname
= DECL_ASSEMBLER_NAME (fndecl
);
14454 if (id_equal (fname
, "_ZdlPvS_") // ordinary form
14455 || id_equal (fname
, "_ZdaPvS_")) // array form
14460 /* TODO: Handle user-defined functions with attribute malloc? Handle
14461 known non-built-ins like fopen? */
14462 if (fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
14464 switch (DECL_FUNCTION_CODE (fndecl
))
14466 case BUILT_IN_FREE
:
14467 case BUILT_IN_REALLOC
:
14475 tree attrs
= DECL_ATTRIBUTES (fndecl
);
14479 for (tree atfree
= attrs
;
14480 (atfree
= lookup_attribute ("*dealloc", atfree
));
14481 atfree
= TREE_CHAIN (atfree
))
14483 tree alloc
= TREE_VALUE (atfree
);
14487 tree pos
= TREE_CHAIN (alloc
);
14491 pos
= TREE_VALUE (pos
);
14492 return TREE_INT_CST_LOW (pos
) - 1;
14498 /* If EXPR refers to a character array or pointer declared attribute
14499 nonstring, return a decl for that array or pointer and set *REF
14500 to the referenced enclosing object or pointer. Otherwise return
14504 get_attr_nonstring_decl (tree expr
, tree
*ref
)
14507 tree var
= NULL_TREE
;
14508 if (TREE_CODE (decl
) == SSA_NAME
)
14510 gimple
*def
= SSA_NAME_DEF_STMT (decl
);
14512 if (is_gimple_assign (def
))
14514 tree_code code
= gimple_assign_rhs_code (def
);
14515 if (code
== ADDR_EXPR
14516 || code
== COMPONENT_REF
14517 || code
== VAR_DECL
)
14518 decl
= gimple_assign_rhs1 (def
);
14521 var
= SSA_NAME_VAR (decl
);
14524 if (TREE_CODE (decl
) == ADDR_EXPR
)
14525 decl
= TREE_OPERAND (decl
, 0);
14527 /* To simplify calling code, store the referenced DECL regardless of
14528 the attribute determined below, but avoid storing the SSA_NAME_VAR
14529 obtained above (it's not useful for dataflow purposes). */
14533 /* Use the SSA_NAME_VAR that was determined above to see if it's
14534 declared nonstring. Otherwise drill down into the referenced
14538 else if (TREE_CODE (decl
) == ARRAY_REF
)
14539 decl
= TREE_OPERAND (decl
, 0);
14540 else if (TREE_CODE (decl
) == COMPONENT_REF
)
14541 decl
= TREE_OPERAND (decl
, 1);
14542 else if (TREE_CODE (decl
) == MEM_REF
)
14543 return get_attr_nonstring_decl (TREE_OPERAND (decl
, 0), ref
);
14546 && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl
)))
14554 namespace selftest
{
14556 /* Selftests for tree. */
14558 /* Verify that integer constants are sane. */
14561 test_integer_constants ()
14563 ASSERT_TRUE (integer_type_node
!= NULL
);
14564 ASSERT_TRUE (build_int_cst (integer_type_node
, 0) != NULL
);
14566 tree type
= integer_type_node
;
14568 tree zero
= build_zero_cst (type
);
14569 ASSERT_EQ (INTEGER_CST
, TREE_CODE (zero
));
14570 ASSERT_EQ (type
, TREE_TYPE (zero
));
14572 tree one
= build_int_cst (type
, 1);
14573 ASSERT_EQ (INTEGER_CST
, TREE_CODE (one
));
14574 ASSERT_EQ (type
, TREE_TYPE (zero
));
14577 /* Verify identifiers. */
14580 test_identifiers ()
14582 tree identifier
= get_identifier ("foo");
14583 ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier
));
14584 ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier
));
14587 /* Verify LABEL_DECL. */
14592 tree identifier
= get_identifier ("err");
14593 tree label_decl
= build_decl (UNKNOWN_LOCATION
, LABEL_DECL
,
14594 identifier
, void_type_node
);
14595 ASSERT_EQ (-1, LABEL_DECL_UID (label_decl
));
14596 ASSERT_FALSE (FORCED_LABEL (label_decl
));
14599 /* Return a new VECTOR_CST node whose type is TYPE and whose values
14600 are given by VALS. */
14603 build_vector (tree type
, const vec
<tree
> &vals MEM_STAT_DECL
)
14605 gcc_assert (known_eq (vals
.length (), TYPE_VECTOR_SUBPARTS (type
)));
14606 tree_vector_builder
builder (type
, vals
.length (), 1);
14607 builder
.splice (vals
);
14608 return builder
.build ();
14611 /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
14614 check_vector_cst (const vec
<tree
> &expected
, tree actual
)
14616 ASSERT_KNOWN_EQ (expected
.length (),
14617 TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual
)));
14618 for (unsigned int i
= 0; i
< expected
.length (); ++i
)
14619 ASSERT_EQ (wi::to_wide (expected
[i
]),
14620 wi::to_wide (vector_cst_elt (actual
, i
)));
14623 /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
14624 and that its elements match EXPECTED. */
14627 check_vector_cst_duplicate (const vec
<tree
> &expected
, tree actual
,
14628 unsigned int npatterns
)
14630 ASSERT_EQ (npatterns
, VECTOR_CST_NPATTERNS (actual
));
14631 ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual
));
14632 ASSERT_EQ (npatterns
, vector_cst_encoded_nelts (actual
));
14633 ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual
));
14634 ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual
));
14635 check_vector_cst (expected
, actual
);
14638 /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
14639 and NPATTERNS background elements, and that its elements match
14643 check_vector_cst_fill (const vec
<tree
> &expected
, tree actual
,
14644 unsigned int npatterns
)
14646 ASSERT_EQ (npatterns
, VECTOR_CST_NPATTERNS (actual
));
14647 ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual
));
14648 ASSERT_EQ (2 * npatterns
, vector_cst_encoded_nelts (actual
));
14649 ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual
));
14650 ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual
));
14651 check_vector_cst (expected
, actual
);
14654 /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
14655 and that its elements match EXPECTED. */
14658 check_vector_cst_stepped (const vec
<tree
> &expected
, tree actual
,
14659 unsigned int npatterns
)
14661 ASSERT_EQ (npatterns
, VECTOR_CST_NPATTERNS (actual
));
14662 ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual
));
14663 ASSERT_EQ (3 * npatterns
, vector_cst_encoded_nelts (actual
));
14664 ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual
));
14665 ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual
));
14666 check_vector_cst (expected
, actual
);
14669 /* Test the creation of VECTOR_CSTs. */
14672 test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO
)
14674 auto_vec
<tree
, 8> elements (8);
14675 elements
.quick_grow (8);
14676 tree element_type
= build_nonstandard_integer_type (16, true);
14677 tree vector_type
= build_vector_type (element_type
, 8);
14679 /* Test a simple linear series with a base of 0 and a step of 1:
14680 { 0, 1, 2, 3, 4, 5, 6, 7 }. */
14681 for (unsigned int i
= 0; i
< 8; ++i
)
14682 elements
[i
] = build_int_cst (element_type
, i
);
14683 tree vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14684 check_vector_cst_stepped (elements
, vector
, 1);
14686 /* Try the same with the first element replaced by 100:
14687 { 100, 1, 2, 3, 4, 5, 6, 7 }. */
14688 elements
[0] = build_int_cst (element_type
, 100);
14689 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14690 check_vector_cst_stepped (elements
, vector
, 1);
14692 /* Try a series that wraps around.
14693 { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
14694 for (unsigned int i
= 1; i
< 8; ++i
)
14695 elements
[i
] = build_int_cst (element_type
, (65530 + i
) & 0xffff);
14696 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14697 check_vector_cst_stepped (elements
, vector
, 1);
14699 /* Try a downward series:
14700 { 100, 79, 78, 77, 76, 75, 75, 73 }. */
14701 for (unsigned int i
= 1; i
< 8; ++i
)
14702 elements
[i
] = build_int_cst (element_type
, 80 - i
);
14703 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14704 check_vector_cst_stepped (elements
, vector
, 1);
14706 /* Try two interleaved series with different bases and steps:
14707 { 100, 53, 66, 206, 62, 212, 58, 218 }. */
14708 elements
[1] = build_int_cst (element_type
, 53);
14709 for (unsigned int i
= 2; i
< 8; i
+= 2)
14711 elements
[i
] = build_int_cst (element_type
, 70 - i
* 2);
14712 elements
[i
+ 1] = build_int_cst (element_type
, 200 + i
* 3);
14714 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14715 check_vector_cst_stepped (elements
, vector
, 2);
14717 /* Try a duplicated value:
14718 { 100, 100, 100, 100, 100, 100, 100, 100 }. */
14719 for (unsigned int i
= 1; i
< 8; ++i
)
14720 elements
[i
] = elements
[0];
14721 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14722 check_vector_cst_duplicate (elements
, vector
, 1);
14724 /* Try an interleaved duplicated value:
14725 { 100, 55, 100, 55, 100, 55, 100, 55 }. */
14726 elements
[1] = build_int_cst (element_type
, 55);
14727 for (unsigned int i
= 2; i
< 8; ++i
)
14728 elements
[i
] = elements
[i
- 2];
14729 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14730 check_vector_cst_duplicate (elements
, vector
, 2);
14732 /* Try a duplicated value with 2 exceptions
14733 { 41, 97, 100, 55, 100, 55, 100, 55 }. */
14734 elements
[0] = build_int_cst (element_type
, 41);
14735 elements
[1] = build_int_cst (element_type
, 97);
14736 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14737 check_vector_cst_fill (elements
, vector
, 2);
14739 /* Try with and without a step
14740 { 41, 97, 100, 21, 100, 35, 100, 49 }. */
14741 for (unsigned int i
= 3; i
< 8; i
+= 2)
14742 elements
[i
] = build_int_cst (element_type
, i
* 7);
14743 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14744 check_vector_cst_stepped (elements
, vector
, 2);
14746 /* Try a fully-general constant:
14747 { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
14748 elements
[5] = build_int_cst (element_type
, 9990);
14749 vector
= build_vector (vector_type
, elements PASS_MEM_STAT
);
14750 check_vector_cst_fill (elements
, vector
, 4);
14753 /* Verify that STRIP_NOPS (NODE) is EXPECTED.
14754 Helper function for test_location_wrappers, to deal with STRIP_NOPS
14755 modifying its argument in-place. */
14758 check_strip_nops (tree node
, tree expected
)
14761 ASSERT_EQ (expected
, node
);
14764 /* Verify location wrappers. */
14767 test_location_wrappers ()
14769 location_t loc
= BUILTINS_LOCATION
;
14771 ASSERT_EQ (NULL_TREE
, maybe_wrap_with_location (NULL_TREE
, loc
));
14773 /* Wrapping a constant. */
14774 tree int_cst
= build_int_cst (integer_type_node
, 42);
14775 ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst
));
14776 ASSERT_FALSE (location_wrapper_p (int_cst
));
14778 tree wrapped_int_cst
= maybe_wrap_with_location (int_cst
, loc
);
14779 ASSERT_TRUE (location_wrapper_p (wrapped_int_cst
));
14780 ASSERT_EQ (loc
, EXPR_LOCATION (wrapped_int_cst
));
14781 ASSERT_EQ (int_cst
, tree_strip_any_location_wrapper (wrapped_int_cst
));
14783 /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
14784 ASSERT_EQ (int_cst
, maybe_wrap_with_location (int_cst
, UNKNOWN_LOCATION
));
14786 /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
14787 tree cast
= build1 (NOP_EXPR
, char_type_node
, int_cst
);
14788 ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast
));
14789 ASSERT_EQ (cast
, maybe_wrap_with_location (cast
, loc
));
14791 /* Wrapping a STRING_CST. */
14792 tree string_cst
= build_string (4, "foo");
14793 ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst
));
14794 ASSERT_FALSE (location_wrapper_p (string_cst
));
14796 tree wrapped_string_cst
= maybe_wrap_with_location (string_cst
, loc
);
14797 ASSERT_TRUE (location_wrapper_p (wrapped_string_cst
));
14798 ASSERT_EQ (VIEW_CONVERT_EXPR
, TREE_CODE (wrapped_string_cst
));
14799 ASSERT_EQ (loc
, EXPR_LOCATION (wrapped_string_cst
));
14800 ASSERT_EQ (string_cst
, tree_strip_any_location_wrapper (wrapped_string_cst
));
14803 /* Wrapping a variable. */
14804 tree int_var
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
14805 get_identifier ("some_int_var"),
14806 integer_type_node
);
14807 ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var
));
14808 ASSERT_FALSE (location_wrapper_p (int_var
));
14810 tree wrapped_int_var
= maybe_wrap_with_location (int_var
, loc
);
14811 ASSERT_TRUE (location_wrapper_p (wrapped_int_var
));
14812 ASSERT_EQ (loc
, EXPR_LOCATION (wrapped_int_var
));
14813 ASSERT_EQ (int_var
, tree_strip_any_location_wrapper (wrapped_int_var
));
14815 /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
14817 tree r_cast
= build1 (NON_LVALUE_EXPR
, integer_type_node
, int_var
);
14818 ASSERT_FALSE (location_wrapper_p (r_cast
));
14819 ASSERT_EQ (r_cast
, tree_strip_any_location_wrapper (r_cast
));
14821 /* Verify that STRIP_NOPS removes wrappers. */
14822 check_strip_nops (wrapped_int_cst
, int_cst
);
14823 check_strip_nops (wrapped_string_cst
, string_cst
);
14824 check_strip_nops (wrapped_int_var
, int_var
);
14827 /* Test various tree predicates. Verify that location wrappers don't
14828 affect the results. */
14833 /* Build various constants and wrappers around them. */
14835 location_t loc
= BUILTINS_LOCATION
;
14837 tree i_0
= build_int_cst (integer_type_node
, 0);
14838 tree wr_i_0
= maybe_wrap_with_location (i_0
, loc
);
14840 tree i_1
= build_int_cst (integer_type_node
, 1);
14841 tree wr_i_1
= maybe_wrap_with_location (i_1
, loc
);
14843 tree i_m1
= build_int_cst (integer_type_node
, -1);
14844 tree wr_i_m1
= maybe_wrap_with_location (i_m1
, loc
);
14846 tree f_0
= build_real_from_int_cst (float_type_node
, i_0
);
14847 tree wr_f_0
= maybe_wrap_with_location (f_0
, loc
);
14848 tree f_1
= build_real_from_int_cst (float_type_node
, i_1
);
14849 tree wr_f_1
= maybe_wrap_with_location (f_1
, loc
);
14850 tree f_m1
= build_real_from_int_cst (float_type_node
, i_m1
);
14851 tree wr_f_m1
= maybe_wrap_with_location (f_m1
, loc
);
14853 tree c_i_0
= build_complex (NULL_TREE
, i_0
, i_0
);
14854 tree c_i_1
= build_complex (NULL_TREE
, i_1
, i_0
);
14855 tree c_i_m1
= build_complex (NULL_TREE
, i_m1
, i_0
);
14857 tree c_f_0
= build_complex (NULL_TREE
, f_0
, f_0
);
14858 tree c_f_1
= build_complex (NULL_TREE
, f_1
, f_0
);
14859 tree c_f_m1
= build_complex (NULL_TREE
, f_m1
, f_0
);
14861 /* TODO: vector constants. */
14863 /* Test integer_onep. */
14864 ASSERT_FALSE (integer_onep (i_0
));
14865 ASSERT_FALSE (integer_onep (wr_i_0
));
14866 ASSERT_TRUE (integer_onep (i_1
));
14867 ASSERT_TRUE (integer_onep (wr_i_1
));
14868 ASSERT_FALSE (integer_onep (i_m1
));
14869 ASSERT_FALSE (integer_onep (wr_i_m1
));
14870 ASSERT_FALSE (integer_onep (f_0
));
14871 ASSERT_FALSE (integer_onep (wr_f_0
));
14872 ASSERT_FALSE (integer_onep (f_1
));
14873 ASSERT_FALSE (integer_onep (wr_f_1
));
14874 ASSERT_FALSE (integer_onep (f_m1
));
14875 ASSERT_FALSE (integer_onep (wr_f_m1
));
14876 ASSERT_FALSE (integer_onep (c_i_0
));
14877 ASSERT_TRUE (integer_onep (c_i_1
));
14878 ASSERT_FALSE (integer_onep (c_i_m1
));
14879 ASSERT_FALSE (integer_onep (c_f_0
));
14880 ASSERT_FALSE (integer_onep (c_f_1
));
14881 ASSERT_FALSE (integer_onep (c_f_m1
));
14883 /* Test integer_zerop. */
14884 ASSERT_TRUE (integer_zerop (i_0
));
14885 ASSERT_TRUE (integer_zerop (wr_i_0
));
14886 ASSERT_FALSE (integer_zerop (i_1
));
14887 ASSERT_FALSE (integer_zerop (wr_i_1
));
14888 ASSERT_FALSE (integer_zerop (i_m1
));
14889 ASSERT_FALSE (integer_zerop (wr_i_m1
));
14890 ASSERT_FALSE (integer_zerop (f_0
));
14891 ASSERT_FALSE (integer_zerop (wr_f_0
));
14892 ASSERT_FALSE (integer_zerop (f_1
));
14893 ASSERT_FALSE (integer_zerop (wr_f_1
));
14894 ASSERT_FALSE (integer_zerop (f_m1
));
14895 ASSERT_FALSE (integer_zerop (wr_f_m1
));
14896 ASSERT_TRUE (integer_zerop (c_i_0
));
14897 ASSERT_FALSE (integer_zerop (c_i_1
));
14898 ASSERT_FALSE (integer_zerop (c_i_m1
));
14899 ASSERT_FALSE (integer_zerop (c_f_0
));
14900 ASSERT_FALSE (integer_zerop (c_f_1
));
14901 ASSERT_FALSE (integer_zerop (c_f_m1
));
14903 /* Test integer_all_onesp. */
14904 ASSERT_FALSE (integer_all_onesp (i_0
));
14905 ASSERT_FALSE (integer_all_onesp (wr_i_0
));
14906 ASSERT_FALSE (integer_all_onesp (i_1
));
14907 ASSERT_FALSE (integer_all_onesp (wr_i_1
));
14908 ASSERT_TRUE (integer_all_onesp (i_m1
));
14909 ASSERT_TRUE (integer_all_onesp (wr_i_m1
));
14910 ASSERT_FALSE (integer_all_onesp (f_0
));
14911 ASSERT_FALSE (integer_all_onesp (wr_f_0
));
14912 ASSERT_FALSE (integer_all_onesp (f_1
));
14913 ASSERT_FALSE (integer_all_onesp (wr_f_1
));
14914 ASSERT_FALSE (integer_all_onesp (f_m1
));
14915 ASSERT_FALSE (integer_all_onesp (wr_f_m1
));
14916 ASSERT_FALSE (integer_all_onesp (c_i_0
));
14917 ASSERT_FALSE (integer_all_onesp (c_i_1
));
14918 ASSERT_FALSE (integer_all_onesp (c_i_m1
));
14919 ASSERT_FALSE (integer_all_onesp (c_f_0
));
14920 ASSERT_FALSE (integer_all_onesp (c_f_1
));
14921 ASSERT_FALSE (integer_all_onesp (c_f_m1
));
14923 /* Test integer_minus_onep. */
14924 ASSERT_FALSE (integer_minus_onep (i_0
));
14925 ASSERT_FALSE (integer_minus_onep (wr_i_0
));
14926 ASSERT_FALSE (integer_minus_onep (i_1
));
14927 ASSERT_FALSE (integer_minus_onep (wr_i_1
));
14928 ASSERT_TRUE (integer_minus_onep (i_m1
));
14929 ASSERT_TRUE (integer_minus_onep (wr_i_m1
));
14930 ASSERT_FALSE (integer_minus_onep (f_0
));
14931 ASSERT_FALSE (integer_minus_onep (wr_f_0
));
14932 ASSERT_FALSE (integer_minus_onep (f_1
));
14933 ASSERT_FALSE (integer_minus_onep (wr_f_1
));
14934 ASSERT_FALSE (integer_minus_onep (f_m1
));
14935 ASSERT_FALSE (integer_minus_onep (wr_f_m1
));
14936 ASSERT_FALSE (integer_minus_onep (c_i_0
));
14937 ASSERT_FALSE (integer_minus_onep (c_i_1
));
14938 ASSERT_TRUE (integer_minus_onep (c_i_m1
));
14939 ASSERT_FALSE (integer_minus_onep (c_f_0
));
14940 ASSERT_FALSE (integer_minus_onep (c_f_1
));
14941 ASSERT_FALSE (integer_minus_onep (c_f_m1
));
14943 /* Test integer_each_onep. */
14944 ASSERT_FALSE (integer_each_onep (i_0
));
14945 ASSERT_FALSE (integer_each_onep (wr_i_0
));
14946 ASSERT_TRUE (integer_each_onep (i_1
));
14947 ASSERT_TRUE (integer_each_onep (wr_i_1
));
14948 ASSERT_FALSE (integer_each_onep (i_m1
));
14949 ASSERT_FALSE (integer_each_onep (wr_i_m1
));
14950 ASSERT_FALSE (integer_each_onep (f_0
));
14951 ASSERT_FALSE (integer_each_onep (wr_f_0
));
14952 ASSERT_FALSE (integer_each_onep (f_1
));
14953 ASSERT_FALSE (integer_each_onep (wr_f_1
));
14954 ASSERT_FALSE (integer_each_onep (f_m1
));
14955 ASSERT_FALSE (integer_each_onep (wr_f_m1
));
14956 ASSERT_FALSE (integer_each_onep (c_i_0
));
14957 ASSERT_FALSE (integer_each_onep (c_i_1
));
14958 ASSERT_FALSE (integer_each_onep (c_i_m1
));
14959 ASSERT_FALSE (integer_each_onep (c_f_0
));
14960 ASSERT_FALSE (integer_each_onep (c_f_1
));
14961 ASSERT_FALSE (integer_each_onep (c_f_m1
));
14963 /* Test integer_truep. */
14964 ASSERT_FALSE (integer_truep (i_0
));
14965 ASSERT_FALSE (integer_truep (wr_i_0
));
14966 ASSERT_TRUE (integer_truep (i_1
));
14967 ASSERT_TRUE (integer_truep (wr_i_1
));
14968 ASSERT_FALSE (integer_truep (i_m1
));
14969 ASSERT_FALSE (integer_truep (wr_i_m1
));
14970 ASSERT_FALSE (integer_truep (f_0
));
14971 ASSERT_FALSE (integer_truep (wr_f_0
));
14972 ASSERT_FALSE (integer_truep (f_1
));
14973 ASSERT_FALSE (integer_truep (wr_f_1
));
14974 ASSERT_FALSE (integer_truep (f_m1
));
14975 ASSERT_FALSE (integer_truep (wr_f_m1
));
14976 ASSERT_FALSE (integer_truep (c_i_0
));
14977 ASSERT_TRUE (integer_truep (c_i_1
));
14978 ASSERT_FALSE (integer_truep (c_i_m1
));
14979 ASSERT_FALSE (integer_truep (c_f_0
));
14980 ASSERT_FALSE (integer_truep (c_f_1
));
14981 ASSERT_FALSE (integer_truep (c_f_m1
));
14983 /* Test integer_nonzerop. */
14984 ASSERT_FALSE (integer_nonzerop (i_0
));
14985 ASSERT_FALSE (integer_nonzerop (wr_i_0
));
14986 ASSERT_TRUE (integer_nonzerop (i_1
));
14987 ASSERT_TRUE (integer_nonzerop (wr_i_1
));
14988 ASSERT_TRUE (integer_nonzerop (i_m1
));
14989 ASSERT_TRUE (integer_nonzerop (wr_i_m1
));
14990 ASSERT_FALSE (integer_nonzerop (f_0
));
14991 ASSERT_FALSE (integer_nonzerop (wr_f_0
));
14992 ASSERT_FALSE (integer_nonzerop (f_1
));
14993 ASSERT_FALSE (integer_nonzerop (wr_f_1
));
14994 ASSERT_FALSE (integer_nonzerop (f_m1
));
14995 ASSERT_FALSE (integer_nonzerop (wr_f_m1
));
14996 ASSERT_FALSE (integer_nonzerop (c_i_0
));
14997 ASSERT_TRUE (integer_nonzerop (c_i_1
));
14998 ASSERT_TRUE (integer_nonzerop (c_i_m1
));
14999 ASSERT_FALSE (integer_nonzerop (c_f_0
));
15000 ASSERT_FALSE (integer_nonzerop (c_f_1
));
15001 ASSERT_FALSE (integer_nonzerop (c_f_m1
));
15003 /* Test real_zerop. */
15004 ASSERT_FALSE (real_zerop (i_0
));
15005 ASSERT_FALSE (real_zerop (wr_i_0
));
15006 ASSERT_FALSE (real_zerop (i_1
));
15007 ASSERT_FALSE (real_zerop (wr_i_1
));
15008 ASSERT_FALSE (real_zerop (i_m1
));
15009 ASSERT_FALSE (real_zerop (wr_i_m1
));
15010 ASSERT_TRUE (real_zerop (f_0
));
15011 ASSERT_TRUE (real_zerop (wr_f_0
));
15012 ASSERT_FALSE (real_zerop (f_1
));
15013 ASSERT_FALSE (real_zerop (wr_f_1
));
15014 ASSERT_FALSE (real_zerop (f_m1
));
15015 ASSERT_FALSE (real_zerop (wr_f_m1
));
15016 ASSERT_FALSE (real_zerop (c_i_0
));
15017 ASSERT_FALSE (real_zerop (c_i_1
));
15018 ASSERT_FALSE (real_zerop (c_i_m1
));
15019 ASSERT_TRUE (real_zerop (c_f_0
));
15020 ASSERT_FALSE (real_zerop (c_f_1
));
15021 ASSERT_FALSE (real_zerop (c_f_m1
));
15023 /* Test real_onep. */
15024 ASSERT_FALSE (real_onep (i_0
));
15025 ASSERT_FALSE (real_onep (wr_i_0
));
15026 ASSERT_FALSE (real_onep (i_1
));
15027 ASSERT_FALSE (real_onep (wr_i_1
));
15028 ASSERT_FALSE (real_onep (i_m1
));
15029 ASSERT_FALSE (real_onep (wr_i_m1
));
15030 ASSERT_FALSE (real_onep (f_0
));
15031 ASSERT_FALSE (real_onep (wr_f_0
));
15032 ASSERT_TRUE (real_onep (f_1
));
15033 ASSERT_TRUE (real_onep (wr_f_1
));
15034 ASSERT_FALSE (real_onep (f_m1
));
15035 ASSERT_FALSE (real_onep (wr_f_m1
));
15036 ASSERT_FALSE (real_onep (c_i_0
));
15037 ASSERT_FALSE (real_onep (c_i_1
));
15038 ASSERT_FALSE (real_onep (c_i_m1
));
15039 ASSERT_FALSE (real_onep (c_f_0
));
15040 ASSERT_TRUE (real_onep (c_f_1
));
15041 ASSERT_FALSE (real_onep (c_f_m1
));
15043 /* Test real_minus_onep. */
15044 ASSERT_FALSE (real_minus_onep (i_0
));
15045 ASSERT_FALSE (real_minus_onep (wr_i_0
));
15046 ASSERT_FALSE (real_minus_onep (i_1
));
15047 ASSERT_FALSE (real_minus_onep (wr_i_1
));
15048 ASSERT_FALSE (real_minus_onep (i_m1
));
15049 ASSERT_FALSE (real_minus_onep (wr_i_m1
));
15050 ASSERT_FALSE (real_minus_onep (f_0
));
15051 ASSERT_FALSE (real_minus_onep (wr_f_0
));
15052 ASSERT_FALSE (real_minus_onep (f_1
));
15053 ASSERT_FALSE (real_minus_onep (wr_f_1
));
15054 ASSERT_TRUE (real_minus_onep (f_m1
));
15055 ASSERT_TRUE (real_minus_onep (wr_f_m1
));
15056 ASSERT_FALSE (real_minus_onep (c_i_0
));
15057 ASSERT_FALSE (real_minus_onep (c_i_1
));
15058 ASSERT_FALSE (real_minus_onep (c_i_m1
));
15059 ASSERT_FALSE (real_minus_onep (c_f_0
));
15060 ASSERT_FALSE (real_minus_onep (c_f_1
));
15061 ASSERT_TRUE (real_minus_onep (c_f_m1
));
15064 ASSERT_TRUE (zerop (i_0
));
15065 ASSERT_TRUE (zerop (wr_i_0
));
15066 ASSERT_FALSE (zerop (i_1
));
15067 ASSERT_FALSE (zerop (wr_i_1
));
15068 ASSERT_FALSE (zerop (i_m1
));
15069 ASSERT_FALSE (zerop (wr_i_m1
));
15070 ASSERT_TRUE (zerop (f_0
));
15071 ASSERT_TRUE (zerop (wr_f_0
));
15072 ASSERT_FALSE (zerop (f_1
));
15073 ASSERT_FALSE (zerop (wr_f_1
));
15074 ASSERT_FALSE (zerop (f_m1
));
15075 ASSERT_FALSE (zerop (wr_f_m1
));
15076 ASSERT_TRUE (zerop (c_i_0
));
15077 ASSERT_FALSE (zerop (c_i_1
));
15078 ASSERT_FALSE (zerop (c_i_m1
));
15079 ASSERT_TRUE (zerop (c_f_0
));
15080 ASSERT_FALSE (zerop (c_f_1
));
15081 ASSERT_FALSE (zerop (c_f_m1
));
15083 /* Test tree_expr_nonnegative_p. */
15084 ASSERT_TRUE (tree_expr_nonnegative_p (i_0
));
15085 ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0
));
15086 ASSERT_TRUE (tree_expr_nonnegative_p (i_1
));
15087 ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1
));
15088 ASSERT_FALSE (tree_expr_nonnegative_p (i_m1
));
15089 ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1
));
15090 ASSERT_TRUE (tree_expr_nonnegative_p (f_0
));
15091 ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0
));
15092 ASSERT_TRUE (tree_expr_nonnegative_p (f_1
));
15093 ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1
));
15094 ASSERT_FALSE (tree_expr_nonnegative_p (f_m1
));
15095 ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1
));
15096 ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0
));
15097 ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1
));
15098 ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1
));
15099 ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0
));
15100 ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1
));
15101 ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1
));
15103 /* Test tree_expr_nonzero_p. */
15104 ASSERT_FALSE (tree_expr_nonzero_p (i_0
));
15105 ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0
));
15106 ASSERT_TRUE (tree_expr_nonzero_p (i_1
));
15107 ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1
));
15108 ASSERT_TRUE (tree_expr_nonzero_p (i_m1
));
15109 ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1
));
15111 /* Test integer_valued_real_p. */
15112 ASSERT_FALSE (integer_valued_real_p (i_0
));
15113 ASSERT_TRUE (integer_valued_real_p (f_0
));
15114 ASSERT_TRUE (integer_valued_real_p (wr_f_0
));
15115 ASSERT_TRUE (integer_valued_real_p (f_1
));
15116 ASSERT_TRUE (integer_valued_real_p (wr_f_1
));
15118 /* Test integer_pow2p. */
15119 ASSERT_FALSE (integer_pow2p (i_0
));
15120 ASSERT_TRUE (integer_pow2p (i_1
));
15121 ASSERT_TRUE (integer_pow2p (wr_i_1
));
15123 /* Test uniform_integer_cst_p. */
15124 ASSERT_TRUE (uniform_integer_cst_p (i_0
));
15125 ASSERT_TRUE (uniform_integer_cst_p (wr_i_0
));
15126 ASSERT_TRUE (uniform_integer_cst_p (i_1
));
15127 ASSERT_TRUE (uniform_integer_cst_p (wr_i_1
));
15128 ASSERT_TRUE (uniform_integer_cst_p (i_m1
));
15129 ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1
));
15130 ASSERT_FALSE (uniform_integer_cst_p (f_0
));
15131 ASSERT_FALSE (uniform_integer_cst_p (wr_f_0
));
15132 ASSERT_FALSE (uniform_integer_cst_p (f_1
));
15133 ASSERT_FALSE (uniform_integer_cst_p (wr_f_1
));
15134 ASSERT_FALSE (uniform_integer_cst_p (f_m1
));
15135 ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1
));
15136 ASSERT_FALSE (uniform_integer_cst_p (c_i_0
));
15137 ASSERT_FALSE (uniform_integer_cst_p (c_i_1
));
15138 ASSERT_FALSE (uniform_integer_cst_p (c_i_m1
));
15139 ASSERT_FALSE (uniform_integer_cst_p (c_f_0
));
15140 ASSERT_FALSE (uniform_integer_cst_p (c_f_1
));
15141 ASSERT_FALSE (uniform_integer_cst_p (c_f_m1
));
15144 /* Check that string escaping works correctly. */
15147 test_escaped_strings (void)
15150 escaped_string msg
;
15153 /* ASSERT_STREQ does not accept NULL as a valid test
15154 result, so we have to use ASSERT_EQ instead. */
15155 ASSERT_EQ (NULL
, (const char *) msg
);
15158 ASSERT_STREQ ("", (const char *) msg
);
15160 msg
.escape ("foobar");
15161 ASSERT_STREQ ("foobar", (const char *) msg
);
15163 /* Ensure that we have -fmessage-length set to 0. */
15164 saved_cutoff
= pp_line_cutoff (global_dc
->printer
);
15165 pp_line_cutoff (global_dc
->printer
) = 0;
15167 msg
.escape ("foo\nbar");
15168 ASSERT_STREQ ("foo\\nbar", (const char *) msg
);
15170 msg
.escape ("\a\b\f\n\r\t\v");
15171 ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg
);
15173 /* Now repeat the tests with -fmessage-length set to 5. */
15174 pp_line_cutoff (global_dc
->printer
) = 5;
15176 /* Note that the newline is not translated into an escape. */
15177 msg
.escape ("foo\nbar");
15178 ASSERT_STREQ ("foo\nbar", (const char *) msg
);
15180 msg
.escape ("\a\b\f\n\r\t\v");
15181 ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg
);
15183 /* Restore the original message length setting. */
15184 pp_line_cutoff (global_dc
->printer
) = saved_cutoff
;
15187 /* Run all of the selftests within this file. */
15192 test_integer_constants ();
15193 test_identifiers ();
15195 test_vector_cst_patterns ();
15196 test_location_wrappers ();
15197 test_predicates ();
15198 test_escaped_strings ();
15201 } // namespace selftest
15203 #endif /* CHECKING_P */
15205 #include "gt-tree.h"