1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file contains the low level primitives for operating on tree nodes,
21 including allocation, list operations, interning of identifiers,
22 construction of data type nodes and statement nodes,
23 and construction of type conversion nodes. It also contains
24 tables index by tree code that describe how to take apart
27 It is intended to be language-independent, but occasionally
28 calls language-dependent routines defined (for C) in typecheck.c. */
32 #include "coretypes.h"
39 #include "toplev.h" /* get_random_seed */
42 #include "filenames.h"
45 #include "common/common-target.h"
46 #include "langhooks.h"
47 #include "tree-inline.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "tree-pass.h"
54 #include "langhooks-def.h"
55 #include "diagnostic.h"
56 #include "tree-diagnostic.h"
57 #include "tree-pretty-print.h"
63 /* Tree code classes. */
65 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
66 #define END_OF_BASE_TREE_CODES tcc_exceptional,
68 const enum tree_code_class tree_code_type
[] = {
69 #include "all-tree.def"
73 #undef END_OF_BASE_TREE_CODES
75 /* Table indexed by tree code giving number of expression
76 operands beyond the fixed part of the node structure.
77 Not used for types or decls. */
79 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
80 #define END_OF_BASE_TREE_CODES 0,
82 const unsigned char tree_code_length
[] = {
83 #include "all-tree.def"
87 #undef END_OF_BASE_TREE_CODES
89 /* Names of tree components.
90 Used for printing out the tree and error messages. */
91 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
92 #define END_OF_BASE_TREE_CODES "@dummy",
94 const char *const tree_code_name
[] = {
95 #include "all-tree.def"
99 #undef END_OF_BASE_TREE_CODES
101 /* Each tree code class has an associated string representation.
102 These must correspond to the tree_code_class entries. */
104 const char *const tree_code_class_strings
[] =
119 /* obstack.[ch] explicitly declined to prototype this. */
120 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
122 /* Statistics-gathering stuff. */
124 static int tree_code_counts
[MAX_TREE_CODES
];
125 int tree_node_counts
[(int) all_kinds
];
126 int tree_node_sizes
[(int) all_kinds
];
128 /* Keep in sync with tree.h:enum tree_node_kind. */
129 static const char * const tree_node_kind_names
[] = {
148 /* Unique id for next decl created. */
149 static GTY(()) int next_decl_uid
;
150 /* Unique id for next type created. */
151 static GTY(()) int next_type_uid
= 1;
152 /* Unique id for next debug decl created. Use negative numbers,
153 to catch erroneous uses. */
154 static GTY(()) int next_debug_decl_uid
;
156 /* Since we cannot rehash a type after it is in the table, we have to
157 keep the hash code. */
159 struct GTY(()) type_hash
{
164 /* Initial size of the hash table (rounded to next prime). */
165 #define TYPE_HASH_INITIAL_SIZE 1000
167 /* Now here is the hash table. When recording a type, it is added to
168 the slot whose index is the hash code. Note that the hash table is
169 used for several kinds of types (function types, array types and
170 array index range types, for now). While all these live in the
171 same table, they are completely independent, and the hash code is
172 computed differently for each of these. */
174 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
175 htab_t type_hash_table
;
177 /* Hash table and temporary node for larger integer const values. */
178 static GTY (()) tree int_cst_node
;
179 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
180 htab_t int_cst_hash_table
;
182 /* Hash table for optimization flags and target option flags. Use the same
183 hash table for both sets of options. Nodes for building the current
184 optimization and target option nodes. The assumption is most of the time
185 the options created will already be in the hash table, so we avoid
186 allocating and freeing up a node repeatably. */
187 static GTY (()) tree cl_optimization_node
;
188 static GTY (()) tree cl_target_option_node
;
189 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
190 htab_t cl_option_hash_table
;
192 /* General tree->tree mapping structure for use in hash tables. */
195 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
196 htab_t debug_expr_for_decl
;
198 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
199 htab_t value_expr_for_decl
;
201 static GTY ((if_marked ("tree_vec_map_marked_p"), param_is (struct tree_vec_map
)))
202 htab_t debug_args_for_decl
;
204 static GTY ((if_marked ("tree_priority_map_marked_p"),
205 param_is (struct tree_priority_map
)))
206 htab_t init_priority_for_decl
;
208 static void set_type_quals (tree
, int);
209 static int type_hash_eq (const void *, const void *);
210 static hashval_t
type_hash_hash (const void *);
211 static hashval_t
int_cst_hash_hash (const void *);
212 static int int_cst_hash_eq (const void *, const void *);
213 static hashval_t
cl_option_hash_hash (const void *);
214 static int cl_option_hash_eq (const void *, const void *);
215 static void print_type_hash_statistics (void);
216 static void print_debug_expr_statistics (void);
217 static void print_value_expr_statistics (void);
218 static int type_hash_marked_p (const void *);
219 static unsigned int type_hash_list (const_tree
, hashval_t
);
220 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
221 static bool decls_same_for_odr (tree decl1
, tree decl2
);
223 tree global_trees
[TI_MAX
];
224 tree integer_types
[itk_none
];
226 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
228 /* Number of operands for each OpenMP clause. */
229 unsigned const char omp_clause_num_ops
[] =
231 0, /* OMP_CLAUSE_ERROR */
232 1, /* OMP_CLAUSE_PRIVATE */
233 1, /* OMP_CLAUSE_SHARED */
234 1, /* OMP_CLAUSE_FIRSTPRIVATE */
235 2, /* OMP_CLAUSE_LASTPRIVATE */
236 4, /* OMP_CLAUSE_REDUCTION */
237 1, /* OMP_CLAUSE_COPYIN */
238 1, /* OMP_CLAUSE_COPYPRIVATE */
239 1, /* OMP_CLAUSE_IF */
240 1, /* OMP_CLAUSE_NUM_THREADS */
241 1, /* OMP_CLAUSE_SCHEDULE */
242 0, /* OMP_CLAUSE_NOWAIT */
243 0, /* OMP_CLAUSE_ORDERED */
244 0, /* OMP_CLAUSE_DEFAULT */
245 3, /* OMP_CLAUSE_COLLAPSE */
246 0, /* OMP_CLAUSE_UNTIED */
247 1, /* OMP_CLAUSE_FINAL */
248 0 /* OMP_CLAUSE_MERGEABLE */
251 const char * const omp_clause_code_name
[] =
274 /* Return the tree node structure used by tree code CODE. */
276 static inline enum tree_node_structure_enum
277 tree_node_structure_for_code (enum tree_code code
)
279 switch (TREE_CODE_CLASS (code
))
281 case tcc_declaration
:
286 return TS_FIELD_DECL
;
292 return TS_LABEL_DECL
;
294 return TS_RESULT_DECL
;
295 case DEBUG_EXPR_DECL
:
298 return TS_CONST_DECL
;
302 return TS_FUNCTION_DECL
;
303 case TRANSLATION_UNIT_DECL
:
304 return TS_TRANSLATION_UNIT_DECL
;
306 return TS_DECL_NON_COMMON
;
310 return TS_TYPE_NON_COMMON
;
319 default: /* tcc_constant and tcc_exceptional */
324 /* tcc_constant cases. */
325 case INTEGER_CST
: return TS_INT_CST
;
326 case REAL_CST
: return TS_REAL_CST
;
327 case FIXED_CST
: return TS_FIXED_CST
;
328 case COMPLEX_CST
: return TS_COMPLEX
;
329 case VECTOR_CST
: return TS_VECTOR
;
330 case STRING_CST
: return TS_STRING
;
331 /* tcc_exceptional cases. */
332 case ERROR_MARK
: return TS_COMMON
;
333 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
334 case TREE_LIST
: return TS_LIST
;
335 case TREE_VEC
: return TS_VEC
;
336 case SSA_NAME
: return TS_SSA_NAME
;
337 case PLACEHOLDER_EXPR
: return TS_COMMON
;
338 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
339 case BLOCK
: return TS_BLOCK
;
340 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
341 case TREE_BINFO
: return TS_BINFO
;
342 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
343 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
344 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
352 /* Initialize tree_contains_struct to describe the hierarchy of tree
356 initialize_tree_contains_struct (void)
360 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
363 enum tree_node_structure_enum ts_code
;
365 code
= (enum tree_code
) i
;
366 ts_code
= tree_node_structure_for_code (code
);
368 /* Mark the TS structure itself. */
369 tree_contains_struct
[code
][ts_code
] = 1;
371 /* Mark all the structures that TS is derived from. */
389 case TS_STATEMENT_LIST
:
390 MARK_TS_TYPED (code
);
394 case TS_DECL_MINIMAL
:
400 case TS_OPTIMIZATION
:
401 case TS_TARGET_OPTION
:
402 MARK_TS_COMMON (code
);
405 case TS_TYPE_WITH_LANG_SPECIFIC
:
406 MARK_TS_TYPE_COMMON (code
);
409 case TS_TYPE_NON_COMMON
:
410 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
414 MARK_TS_DECL_MINIMAL (code
);
419 MARK_TS_DECL_COMMON (code
);
422 case TS_DECL_NON_COMMON
:
423 MARK_TS_DECL_WITH_VIS (code
);
426 case TS_DECL_WITH_VIS
:
430 MARK_TS_DECL_WRTL (code
);
434 MARK_TS_DECL_COMMON (code
);
438 MARK_TS_DECL_WITH_VIS (code
);
442 case TS_FUNCTION_DECL
:
443 MARK_TS_DECL_NON_COMMON (code
);
446 case TS_TRANSLATION_UNIT_DECL
:
447 MARK_TS_DECL_COMMON (code
);
455 /* Basic consistency checks for attributes used in fold. */
456 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
457 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
458 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
459 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
460 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
461 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
462 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
463 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
464 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
465 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
466 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
467 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
468 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
469 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
470 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
471 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
472 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
473 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
474 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
475 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
476 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
477 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
478 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
479 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
480 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
481 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
482 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
483 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
484 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
485 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
486 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
487 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
488 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
489 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
490 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
491 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
492 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
493 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
502 /* Initialize the hash table of types. */
503 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
506 debug_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
507 tree_decl_map_eq
, 0);
509 value_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
510 tree_decl_map_eq
, 0);
511 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
512 tree_priority_map_eq
, 0);
514 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
515 int_cst_hash_eq
, NULL
);
517 int_cst_node
= make_node (INTEGER_CST
);
519 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
520 cl_option_hash_eq
, NULL
);
522 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
523 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
525 /* Initialize the tree_contains_struct array. */
526 initialize_tree_contains_struct ();
527 lang_hooks
.init_ts ();
531 /* The name of the object as the assembler will see it (but before any
532 translations made by ASM_OUTPUT_LABELREF). Often this is the same
533 as DECL_NAME. It is an IDENTIFIER_NODE. */
535 decl_assembler_name (tree decl
)
537 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
538 lang_hooks
.set_decl_assembler_name (decl
);
539 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
542 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
545 decl_assembler_name_equal (tree decl
, const_tree asmname
)
547 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
548 const char *decl_str
;
549 const char *asmname_str
;
552 if (decl_asmname
== asmname
)
555 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
556 asmname_str
= IDENTIFIER_POINTER (asmname
);
559 /* If the target assembler name was set by the user, things are trickier.
560 We have a leading '*' to begin with. After that, it's arguable what
561 is the correct thing to do with -fleading-underscore. Arguably, we've
562 historically been doing the wrong thing in assemble_alias by always
563 printing the leading underscore. Since we're not changing that, make
564 sure user_label_prefix follows the '*' before matching. */
565 if (decl_str
[0] == '*')
567 size_t ulp_len
= strlen (user_label_prefix
);
573 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
574 decl_str
+= ulp_len
, test
=true;
578 if (asmname_str
[0] == '*')
580 size_t ulp_len
= strlen (user_label_prefix
);
586 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
587 asmname_str
+= ulp_len
, test
=true;
594 return strcmp (decl_str
, asmname_str
) == 0;
597 /* Hash asmnames ignoring the user specified marks. */
600 decl_assembler_name_hash (const_tree asmname
)
602 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
604 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
605 size_t ulp_len
= strlen (user_label_prefix
);
609 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
612 return htab_hash_string (decl_str
);
615 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
618 /* Compute the number of bytes occupied by a tree with code CODE.
619 This function cannot be used for nodes that have variable sizes,
620 including TREE_VEC, STRING_CST, and CALL_EXPR. */
622 tree_code_size (enum tree_code code
)
624 switch (TREE_CODE_CLASS (code
))
626 case tcc_declaration
: /* A decl node */
631 return sizeof (struct tree_field_decl
);
633 return sizeof (struct tree_parm_decl
);
635 return sizeof (struct tree_var_decl
);
637 return sizeof (struct tree_label_decl
);
639 return sizeof (struct tree_result_decl
);
641 return sizeof (struct tree_const_decl
);
643 return sizeof (struct tree_type_decl
);
645 return sizeof (struct tree_function_decl
);
646 case DEBUG_EXPR_DECL
:
647 return sizeof (struct tree_decl_with_rtl
);
649 return sizeof (struct tree_decl_non_common
);
653 case tcc_type
: /* a type node */
654 return sizeof (struct tree_type_non_common
);
656 case tcc_reference
: /* a reference */
657 case tcc_expression
: /* an expression */
658 case tcc_statement
: /* an expression with side effects */
659 case tcc_comparison
: /* a comparison expression */
660 case tcc_unary
: /* a unary arithmetic expression */
661 case tcc_binary
: /* a binary arithmetic expression */
662 return (sizeof (struct tree_exp
)
663 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
665 case tcc_constant
: /* a constant */
668 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
669 case REAL_CST
: return sizeof (struct tree_real_cst
);
670 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
671 case COMPLEX_CST
: return sizeof (struct tree_complex
);
672 case VECTOR_CST
: return sizeof (struct tree_vector
);
673 case STRING_CST
: gcc_unreachable ();
675 return lang_hooks
.tree_size (code
);
678 case tcc_exceptional
: /* something random, like an identifier. */
681 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
682 case TREE_LIST
: return sizeof (struct tree_list
);
685 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
688 case OMP_CLAUSE
: gcc_unreachable ();
690 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
692 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
693 case BLOCK
: return sizeof (struct tree_block
);
694 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
695 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
696 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
699 return lang_hooks
.tree_size (code
);
707 /* Compute the number of bytes occupied by NODE. This routine only
708 looks at TREE_CODE, except for those nodes that have variable sizes. */
710 tree_size (const_tree node
)
712 const enum tree_code code
= TREE_CODE (node
);
716 return (offsetof (struct tree_binfo
, base_binfos
)
718 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
721 return (sizeof (struct tree_vec
)
722 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
725 return (sizeof (struct tree_vector
)
726 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node
)) - 1) * sizeof (tree
));
729 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
732 return (sizeof (struct tree_omp_clause
)
733 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
737 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
738 return (sizeof (struct tree_exp
)
739 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
741 return tree_code_size (code
);
745 /* Record interesting allocation statistics for a tree node with CODE
749 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
750 size_t length ATTRIBUTE_UNUSED
)
752 enum tree_code_class type
= TREE_CODE_CLASS (code
);
755 if (!GATHER_STATISTICS
)
760 case tcc_declaration
: /* A decl node */
764 case tcc_type
: /* a type node */
768 case tcc_statement
: /* an expression with side effects */
772 case tcc_reference
: /* a reference */
776 case tcc_expression
: /* an expression */
777 case tcc_comparison
: /* a comparison expression */
778 case tcc_unary
: /* a unary arithmetic expression */
779 case tcc_binary
: /* a binary arithmetic expression */
783 case tcc_constant
: /* a constant */
787 case tcc_exceptional
: /* something random, like an identifier. */
790 case IDENTIFIER_NODE
:
803 kind
= ssa_name_kind
;
815 kind
= omp_clause_kind
;
832 tree_code_counts
[(int) code
]++;
833 tree_node_counts
[(int) kind
]++;
834 tree_node_sizes
[(int) kind
] += length
;
837 /* Allocate and return a new UID from the DECL_UID namespace. */
840 allocate_decl_uid (void)
842 return next_decl_uid
++;
845 /* Return a newly allocated node of code CODE. For decl and type
846 nodes, some other fields are initialized. The rest of the node is
847 initialized to zero. This function cannot be used for TREE_VEC or
848 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
850 Achoo! I got a code in the node. */
853 make_node_stat (enum tree_code code MEM_STAT_DECL
)
856 enum tree_code_class type
= TREE_CODE_CLASS (code
);
857 size_t length
= tree_code_size (code
);
859 record_node_allocation_statistics (code
, length
);
861 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
862 TREE_SET_CODE (t
, code
);
867 TREE_SIDE_EFFECTS (t
) = 1;
870 case tcc_declaration
:
871 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
873 if (code
== FUNCTION_DECL
)
875 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
876 DECL_MODE (t
) = FUNCTION_MODE
;
881 DECL_SOURCE_LOCATION (t
) = input_location
;
882 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
883 DECL_UID (t
) = --next_debug_decl_uid
;
886 DECL_UID (t
) = allocate_decl_uid ();
887 SET_DECL_PT_UID (t
, -1);
889 if (TREE_CODE (t
) == LABEL_DECL
)
890 LABEL_DECL_UID (t
) = -1;
895 TYPE_UID (t
) = next_type_uid
++;
896 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
897 TYPE_USER_ALIGN (t
) = 0;
898 TYPE_MAIN_VARIANT (t
) = t
;
899 TYPE_CANONICAL (t
) = t
;
901 /* Default to no attributes for type, but let target change that. */
902 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
903 targetm
.set_default_type_attributes (t
);
905 /* We have not yet computed the alias set for this type. */
906 TYPE_ALIAS_SET (t
) = -1;
910 TREE_CONSTANT (t
) = 1;
919 case PREDECREMENT_EXPR
:
920 case PREINCREMENT_EXPR
:
921 case POSTDECREMENT_EXPR
:
922 case POSTINCREMENT_EXPR
:
923 /* All of these have side-effects, no matter what their
925 TREE_SIDE_EFFECTS (t
) = 1;
934 /* Other classes need no special treatment. */
941 /* Return a new node with the same contents as NODE except that its
942 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
945 copy_node_stat (tree node MEM_STAT_DECL
)
948 enum tree_code code
= TREE_CODE (node
);
951 gcc_assert (code
!= STATEMENT_LIST
);
953 length
= tree_size (node
);
954 record_node_allocation_statistics (code
, length
);
955 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
956 memcpy (t
, node
, length
);
958 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
960 TREE_ASM_WRITTEN (t
) = 0;
961 TREE_VISITED (t
) = 0;
963 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
965 if (code
== DEBUG_EXPR_DECL
)
966 DECL_UID (t
) = --next_debug_decl_uid
;
969 DECL_UID (t
) = allocate_decl_uid ();
970 if (DECL_PT_UID_SET_P (node
))
971 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
973 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
974 && DECL_HAS_VALUE_EXPR_P (node
))
976 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
977 DECL_HAS_VALUE_EXPR_P (t
) = 1;
979 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
980 if (TREE_CODE (node
) == VAR_DECL
)
981 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
982 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
984 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
985 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
987 if (TREE_CODE (node
) == FUNCTION_DECL
)
988 DECL_STRUCT_FUNCTION (t
) = NULL
;
990 else if (TREE_CODE_CLASS (code
) == tcc_type
)
992 TYPE_UID (t
) = next_type_uid
++;
993 /* The following is so that the debug code for
994 the copy is different from the original type.
995 The two statements usually duplicate each other
996 (because they clear fields of the same union),
997 but the optimizer should catch that. */
998 TYPE_SYMTAB_POINTER (t
) = 0;
999 TYPE_SYMTAB_ADDRESS (t
) = 0;
1001 /* Do not copy the values cache. */
1002 if (TYPE_CACHED_VALUES_P(t
))
1004 TYPE_CACHED_VALUES_P (t
) = 0;
1005 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1012 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1013 For example, this can copy a list made of TREE_LIST nodes. */
1016 copy_list (tree list
)
1024 head
= prev
= copy_node (list
);
1025 next
= TREE_CHAIN (list
);
1028 TREE_CHAIN (prev
) = copy_node (next
);
1029 prev
= TREE_CHAIN (prev
);
1030 next
= TREE_CHAIN (next
);
1036 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1039 build_int_cst (tree type
, HOST_WIDE_INT low
)
1041 /* Support legacy code. */
1043 type
= integer_type_node
;
1045 return double_int_to_tree (type
, double_int::from_shwi (low
));
1048 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1051 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1055 return double_int_to_tree (type
, double_int::from_shwi (low
));
1058 /* Constructs tree in type TYPE from with value given by CST. Signedness
1059 of CST is assumed to be the same as the signedness of TYPE. */
1062 double_int_to_tree (tree type
, double_int cst
)
1064 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1066 cst
= cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1068 return build_int_cst_wide (type
, cst
.low
, cst
.high
);
1071 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1072 to be the same as the signedness of TYPE. */
1075 double_int_fits_to_tree_p (const_tree type
, double_int cst
)
1077 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1080 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1085 /* We force the double_int CST to the range of the type TYPE by sign or
1086 zero extending it. OVERFLOWABLE indicates if we are interested in
1087 overflow of the value, when >0 we are only interested in signed
1088 overflow, for <0 we are interested in any overflow. OVERFLOWED
1089 indicates whether overflow has already occurred. CONST_OVERFLOWED
1090 indicates whether constant overflow has already occurred. We force
1091 T's value to be within range of T's type (by setting to 0 or 1 all
1092 the bits outside the type's range). We set TREE_OVERFLOWED if,
1093 OVERFLOWED is nonzero,
1094 or OVERFLOWABLE is >0 and signed overflow occurs
1095 or OVERFLOWABLE is <0 and any overflow occurs
1096 We return a new tree node for the extended double_int. The node
1097 is shared if no overflow flags are set. */
1101 force_fit_type_double (tree type
, double_int cst
, int overflowable
,
1104 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1106 /* If we need to set overflow flags, return a new unshared node. */
1107 if (overflowed
|| !double_int_fits_to_tree_p(type
, cst
))
1111 || (overflowable
> 0 && sign_extended_type
))
1113 tree t
= make_node (INTEGER_CST
);
1115 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1116 TREE_TYPE (t
) = type
;
1117 TREE_OVERFLOW (t
) = 1;
1122 /* Else build a shared node. */
1123 return double_int_to_tree (type
, cst
);
1126 /* These are the hash table functions for the hash table of INTEGER_CST
1127 nodes of a sizetype. */
1129 /* Return the hash code code X, an INTEGER_CST. */
1132 int_cst_hash_hash (const void *x
)
1134 const_tree
const t
= (const_tree
) x
;
1136 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
1137 ^ htab_hash_pointer (TREE_TYPE (t
)));
1140 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1141 is the same as that given by *Y, which is the same. */
1144 int_cst_hash_eq (const void *x
, const void *y
)
1146 const_tree
const xt
= (const_tree
) x
;
1147 const_tree
const yt
= (const_tree
) y
;
1149 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
1150 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
1151 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
1154 /* Create an INT_CST node of TYPE and value HI:LOW.
1155 The returned node is always shared. For small integers we use a
1156 per-type vector cache, for larger ones we use a single hash table. */
1159 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
1167 switch (TREE_CODE (type
))
1170 gcc_assert (hi
== 0 && low
== 0);
1174 case REFERENCE_TYPE
:
1175 /* Cache NULL pointer. */
1184 /* Cache false or true. */
1192 if (TYPE_UNSIGNED (type
))
1195 limit
= INTEGER_SHARE_LIMIT
;
1196 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1202 limit
= INTEGER_SHARE_LIMIT
+ 1;
1203 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1205 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1219 /* Look for it in the type's vector of small shared ints. */
1220 if (!TYPE_CACHED_VALUES_P (type
))
1222 TYPE_CACHED_VALUES_P (type
) = 1;
1223 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1226 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1229 /* Make sure no one is clobbering the shared constant. */
1230 gcc_assert (TREE_TYPE (t
) == type
);
1231 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
1232 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
1236 /* Create a new shared int. */
1237 t
= make_node (INTEGER_CST
);
1239 TREE_INT_CST_LOW (t
) = low
;
1240 TREE_INT_CST_HIGH (t
) = hi
;
1241 TREE_TYPE (t
) = type
;
1243 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1248 /* Use the cache of larger shared ints. */
1251 TREE_INT_CST_LOW (int_cst_node
) = low
;
1252 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
1253 TREE_TYPE (int_cst_node
) = type
;
1255 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1259 /* Insert this one into the hash table. */
1262 /* Make a new node for next time round. */
1263 int_cst_node
= make_node (INTEGER_CST
);
1271 cache_integer_cst (tree t
)
1273 tree type
= TREE_TYPE (t
);
1274 HOST_WIDE_INT hi
= TREE_INT_CST_HIGH (t
);
1275 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (t
);
1279 gcc_assert (!TREE_OVERFLOW (t
));
1281 switch (TREE_CODE (type
))
1284 gcc_assert (hi
== 0 && low
== 0);
1288 case REFERENCE_TYPE
:
1289 /* Cache NULL pointer. */
1298 /* Cache false or true. */
1306 if (TYPE_UNSIGNED (type
))
1309 limit
= INTEGER_SHARE_LIMIT
;
1310 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1316 limit
= INTEGER_SHARE_LIMIT
+ 1;
1317 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1319 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1333 /* Look for it in the type's vector of small shared ints. */
1334 if (!TYPE_CACHED_VALUES_P (type
))
1336 TYPE_CACHED_VALUES_P (type
) = 1;
1337 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1340 gcc_assert (TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) == NULL_TREE
);
1341 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1345 /* Use the cache of larger shared ints. */
1348 slot
= htab_find_slot (int_cst_hash_table
, t
, INSERT
);
1349 /* If there is already an entry for the number verify it's the
1353 gcc_assert (TREE_INT_CST_LOW ((tree
)*slot
) == low
1354 && TREE_INT_CST_HIGH ((tree
)*slot
) == hi
);
1357 /* Otherwise insert this one into the hash table. */
1363 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1364 and the rest are zeros. */
1367 build_low_bits_mask (tree type
, unsigned bits
)
1371 gcc_assert (bits
<= TYPE_PRECISION (type
));
1373 if (bits
== TYPE_PRECISION (type
)
1374 && !TYPE_UNSIGNED (type
))
1375 /* Sign extended all-ones mask. */
1376 mask
= double_int_minus_one
;
1378 mask
= double_int::mask (bits
);
1380 return build_int_cst_wide (type
, mask
.low
, mask
.high
);
1383 /* Checks that X is integer constant that can be expressed in (unsigned)
1384 HOST_WIDE_INT without loss of precision. */
1387 cst_and_fits_in_hwi (const_tree x
)
1389 if (TREE_CODE (x
) != INTEGER_CST
)
1392 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1395 return (TREE_INT_CST_HIGH (x
) == 0
1396 || TREE_INT_CST_HIGH (x
) == -1);
1399 /* Build a newly constructed TREE_VEC node of length LEN. */
1402 make_vector_stat (unsigned len MEM_STAT_DECL
)
1405 unsigned length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vector
);
1407 record_node_allocation_statistics (VECTOR_CST
, length
);
1409 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1411 TREE_SET_CODE (t
, VECTOR_CST
);
1412 TREE_CONSTANT (t
) = 1;
1417 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1418 are in a list pointed to by VALS. */
1421 build_vector_stat (tree type
, tree
*vals MEM_STAT_DECL
)
1425 tree v
= make_vector (TYPE_VECTOR_SUBPARTS (type
));
1426 TREE_TYPE (v
) = type
;
1428 /* Iterate through elements and check for overflow. */
1429 for (cnt
= 0; cnt
< TYPE_VECTOR_SUBPARTS (type
); ++cnt
)
1431 tree value
= vals
[cnt
];
1433 VECTOR_CST_ELT (v
, cnt
) = value
;
1435 /* Don't crash if we get an address constant. */
1436 if (!CONSTANT_CLASS_P (value
))
1439 over
|= TREE_OVERFLOW (value
);
1442 TREE_OVERFLOW (v
) = over
;
1446 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1447 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1450 build_vector_from_ctor (tree type
, vec
<constructor_elt
, va_gc
> *v
)
1452 tree
*vec
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (type
));
1453 unsigned HOST_WIDE_INT idx
;
1456 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1458 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1459 vec
[idx
] = build_zero_cst (TREE_TYPE (type
));
1461 return build_vector (type
, vec
);
1464 /* Build a vector of type VECTYPE where all the elements are SCs. */
1466 build_vector_from_val (tree vectype
, tree sc
)
1468 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1470 if (sc
== error_mark_node
)
1473 /* Verify that the vector type is suitable for SC. Note that there
1474 is some inconsistency in the type-system with respect to restrict
1475 qualifications of pointers. Vector types always have a main-variant
1476 element type and the qualification is applied to the vector-type.
1477 So TREE_TYPE (vector-type) does not return a properly qualified
1478 vector element-type. */
1479 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1480 TREE_TYPE (vectype
)));
1482 if (CONSTANT_CLASS_P (sc
))
1484 tree
*v
= XALLOCAVEC (tree
, nunits
);
1485 for (i
= 0; i
< nunits
; ++i
)
1487 return build_vector (vectype
, v
);
1491 vec
<constructor_elt
, va_gc
> *v
;
1492 vec_alloc (v
, nunits
);
1493 for (i
= 0; i
< nunits
; ++i
)
1494 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1495 return build_constructor (vectype
, v
);
1499 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1500 are in the vec pointed to by VALS. */
1502 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals
)
1504 tree c
= make_node (CONSTRUCTOR
);
1506 constructor_elt
*elt
;
1507 bool constant_p
= true;
1508 bool side_effects_p
= false;
1510 TREE_TYPE (c
) = type
;
1511 CONSTRUCTOR_ELTS (c
) = vals
;
1513 FOR_EACH_VEC_SAFE_ELT (vals
, i
, elt
)
1515 /* Mostly ctors will have elts that don't have side-effects, so
1516 the usual case is to scan all the elements. Hence a single
1517 loop for both const and side effects, rather than one loop
1518 each (with early outs). */
1519 if (!TREE_CONSTANT (elt
->value
))
1521 if (TREE_SIDE_EFFECTS (elt
->value
))
1522 side_effects_p
= true;
1525 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
1526 TREE_CONSTANT (c
) = constant_p
;
1531 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1534 build_constructor_single (tree type
, tree index
, tree value
)
1536 vec
<constructor_elt
, va_gc
> *v
;
1537 constructor_elt elt
= {index
, value
};
1540 v
->quick_push (elt
);
1542 return build_constructor (type
, v
);
1546 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1547 are in a list pointed to by VALS. */
1549 build_constructor_from_list (tree type
, tree vals
)
1552 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1556 vec_alloc (v
, list_length (vals
));
1557 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1558 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1561 return build_constructor (type
, v
);
1564 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1565 of elements, provided as index/value pairs. */
1568 build_constructor_va (tree type
, int nelts
, ...)
1570 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1573 va_start (p
, nelts
);
1574 vec_alloc (v
, nelts
);
1577 tree index
= va_arg (p
, tree
);
1578 tree value
= va_arg (p
, tree
);
1579 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
1582 return build_constructor (type
, v
);
1585 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1588 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1591 FIXED_VALUE_TYPE
*fp
;
1593 v
= make_node (FIXED_CST
);
1594 fp
= ggc_alloc_fixed_value ();
1595 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1597 TREE_TYPE (v
) = type
;
1598 TREE_FIXED_CST_PTR (v
) = fp
;
1602 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1605 build_real (tree type
, REAL_VALUE_TYPE d
)
1608 REAL_VALUE_TYPE
*dp
;
1611 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1612 Consider doing it via real_convert now. */
1614 v
= make_node (REAL_CST
);
1615 dp
= ggc_alloc_real_value ();
1616 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1618 TREE_TYPE (v
) = type
;
1619 TREE_REAL_CST_PTR (v
) = dp
;
1620 TREE_OVERFLOW (v
) = overflow
;
1624 /* Return a new REAL_CST node whose type is TYPE
1625 and whose value is the integer value of the INTEGER_CST node I. */
1628 real_value_from_int_cst (const_tree type
, const_tree i
)
1632 /* Clear all bits of the real value type so that we can later do
1633 bitwise comparisons to see if two values are the same. */
1634 memset (&d
, 0, sizeof d
);
1636 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1637 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1638 TYPE_UNSIGNED (TREE_TYPE (i
)));
1642 /* Given a tree representing an integer constant I, return a tree
1643 representing the same value as a floating-point constant of type TYPE. */
1646 build_real_from_int_cst (tree type
, const_tree i
)
1649 int overflow
= TREE_OVERFLOW (i
);
1651 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1653 TREE_OVERFLOW (v
) |= overflow
;
1657 /* Return a newly constructed STRING_CST node whose value is
1658 the LEN characters at STR.
1659 Note that for a C string literal, LEN should include the trailing NUL.
1660 The TREE_TYPE is not initialized. */
1663 build_string (int len
, const char *str
)
1668 /* Do not waste bytes provided by padding of struct tree_string. */
1669 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1671 record_node_allocation_statistics (STRING_CST
, length
);
1673 s
= ggc_alloc_tree_node (length
);
1675 memset (s
, 0, sizeof (struct tree_typed
));
1676 TREE_SET_CODE (s
, STRING_CST
);
1677 TREE_CONSTANT (s
) = 1;
1678 TREE_STRING_LENGTH (s
) = len
;
1679 memcpy (s
->string
.str
, str
, len
);
1680 s
->string
.str
[len
] = '\0';
1685 /* Return a newly constructed COMPLEX_CST node whose value is
1686 specified by the real and imaginary parts REAL and IMAG.
1687 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1688 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1691 build_complex (tree type
, tree real
, tree imag
)
1693 tree t
= make_node (COMPLEX_CST
);
1695 TREE_REALPART (t
) = real
;
1696 TREE_IMAGPART (t
) = imag
;
1697 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1698 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1702 /* Return a constant of arithmetic type TYPE which is the
1703 multiplicative identity of the set TYPE. */
1706 build_one_cst (tree type
)
1708 switch (TREE_CODE (type
))
1710 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1711 case POINTER_TYPE
: case REFERENCE_TYPE
:
1713 return build_int_cst (type
, 1);
1716 return build_real (type
, dconst1
);
1718 case FIXED_POINT_TYPE
:
1719 /* We can only generate 1 for accum types. */
1720 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1721 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1725 tree scalar
= build_one_cst (TREE_TYPE (type
));
1727 return build_vector_from_val (type
, scalar
);
1731 return build_complex (type
,
1732 build_one_cst (TREE_TYPE (type
)),
1733 build_zero_cst (TREE_TYPE (type
)));
1740 /* Return an integer of type TYPE containing all 1's in as much precision as
1741 it contains, or a complex or vector whose subparts are such integers. */
1744 build_all_ones_cst (tree type
)
1746 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1748 tree scalar
= build_all_ones_cst (TREE_TYPE (type
));
1749 return build_complex (type
, scalar
, scalar
);
1752 return build_minus_one_cst (type
);
1755 /* Return a constant of arithmetic type TYPE which is the
1756 opposite of the multiplicative identity of the set TYPE. */
1759 build_minus_one_cst (tree type
)
1761 switch (TREE_CODE (type
))
1763 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1764 case POINTER_TYPE
: case REFERENCE_TYPE
:
1766 return build_int_cst (type
, -1);
1769 return build_real (type
, dconstm1
);
1771 case FIXED_POINT_TYPE
:
1772 /* We can only generate 1 for accum types. */
1773 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1774 return build_fixed (type
, fixed_from_double_int (double_int_minus_one
,
1779 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
1781 return build_vector_from_val (type
, scalar
);
1785 return build_complex (type
,
1786 build_minus_one_cst (TREE_TYPE (type
)),
1787 build_zero_cst (TREE_TYPE (type
)));
1794 /* Build 0 constant of type TYPE. This is used by constructor folding
1795 and thus the constant should be represented in memory by
1799 build_zero_cst (tree type
)
1801 switch (TREE_CODE (type
))
1803 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1804 case POINTER_TYPE
: case REFERENCE_TYPE
:
1805 case OFFSET_TYPE
: case NULLPTR_TYPE
:
1806 return build_int_cst (type
, 0);
1809 return build_real (type
, dconst0
);
1811 case FIXED_POINT_TYPE
:
1812 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
1816 tree scalar
= build_zero_cst (TREE_TYPE (type
));
1818 return build_vector_from_val (type
, scalar
);
1823 tree zero
= build_zero_cst (TREE_TYPE (type
));
1825 return build_complex (type
, zero
, zero
);
1829 if (!AGGREGATE_TYPE_P (type
))
1830 return fold_convert (type
, integer_zero_node
);
1831 return build_constructor (type
, NULL
);
1836 /* Build a BINFO with LEN language slots. */
1839 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1842 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1843 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
1845 record_node_allocation_statistics (TREE_BINFO
, length
);
1847 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1849 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1851 TREE_SET_CODE (t
, TREE_BINFO
);
1853 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
1858 /* Create a CASE_LABEL_EXPR tree node and return it. */
1861 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
1863 tree t
= make_node (CASE_LABEL_EXPR
);
1865 TREE_TYPE (t
) = void_type_node
;
1866 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
1868 CASE_LOW (t
) = low_value
;
1869 CASE_HIGH (t
) = high_value
;
1870 CASE_LABEL (t
) = label_decl
;
1871 CASE_CHAIN (t
) = NULL_TREE
;
1876 /* Build a newly constructed TREE_VEC node of length LEN. */
1879 make_tree_vec_stat (int len MEM_STAT_DECL
)
1882 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1884 record_node_allocation_statistics (TREE_VEC
, length
);
1886 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1888 TREE_SET_CODE (t
, TREE_VEC
);
1889 TREE_VEC_LENGTH (t
) = len
;
1894 /* Return 1 if EXPR is the integer constant zero or a complex constant
1898 integer_zerop (const_tree expr
)
1902 switch (TREE_CODE (expr
))
1905 return (TREE_INT_CST_LOW (expr
) == 0
1906 && TREE_INT_CST_HIGH (expr
) == 0);
1908 return (integer_zerop (TREE_REALPART (expr
))
1909 && integer_zerop (TREE_IMAGPART (expr
)));
1913 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1914 if (!integer_zerop (VECTOR_CST_ELT (expr
, i
)))
1923 /* Return 1 if EXPR is the integer constant one or the corresponding
1924 complex constant. */
1927 integer_onep (const_tree expr
)
1931 switch (TREE_CODE (expr
))
1934 return (TREE_INT_CST_LOW (expr
) == 1
1935 && TREE_INT_CST_HIGH (expr
) == 0);
1937 return (integer_onep (TREE_REALPART (expr
))
1938 && integer_zerop (TREE_IMAGPART (expr
)));
1942 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1943 if (!integer_onep (VECTOR_CST_ELT (expr
, i
)))
1952 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1953 it contains, or a complex or vector whose subparts are such integers. */
1956 integer_all_onesp (const_tree expr
)
1963 if (TREE_CODE (expr
) == COMPLEX_CST
1964 && integer_all_onesp (TREE_REALPART (expr
))
1965 && integer_all_onesp (TREE_IMAGPART (expr
)))
1968 else if (TREE_CODE (expr
) == VECTOR_CST
)
1971 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1972 if (!integer_all_onesp (VECTOR_CST_ELT (expr
, i
)))
1977 else if (TREE_CODE (expr
) != INTEGER_CST
)
1980 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1981 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1982 && TREE_INT_CST_HIGH (expr
) == -1)
1987 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1988 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1990 HOST_WIDE_INT high_value
;
1993 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1995 /* Can not handle precisions greater than twice the host int size. */
1996 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1997 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1998 /* Shifting by the host word size is undefined according to the ANSI
1999 standard, so we must handle this as a special case. */
2002 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
2004 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
2005 && TREE_INT_CST_HIGH (expr
) == high_value
);
2008 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
2011 /* Return 1 if EXPR is the integer constant minus one. */
2014 integer_minus_onep (const_tree expr
)
2018 if (TREE_CODE (expr
) == COMPLEX_CST
)
2019 return (integer_all_onesp (TREE_REALPART (expr
))
2020 && integer_zerop (TREE_IMAGPART (expr
)));
2022 return integer_all_onesp (expr
);
2025 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2029 integer_pow2p (const_tree expr
)
2032 unsigned HOST_WIDE_INT high
, low
;
2036 if (TREE_CODE (expr
) == COMPLEX_CST
2037 && integer_pow2p (TREE_REALPART (expr
))
2038 && integer_zerop (TREE_IMAGPART (expr
)))
2041 if (TREE_CODE (expr
) != INTEGER_CST
)
2044 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2045 high
= TREE_INT_CST_HIGH (expr
);
2046 low
= TREE_INT_CST_LOW (expr
);
2048 /* First clear all bits that are beyond the type's precision in case
2049 we've been sign extended. */
2051 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
2053 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2054 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
2058 if (prec
< HOST_BITS_PER_WIDE_INT
)
2059 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
2062 if (high
== 0 && low
== 0)
2065 return ((high
== 0 && (low
& (low
- 1)) == 0)
2066 || (low
== 0 && (high
& (high
- 1)) == 0));
2069 /* Return 1 if EXPR is an integer constant other than zero or a
2070 complex constant other than zero. */
2073 integer_nonzerop (const_tree expr
)
2077 return ((TREE_CODE (expr
) == INTEGER_CST
2078 && (TREE_INT_CST_LOW (expr
) != 0
2079 || TREE_INT_CST_HIGH (expr
) != 0))
2080 || (TREE_CODE (expr
) == COMPLEX_CST
2081 && (integer_nonzerop (TREE_REALPART (expr
))
2082 || integer_nonzerop (TREE_IMAGPART (expr
)))));
2085 /* Return 1 if EXPR is the fixed-point constant zero. */
2088 fixed_zerop (const_tree expr
)
2090 return (TREE_CODE (expr
) == FIXED_CST
2091 && TREE_FIXED_CST (expr
).data
.is_zero ());
2094 /* Return the power of two represented by a tree node known to be a
2098 tree_log2 (const_tree expr
)
2101 HOST_WIDE_INT high
, low
;
2105 if (TREE_CODE (expr
) == COMPLEX_CST
)
2106 return tree_log2 (TREE_REALPART (expr
));
2108 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2109 high
= TREE_INT_CST_HIGH (expr
);
2110 low
= TREE_INT_CST_LOW (expr
);
2112 /* First clear all bits that are beyond the type's precision in case
2113 we've been sign extended. */
2115 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
2117 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2118 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
2122 if (prec
< HOST_BITS_PER_WIDE_INT
)
2123 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
2126 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
2127 : exact_log2 (low
));
2130 /* Similar, but return the largest integer Y such that 2 ** Y is less
2131 than or equal to EXPR. */
2134 tree_floor_log2 (const_tree expr
)
2137 HOST_WIDE_INT high
, low
;
2141 if (TREE_CODE (expr
) == COMPLEX_CST
)
2142 return tree_log2 (TREE_REALPART (expr
));
2144 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2145 high
= TREE_INT_CST_HIGH (expr
);
2146 low
= TREE_INT_CST_LOW (expr
);
2148 /* First clear all bits that are beyond the type's precision in case
2149 we've been sign extended. Ignore if type's precision hasn't been set
2150 since what we are doing is setting it. */
2152 if (prec
== HOST_BITS_PER_DOUBLE_INT
|| prec
== 0)
2154 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2155 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
2159 if (prec
< HOST_BITS_PER_WIDE_INT
)
2160 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
2163 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
2164 : floor_log2 (low
));
2167 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2168 decimal float constants, so don't return 1 for them. */
2171 real_zerop (const_tree expr
)
2175 switch (TREE_CODE (expr
))
2178 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
2179 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2181 return real_zerop (TREE_REALPART (expr
))
2182 && real_zerop (TREE_IMAGPART (expr
));
2186 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2187 if (!real_zerop (VECTOR_CST_ELT (expr
, i
)))
2196 /* Return 1 if EXPR is the real constant one in real or complex form.
2197 Trailing zeroes matter for decimal float constants, so don't return
2201 real_onep (const_tree expr
)
2205 switch (TREE_CODE (expr
))
2208 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
2209 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2211 return real_onep (TREE_REALPART (expr
))
2212 && real_zerop (TREE_IMAGPART (expr
));
2216 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2217 if (!real_onep (VECTOR_CST_ELT (expr
, i
)))
2226 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
2227 for decimal float constants, so don't return 1 for them. */
2230 real_twop (const_tree expr
)
2234 switch (TREE_CODE (expr
))
2237 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
)
2238 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2240 return real_twop (TREE_REALPART (expr
))
2241 && real_zerop (TREE_IMAGPART (expr
));
2245 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2246 if (!real_twop (VECTOR_CST_ELT (expr
, i
)))
2255 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2256 matter for decimal float constants, so don't return 1 for them. */
2259 real_minus_onep (const_tree expr
)
2263 switch (TREE_CODE (expr
))
2266 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
2267 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2269 return real_minus_onep (TREE_REALPART (expr
))
2270 && real_zerop (TREE_IMAGPART (expr
));
2274 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2275 if (!real_minus_onep (VECTOR_CST_ELT (expr
, i
)))
2284 /* Nonzero if EXP is a constant or a cast of a constant. */
2287 really_constant_p (const_tree exp
)
2289 /* This is not quite the same as STRIP_NOPS. It does more. */
2290 while (CONVERT_EXPR_P (exp
)
2291 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2292 exp
= TREE_OPERAND (exp
, 0);
2293 return TREE_CONSTANT (exp
);
2296 /* Return first list element whose TREE_VALUE is ELEM.
2297 Return 0 if ELEM is not in LIST. */
2300 value_member (tree elem
, tree list
)
2304 if (elem
== TREE_VALUE (list
))
2306 list
= TREE_CHAIN (list
);
2311 /* Return first list element whose TREE_PURPOSE is ELEM.
2312 Return 0 if ELEM is not in LIST. */
2315 purpose_member (const_tree elem
, tree list
)
2319 if (elem
== TREE_PURPOSE (list
))
2321 list
= TREE_CHAIN (list
);
2326 /* Return true if ELEM is in V. */
2329 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
2333 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
2339 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2343 chain_index (int idx
, tree chain
)
2345 for (; chain
&& idx
> 0; --idx
)
2346 chain
= TREE_CHAIN (chain
);
2350 /* Return nonzero if ELEM is part of the chain CHAIN. */
2353 chain_member (const_tree elem
, const_tree chain
)
2359 chain
= DECL_CHAIN (chain
);
2365 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2366 We expect a null pointer to mark the end of the chain.
2367 This is the Lisp primitive `length'. */
2370 list_length (const_tree t
)
2373 #ifdef ENABLE_TREE_CHECKING
2381 #ifdef ENABLE_TREE_CHECKING
2384 gcc_assert (p
!= q
);
2392 /* Returns the number of FIELD_DECLs in TYPE. */
2395 fields_length (const_tree type
)
2397 tree t
= TYPE_FIELDS (type
);
2400 for (; t
; t
= DECL_CHAIN (t
))
2401 if (TREE_CODE (t
) == FIELD_DECL
)
2407 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2408 UNION_TYPE TYPE, or NULL_TREE if none. */
2411 first_field (const_tree type
)
2413 tree t
= TYPE_FIELDS (type
);
2414 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2419 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2420 by modifying the last node in chain 1 to point to chain 2.
2421 This is the Lisp primitive `nconc'. */
2424 chainon (tree op1
, tree op2
)
2433 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2435 TREE_CHAIN (t1
) = op2
;
2437 #ifdef ENABLE_TREE_CHECKING
2440 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2441 gcc_assert (t2
!= t1
);
2448 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2451 tree_last (tree chain
)
2455 while ((next
= TREE_CHAIN (chain
)))
2460 /* Reverse the order of elements in the chain T,
2461 and return the new head of the chain (old last element). */
2466 tree prev
= 0, decl
, next
;
2467 for (decl
= t
; decl
; decl
= next
)
2469 /* We shouldn't be using this function to reverse BLOCK chains; we
2470 have blocks_nreverse for that. */
2471 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2472 next
= TREE_CHAIN (decl
);
2473 TREE_CHAIN (decl
) = prev
;
2479 /* Return a newly created TREE_LIST node whose
2480 purpose and value fields are PARM and VALUE. */
2483 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2485 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2486 TREE_PURPOSE (t
) = parm
;
2487 TREE_VALUE (t
) = value
;
2491 /* Build a chain of TREE_LIST nodes from a vector. */
2494 build_tree_list_vec_stat (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
2496 tree ret
= NULL_TREE
;
2500 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
2502 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2503 pp
= &TREE_CHAIN (*pp
);
2508 /* Return a newly created TREE_LIST node whose
2509 purpose and value fields are PURPOSE and VALUE
2510 and whose TREE_CHAIN is CHAIN. */
2513 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2517 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
2518 memset (node
, 0, sizeof (struct tree_common
));
2520 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2522 TREE_SET_CODE (node
, TREE_LIST
);
2523 TREE_CHAIN (node
) = chain
;
2524 TREE_PURPOSE (node
) = purpose
;
2525 TREE_VALUE (node
) = value
;
2529 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2533 ctor_to_vec (tree ctor
)
2535 vec
<tree
, va_gc
> *vec
;
2536 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
2540 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2541 vec
->quick_push (val
);
2546 /* Return the size nominally occupied by an object of type TYPE
2547 when it resides in memory. The value is measured in units of bytes,
2548 and its data type is that normally used for type sizes
2549 (which is the first type created by make_signed_type or
2550 make_unsigned_type). */
2553 size_in_bytes (const_tree type
)
2557 if (type
== error_mark_node
)
2558 return integer_zero_node
;
2560 type
= TYPE_MAIN_VARIANT (type
);
2561 t
= TYPE_SIZE_UNIT (type
);
2565 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2566 return size_zero_node
;
2572 /* Return the size of TYPE (in bytes) as a wide integer
2573 or return -1 if the size can vary or is larger than an integer. */
2576 int_size_in_bytes (const_tree type
)
2580 if (type
== error_mark_node
)
2583 type
= TYPE_MAIN_VARIANT (type
);
2584 t
= TYPE_SIZE_UNIT (type
);
2586 || TREE_CODE (t
) != INTEGER_CST
2587 || TREE_INT_CST_HIGH (t
) != 0
2588 /* If the result would appear negative, it's too big to represent. */
2589 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
2592 return TREE_INT_CST_LOW (t
);
2595 /* Return the maximum size of TYPE (in bytes) as a wide integer
2596 or return -1 if the size can vary or is larger than an integer. */
2599 max_int_size_in_bytes (const_tree type
)
2601 HOST_WIDE_INT size
= -1;
2604 /* If this is an array type, check for a possible MAX_SIZE attached. */
2606 if (TREE_CODE (type
) == ARRAY_TYPE
)
2608 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2610 if (size_tree
&& host_integerp (size_tree
, 1))
2611 size
= tree_low_cst (size_tree
, 1);
2614 /* If we still haven't been able to get a size, see if the language
2615 can compute a maximum size. */
2619 size_tree
= lang_hooks
.types
.max_size (type
);
2621 if (size_tree
&& host_integerp (size_tree
, 1))
2622 size
= tree_low_cst (size_tree
, 1);
2628 /* Returns a tree for the size of EXP in bytes. */
2631 tree_expr_size (const_tree exp
)
2634 && DECL_SIZE_UNIT (exp
) != 0)
2635 return DECL_SIZE_UNIT (exp
);
2637 return size_in_bytes (TREE_TYPE (exp
));
2640 /* Return the bit position of FIELD, in bits from the start of the record.
2641 This is a tree of type bitsizetype. */
2644 bit_position (const_tree field
)
2646 return bit_from_pos (DECL_FIELD_OFFSET (field
),
2647 DECL_FIELD_BIT_OFFSET (field
));
2650 /* Likewise, but return as an integer. It must be representable in
2651 that way (since it could be a signed value, we don't have the
2652 option of returning -1 like int_size_in_byte can. */
2655 int_bit_position (const_tree field
)
2657 return tree_low_cst (bit_position (field
), 0);
2660 /* Return the byte position of FIELD, in bytes from the start of the record.
2661 This is a tree of type sizetype. */
2664 byte_position (const_tree field
)
2666 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2667 DECL_FIELD_BIT_OFFSET (field
));
2670 /* Likewise, but return as an integer. It must be representable in
2671 that way (since it could be a signed value, we don't have the
2672 option of returning -1 like int_size_in_byte can. */
2675 int_byte_position (const_tree field
)
2677 return tree_low_cst (byte_position (field
), 0);
2680 /* Return the strictest alignment, in bits, that T is known to have. */
2683 expr_align (const_tree t
)
2685 unsigned int align0
, align1
;
2687 switch (TREE_CODE (t
))
2689 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2690 /* If we have conversions, we know that the alignment of the
2691 object must meet each of the alignments of the types. */
2692 align0
= expr_align (TREE_OPERAND (t
, 0));
2693 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2694 return MAX (align0
, align1
);
2696 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2697 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2698 case CLEANUP_POINT_EXPR
:
2699 /* These don't change the alignment of an object. */
2700 return expr_align (TREE_OPERAND (t
, 0));
2703 /* The best we can do is say that the alignment is the least aligned
2705 align0
= expr_align (TREE_OPERAND (t
, 1));
2706 align1
= expr_align (TREE_OPERAND (t
, 2));
2707 return MIN (align0
, align1
);
2709 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2710 meaningfully, it's always 1. */
2711 case LABEL_DECL
: case CONST_DECL
:
2712 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2714 gcc_assert (DECL_ALIGN (t
) != 0);
2715 return DECL_ALIGN (t
);
2721 /* Otherwise take the alignment from that of the type. */
2722 return TYPE_ALIGN (TREE_TYPE (t
));
2725 /* Return, as a tree node, the number of elements for TYPE (which is an
2726 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2729 array_type_nelts (const_tree type
)
2731 tree index_type
, min
, max
;
2733 /* If they did it with unspecified bounds, then we should have already
2734 given an error about it before we got here. */
2735 if (! TYPE_DOMAIN (type
))
2736 return error_mark_node
;
2738 index_type
= TYPE_DOMAIN (type
);
2739 min
= TYPE_MIN_VALUE (index_type
);
2740 max
= TYPE_MAX_VALUE (index_type
);
2742 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
2744 return error_mark_node
;
2746 return (integer_zerop (min
)
2748 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2751 /* If arg is static -- a reference to an object in static storage -- then
2752 return the object. This is not the same as the C meaning of `static'.
2753 If arg isn't static, return NULL. */
2758 switch (TREE_CODE (arg
))
2761 /* Nested functions are static, even though taking their address will
2762 involve a trampoline as we unnest the nested function and create
2763 the trampoline on the tree level. */
2767 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2768 && ! DECL_THREAD_LOCAL_P (arg
)
2769 && ! DECL_DLLIMPORT_P (arg
)
2773 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2777 return TREE_STATIC (arg
) ? arg
: NULL
;
2784 /* If the thing being referenced is not a field, then it is
2785 something language specific. */
2786 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
2788 /* If we are referencing a bitfield, we can't evaluate an
2789 ADDR_EXPR at compile time and so it isn't a constant. */
2790 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2793 return staticp (TREE_OPERAND (arg
, 0));
2799 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2802 case ARRAY_RANGE_REF
:
2803 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2804 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2805 return staticp (TREE_OPERAND (arg
, 0));
2809 case COMPOUND_LITERAL_EXPR
:
2810 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
2820 /* Return whether OP is a DECL whose address is function-invariant. */
2823 decl_address_invariant_p (const_tree op
)
2825 /* The conditions below are slightly less strict than the one in
2828 switch (TREE_CODE (op
))
2837 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2838 || DECL_THREAD_LOCAL_P (op
)
2839 || DECL_CONTEXT (op
) == current_function_decl
2840 || decl_function_context (op
) == current_function_decl
)
2845 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2846 || decl_function_context (op
) == current_function_decl
)
2857 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2860 decl_address_ip_invariant_p (const_tree op
)
2862 /* The conditions below are slightly less strict than the one in
2865 switch (TREE_CODE (op
))
2873 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2874 && !DECL_DLLIMPORT_P (op
))
2875 || DECL_THREAD_LOCAL_P (op
))
2880 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2892 /* Return true if T is function-invariant (internal function, does
2893 not handle arithmetic; that's handled in skip_simple_arithmetic and
2894 tree_invariant_p). */
2896 static bool tree_invariant_p (tree t
);
2899 tree_invariant_p_1 (tree t
)
2903 if (TREE_CONSTANT (t
)
2904 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2907 switch (TREE_CODE (t
))
2913 op
= TREE_OPERAND (t
, 0);
2914 while (handled_component_p (op
))
2916 switch (TREE_CODE (op
))
2919 case ARRAY_RANGE_REF
:
2920 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2921 || TREE_OPERAND (op
, 2) != NULL_TREE
2922 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2927 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2933 op
= TREE_OPERAND (op
, 0);
2936 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2945 /* Return true if T is function-invariant. */
2948 tree_invariant_p (tree t
)
2950 tree inner
= skip_simple_arithmetic (t
);
2951 return tree_invariant_p_1 (inner
);
2954 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2955 Do this to any expression which may be used in more than one place,
2956 but must be evaluated only once.
2958 Normally, expand_expr would reevaluate the expression each time.
2959 Calling save_expr produces something that is evaluated and recorded
2960 the first time expand_expr is called on it. Subsequent calls to
2961 expand_expr just reuse the recorded value.
2963 The call to expand_expr that generates code that actually computes
2964 the value is the first call *at compile time*. Subsequent calls
2965 *at compile time* generate code to use the saved value.
2966 This produces correct result provided that *at run time* control
2967 always flows through the insns made by the first expand_expr
2968 before reaching the other places where the save_expr was evaluated.
2969 You, the caller of save_expr, must make sure this is so.
2971 Constants, and certain read-only nodes, are returned with no
2972 SAVE_EXPR because that is safe. Expressions containing placeholders
2973 are not touched; see tree.def for an explanation of what these
2977 save_expr (tree expr
)
2979 tree t
= fold (expr
);
2982 /* If the tree evaluates to a constant, then we don't want to hide that
2983 fact (i.e. this allows further folding, and direct checks for constants).
2984 However, a read-only object that has side effects cannot be bypassed.
2985 Since it is no problem to reevaluate literals, we just return the
2987 inner
= skip_simple_arithmetic (t
);
2988 if (TREE_CODE (inner
) == ERROR_MARK
)
2991 if (tree_invariant_p_1 (inner
))
2994 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2995 it means that the size or offset of some field of an object depends on
2996 the value within another field.
2998 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2999 and some variable since it would then need to be both evaluated once and
3000 evaluated more than once. Front-ends must assure this case cannot
3001 happen by surrounding any such subexpressions in their own SAVE_EXPR
3002 and forcing evaluation at the proper time. */
3003 if (contains_placeholder_p (inner
))
3006 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
3007 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
3009 /* This expression might be placed ahead of a jump to ensure that the
3010 value was computed on both sides of the jump. So make sure it isn't
3011 eliminated as dead. */
3012 TREE_SIDE_EFFECTS (t
) = 1;
3016 /* Look inside EXPR into any simple arithmetic operations. Return the
3017 outermost non-arithmetic or non-invariant node. */
3020 skip_simple_arithmetic (tree expr
)
3022 /* We don't care about whether this can be used as an lvalue in this
3024 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3025 expr
= TREE_OPERAND (expr
, 0);
3027 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3028 a constant, it will be more efficient to not make another SAVE_EXPR since
3029 it will allow better simplification and GCSE will be able to merge the
3030 computations if they actually occur. */
3033 if (UNARY_CLASS_P (expr
))
3034 expr
= TREE_OPERAND (expr
, 0);
3035 else if (BINARY_CLASS_P (expr
))
3037 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
3038 expr
= TREE_OPERAND (expr
, 0);
3039 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
3040 expr
= TREE_OPERAND (expr
, 1);
3051 /* Look inside EXPR into simple arithmetic operations involving constants.
3052 Return the outermost non-arithmetic or non-constant node. */
3055 skip_simple_constant_arithmetic (tree expr
)
3057 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3058 expr
= TREE_OPERAND (expr
, 0);
3062 if (UNARY_CLASS_P (expr
))
3063 expr
= TREE_OPERAND (expr
, 0);
3064 else if (BINARY_CLASS_P (expr
))
3066 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
3067 expr
= TREE_OPERAND (expr
, 0);
3068 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3069 expr
= TREE_OPERAND (expr
, 1);
3080 /* Return which tree structure is used by T. */
3082 enum tree_node_structure_enum
3083 tree_node_structure (const_tree t
)
3085 const enum tree_code code
= TREE_CODE (t
);
3086 return tree_node_structure_for_code (code
);
3089 /* Set various status flags when building a CALL_EXPR object T. */
3092 process_call_operands (tree t
)
3094 bool side_effects
= TREE_SIDE_EFFECTS (t
);
3095 bool read_only
= false;
3096 int i
= call_expr_flags (t
);
3098 /* Calls have side-effects, except those to const or pure functions. */
3099 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
3100 side_effects
= true;
3101 /* Propagate TREE_READONLY of arguments for const functions. */
3105 if (!side_effects
|| read_only
)
3106 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3108 tree op
= TREE_OPERAND (t
, i
);
3109 if (op
&& TREE_SIDE_EFFECTS (op
))
3110 side_effects
= true;
3111 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3115 TREE_SIDE_EFFECTS (t
) = side_effects
;
3116 TREE_READONLY (t
) = read_only
;
3119 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3120 size or offset that depends on a field within a record. */
3123 contains_placeholder_p (const_tree exp
)
3125 enum tree_code code
;
3130 code
= TREE_CODE (exp
);
3131 if (code
== PLACEHOLDER_EXPR
)
3134 switch (TREE_CODE_CLASS (code
))
3137 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3138 position computations since they will be converted into a
3139 WITH_RECORD_EXPR involving the reference, which will assume
3140 here will be valid. */
3141 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3143 case tcc_exceptional
:
3144 if (code
== TREE_LIST
)
3145 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3146 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3151 case tcc_comparison
:
3152 case tcc_expression
:
3156 /* Ignoring the first operand isn't quite right, but works best. */
3157 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
3160 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3161 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
3162 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
3165 /* The save_expr function never wraps anything containing
3166 a PLACEHOLDER_EXPR. */
3173 switch (TREE_CODE_LENGTH (code
))
3176 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3178 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3179 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
3190 const_call_expr_arg_iterator iter
;
3191 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
3192 if (CONTAINS_PLACEHOLDER_P (arg
))
3206 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3207 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3211 type_contains_placeholder_1 (const_tree type
)
3213 /* If the size contains a placeholder or the parent type (component type in
3214 the case of arrays) type involves a placeholder, this type does. */
3215 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
3216 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
3217 || (!POINTER_TYPE_P (type
)
3219 && type_contains_placeholder_p (TREE_TYPE (type
))))
3222 /* Now do type-specific checks. Note that the last part of the check above
3223 greatly limits what we have to do below. */
3224 switch (TREE_CODE (type
))
3232 case REFERENCE_TYPE
:
3241 case FIXED_POINT_TYPE
:
3242 /* Here we just check the bounds. */
3243 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
3244 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
3247 /* We have already checked the component type above, so just check the
3249 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
3253 case QUAL_UNION_TYPE
:
3257 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
3258 if (TREE_CODE (field
) == FIELD_DECL
3259 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
3260 || (TREE_CODE (type
) == QUAL_UNION_TYPE
3261 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
3262 || type_contains_placeholder_p (TREE_TYPE (field
))))
3273 /* Wrapper around above function used to cache its result. */
3276 type_contains_placeholder_p (tree type
)
3280 /* If the contains_placeholder_bits field has been initialized,
3281 then we know the answer. */
3282 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
3283 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
3285 /* Indicate that we've seen this type node, and the answer is false.
3286 This is what we want to return if we run into recursion via fields. */
3287 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
3289 /* Compute the real value. */
3290 result
= type_contains_placeholder_1 (type
);
3292 /* Store the real value. */
3293 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
3298 /* Push tree EXP onto vector QUEUE if it is not already present. */
3301 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
3306 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
3307 if (simple_cst_equal (iter
, exp
) == 1)
3311 queue
->safe_push (exp
);
3314 /* Given a tree EXP, find all occurrences of references to fields
3315 in a PLACEHOLDER_EXPR and place them in vector REFS without
3316 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3317 we assume here that EXP contains only arithmetic expressions
3318 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3322 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
3324 enum tree_code code
= TREE_CODE (exp
);
3328 /* We handle TREE_LIST and COMPONENT_REF separately. */
3329 if (code
== TREE_LIST
)
3331 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3332 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3334 else if (code
== COMPONENT_REF
)
3336 for (inner
= TREE_OPERAND (exp
, 0);
3337 REFERENCE_CLASS_P (inner
);
3338 inner
= TREE_OPERAND (inner
, 0))
3341 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3342 push_without_duplicates (exp
, refs
);
3344 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3347 switch (TREE_CODE_CLASS (code
))
3352 case tcc_declaration
:
3353 /* Variables allocated to static storage can stay. */
3354 if (!TREE_STATIC (exp
))
3355 push_without_duplicates (exp
, refs
);
3358 case tcc_expression
:
3359 /* This is the pattern built in ada/make_aligning_type. */
3360 if (code
== ADDR_EXPR
3361 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3363 push_without_duplicates (exp
, refs
);
3367 /* Fall through... */
3369 case tcc_exceptional
:
3372 case tcc_comparison
:
3374 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3375 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3379 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3380 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3388 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3389 return a tree with all occurrences of references to F in a
3390 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3391 CONST_DECLs. Note that we assume here that EXP contains only
3392 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3393 occurring only in their argument list. */
3396 substitute_in_expr (tree exp
, tree f
, tree r
)
3398 enum tree_code code
= TREE_CODE (exp
);
3399 tree op0
, op1
, op2
, op3
;
3402 /* We handle TREE_LIST and COMPONENT_REF separately. */
3403 if (code
== TREE_LIST
)
3405 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3406 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3407 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3410 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3412 else if (code
== COMPONENT_REF
)
3416 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3417 and it is the right field, replace it with R. */
3418 for (inner
= TREE_OPERAND (exp
, 0);
3419 REFERENCE_CLASS_P (inner
);
3420 inner
= TREE_OPERAND (inner
, 0))
3424 op1
= TREE_OPERAND (exp
, 1);
3426 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3429 /* If this expression hasn't been completed let, leave it alone. */
3430 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3433 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3434 if (op0
== TREE_OPERAND (exp
, 0))
3438 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3441 switch (TREE_CODE_CLASS (code
))
3446 case tcc_declaration
:
3452 case tcc_expression
:
3456 /* Fall through... */
3458 case tcc_exceptional
:
3461 case tcc_comparison
:
3463 switch (TREE_CODE_LENGTH (code
))
3469 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3470 if (op0
== TREE_OPERAND (exp
, 0))
3473 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3477 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3478 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3480 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3483 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3487 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3488 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3489 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3491 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3492 && op2
== TREE_OPERAND (exp
, 2))
3495 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3499 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3500 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3501 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3502 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3504 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3505 && op2
== TREE_OPERAND (exp
, 2)
3506 && op3
== TREE_OPERAND (exp
, 3))
3510 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3522 new_tree
= NULL_TREE
;
3524 /* If we are trying to replace F with a constant, inline back
3525 functions which do nothing else than computing a value from
3526 the arguments they are passed. This makes it possible to
3527 fold partially or entirely the replacement expression. */
3528 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3530 tree t
= maybe_inline_call_in_expr (exp
);
3532 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3535 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3537 tree op
= TREE_OPERAND (exp
, i
);
3538 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3542 new_tree
= copy_node (exp
);
3543 TREE_OPERAND (new_tree
, i
) = new_op
;
3549 new_tree
= fold (new_tree
);
3550 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3551 process_call_operands (new_tree
);
3562 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3564 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3565 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3570 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3571 for it within OBJ, a tree that is an object or a chain of references. */
3574 substitute_placeholder_in_expr (tree exp
, tree obj
)
3576 enum tree_code code
= TREE_CODE (exp
);
3577 tree op0
, op1
, op2
, op3
;
3580 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3581 in the chain of OBJ. */
3582 if (code
== PLACEHOLDER_EXPR
)
3584 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3587 for (elt
= obj
; elt
!= 0;
3588 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3589 || TREE_CODE (elt
) == COND_EXPR
)
3590 ? TREE_OPERAND (elt
, 1)
3591 : (REFERENCE_CLASS_P (elt
)
3592 || UNARY_CLASS_P (elt
)
3593 || BINARY_CLASS_P (elt
)
3594 || VL_EXP_CLASS_P (elt
)
3595 || EXPRESSION_CLASS_P (elt
))
3596 ? TREE_OPERAND (elt
, 0) : 0))
3597 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3600 for (elt
= obj
; elt
!= 0;
3601 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3602 || TREE_CODE (elt
) == COND_EXPR
)
3603 ? TREE_OPERAND (elt
, 1)
3604 : (REFERENCE_CLASS_P (elt
)
3605 || UNARY_CLASS_P (elt
)
3606 || BINARY_CLASS_P (elt
)
3607 || VL_EXP_CLASS_P (elt
)
3608 || EXPRESSION_CLASS_P (elt
))
3609 ? TREE_OPERAND (elt
, 0) : 0))
3610 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3611 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3613 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3615 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3616 survives until RTL generation, there will be an error. */
3620 /* TREE_LIST is special because we need to look at TREE_VALUE
3621 and TREE_CHAIN, not TREE_OPERANDS. */
3622 else if (code
== TREE_LIST
)
3624 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3625 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3626 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3629 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3632 switch (TREE_CODE_CLASS (code
))
3635 case tcc_declaration
:
3638 case tcc_exceptional
:
3641 case tcc_comparison
:
3642 case tcc_expression
:
3645 switch (TREE_CODE_LENGTH (code
))
3651 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3652 if (op0
== TREE_OPERAND (exp
, 0))
3655 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3659 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3660 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3662 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3665 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3669 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3670 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3671 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3673 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3674 && op2
== TREE_OPERAND (exp
, 2))
3677 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3681 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3682 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3683 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3684 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3686 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3687 && op2
== TREE_OPERAND (exp
, 2)
3688 && op3
== TREE_OPERAND (exp
, 3))
3692 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3704 new_tree
= NULL_TREE
;
3706 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3708 tree op
= TREE_OPERAND (exp
, i
);
3709 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
3713 new_tree
= copy_node (exp
);
3714 TREE_OPERAND (new_tree
, i
) = new_op
;
3720 new_tree
= fold (new_tree
);
3721 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3722 process_call_operands (new_tree
);
3733 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3735 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3736 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3741 /* Stabilize a reference so that we can use it any number of times
3742 without causing its operands to be evaluated more than once.
3743 Returns the stabilized reference. This works by means of save_expr,
3744 so see the caveats in the comments about save_expr.
3746 Also allows conversion expressions whose operands are references.
3747 Any other kind of expression is returned unchanged. */
3750 stabilize_reference (tree ref
)
3753 enum tree_code code
= TREE_CODE (ref
);
3760 /* No action is needed in this case. */
3765 case FIX_TRUNC_EXPR
:
3766 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
3770 result
= build_nt (INDIRECT_REF
,
3771 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
3775 result
= build_nt (COMPONENT_REF
,
3776 stabilize_reference (TREE_OPERAND (ref
, 0)),
3777 TREE_OPERAND (ref
, 1), NULL_TREE
);
3781 result
= build_nt (BIT_FIELD_REF
,
3782 stabilize_reference (TREE_OPERAND (ref
, 0)),
3783 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
3787 result
= build_nt (ARRAY_REF
,
3788 stabilize_reference (TREE_OPERAND (ref
, 0)),
3789 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3790 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3793 case ARRAY_RANGE_REF
:
3794 result
= build_nt (ARRAY_RANGE_REF
,
3795 stabilize_reference (TREE_OPERAND (ref
, 0)),
3796 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3797 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3801 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3802 it wouldn't be ignored. This matters when dealing with
3804 return stabilize_reference_1 (ref
);
3806 /* If arg isn't a kind of lvalue we recognize, make no change.
3807 Caller should recognize the error for an invalid lvalue. */
3812 return error_mark_node
;
3815 TREE_TYPE (result
) = TREE_TYPE (ref
);
3816 TREE_READONLY (result
) = TREE_READONLY (ref
);
3817 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3818 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3823 /* Subroutine of stabilize_reference; this is called for subtrees of
3824 references. Any expression with side-effects must be put in a SAVE_EXPR
3825 to ensure that it is only evaluated once.
3827 We don't put SAVE_EXPR nodes around everything, because assigning very
3828 simple expressions to temporaries causes us to miss good opportunities
3829 for optimizations. Among other things, the opportunity to fold in the
3830 addition of a constant into an addressing mode often gets lost, e.g.
3831 "y[i+1] += x;". In general, we take the approach that we should not make
3832 an assignment unless we are forced into it - i.e., that any non-side effect
3833 operator should be allowed, and that cse should take care of coalescing
3834 multiple utterances of the same expression should that prove fruitful. */
3837 stabilize_reference_1 (tree e
)
3840 enum tree_code code
= TREE_CODE (e
);
3842 /* We cannot ignore const expressions because it might be a reference
3843 to a const array but whose index contains side-effects. But we can
3844 ignore things that are actual constant or that already have been
3845 handled by this function. */
3847 if (tree_invariant_p (e
))
3850 switch (TREE_CODE_CLASS (code
))
3852 case tcc_exceptional
:
3854 case tcc_declaration
:
3855 case tcc_comparison
:
3857 case tcc_expression
:
3860 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3861 so that it will only be evaluated once. */
3862 /* The reference (r) and comparison (<) classes could be handled as
3863 below, but it is generally faster to only evaluate them once. */
3864 if (TREE_SIDE_EFFECTS (e
))
3865 return save_expr (e
);
3869 /* Constants need no processing. In fact, we should never reach
3874 /* Division is slow and tends to be compiled with jumps,
3875 especially the division by powers of 2 that is often
3876 found inside of an array reference. So do it just once. */
3877 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3878 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3879 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3880 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3881 return save_expr (e
);
3882 /* Recursively stabilize each operand. */
3883 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3884 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3888 /* Recursively stabilize each operand. */
3889 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3896 TREE_TYPE (result
) = TREE_TYPE (e
);
3897 TREE_READONLY (result
) = TREE_READONLY (e
);
3898 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3899 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3904 /* Low-level constructors for expressions. */
3906 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3907 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3910 recompute_tree_invariant_for_addr_expr (tree t
)
3913 bool tc
= true, se
= false;
3915 /* We started out assuming this address is both invariant and constant, but
3916 does not have side effects. Now go down any handled components and see if
3917 any of them involve offsets that are either non-constant or non-invariant.
3918 Also check for side-effects.
3920 ??? Note that this code makes no attempt to deal with the case where
3921 taking the address of something causes a copy due to misalignment. */
3923 #define UPDATE_FLAGS(NODE) \
3924 do { tree _node = (NODE); \
3925 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3926 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3928 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3929 node
= TREE_OPERAND (node
, 0))
3931 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3932 array reference (probably made temporarily by the G++ front end),
3933 so ignore all the operands. */
3934 if ((TREE_CODE (node
) == ARRAY_REF
3935 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3936 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3938 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3939 if (TREE_OPERAND (node
, 2))
3940 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3941 if (TREE_OPERAND (node
, 3))
3942 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3944 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3945 FIELD_DECL, apparently. The G++ front end can put something else
3946 there, at least temporarily. */
3947 else if (TREE_CODE (node
) == COMPONENT_REF
3948 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3950 if (TREE_OPERAND (node
, 2))
3951 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3955 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3957 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3958 the address, since &(*a)->b is a form of addition. If it's a constant, the
3959 address is constant too. If it's a decl, its address is constant if the
3960 decl is static. Everything else is not constant and, furthermore,
3961 taking the address of a volatile variable is not volatile. */
3962 if (TREE_CODE (node
) == INDIRECT_REF
3963 || TREE_CODE (node
) == MEM_REF
)
3964 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3965 else if (CONSTANT_CLASS_P (node
))
3967 else if (DECL_P (node
))
3968 tc
&= (staticp (node
) != NULL_TREE
);
3972 se
|= TREE_SIDE_EFFECTS (node
);
3976 TREE_CONSTANT (t
) = tc
;
3977 TREE_SIDE_EFFECTS (t
) = se
;
3981 /* Build an expression of code CODE, data type TYPE, and operands as
3982 specified. Expressions and reference nodes can be created this way.
3983 Constants, decls, types and misc nodes cannot be.
3985 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3986 enough for all extant tree codes. */
3989 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3993 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3995 t
= make_node_stat (code PASS_MEM_STAT
);
4002 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
4004 int length
= sizeof (struct tree_exp
);
4007 record_node_allocation_statistics (code
, length
);
4009 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
4011 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
4013 memset (t
, 0, sizeof (struct tree_common
));
4015 TREE_SET_CODE (t
, code
);
4017 TREE_TYPE (t
) = type
;
4018 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
4019 TREE_OPERAND (t
, 0) = node
;
4020 if (node
&& !TYPE_P (node
))
4022 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
4023 TREE_READONLY (t
) = TREE_READONLY (node
);
4026 if (TREE_CODE_CLASS (code
) == tcc_statement
)
4027 TREE_SIDE_EFFECTS (t
) = 1;
4031 /* All of these have side-effects, no matter what their
4033 TREE_SIDE_EFFECTS (t
) = 1;
4034 TREE_READONLY (t
) = 0;
4038 /* Whether a dereference is readonly has nothing to do with whether
4039 its operand is readonly. */
4040 TREE_READONLY (t
) = 0;
4045 recompute_tree_invariant_for_addr_expr (t
);
4049 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
4050 && node
&& !TYPE_P (node
)
4051 && TREE_CONSTANT (node
))
4052 TREE_CONSTANT (t
) = 1;
4053 if (TREE_CODE_CLASS (code
) == tcc_reference
4054 && node
&& TREE_THIS_VOLATILE (node
))
4055 TREE_THIS_VOLATILE (t
) = 1;
4062 #define PROCESS_ARG(N) \
4064 TREE_OPERAND (t, N) = arg##N; \
4065 if (arg##N &&!TYPE_P (arg##N)) \
4067 if (TREE_SIDE_EFFECTS (arg##N)) \
4069 if (!TREE_READONLY (arg##N) \
4070 && !CONSTANT_CLASS_P (arg##N)) \
4071 (void) (read_only = 0); \
4072 if (!TREE_CONSTANT (arg##N)) \
4073 (void) (constant = 0); \
4078 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
4080 bool constant
, read_only
, side_effects
;
4083 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
4085 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
4086 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
4087 /* When sizetype precision doesn't match that of pointers
4088 we need to be able to build explicit extensions or truncations
4089 of the offset argument. */
4090 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
4091 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
4092 && TREE_CODE (arg1
) == INTEGER_CST
);
4094 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4095 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4096 && ptrofftype_p (TREE_TYPE (arg1
)));
4098 t
= make_node_stat (code PASS_MEM_STAT
);
4101 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4102 result based on those same flags for the arguments. But if the
4103 arguments aren't really even `tree' expressions, we shouldn't be trying
4106 /* Expressions without side effects may be constant if their
4107 arguments are as well. */
4108 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4109 || TREE_CODE_CLASS (code
) == tcc_binary
);
4111 side_effects
= TREE_SIDE_EFFECTS (t
);
4116 TREE_READONLY (t
) = read_only
;
4117 TREE_CONSTANT (t
) = constant
;
4118 TREE_SIDE_EFFECTS (t
) = side_effects
;
4119 TREE_THIS_VOLATILE (t
)
4120 = (TREE_CODE_CLASS (code
) == tcc_reference
4121 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4128 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4129 tree arg2 MEM_STAT_DECL
)
4131 bool constant
, read_only
, side_effects
;
4134 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
4135 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4137 t
= make_node_stat (code PASS_MEM_STAT
);
4142 /* As a special exception, if COND_EXPR has NULL branches, we
4143 assume that it is a gimple statement and always consider
4144 it to have side effects. */
4145 if (code
== COND_EXPR
4146 && tt
== void_type_node
4147 && arg1
== NULL_TREE
4148 && arg2
== NULL_TREE
)
4149 side_effects
= true;
4151 side_effects
= TREE_SIDE_EFFECTS (t
);
4157 if (code
== COND_EXPR
)
4158 TREE_READONLY (t
) = read_only
;
4160 TREE_SIDE_EFFECTS (t
) = side_effects
;
4161 TREE_THIS_VOLATILE (t
)
4162 = (TREE_CODE_CLASS (code
) == tcc_reference
4163 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4169 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4170 tree arg2
, tree arg3 MEM_STAT_DECL
)
4172 bool constant
, read_only
, side_effects
;
4175 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
4177 t
= make_node_stat (code PASS_MEM_STAT
);
4180 side_effects
= TREE_SIDE_EFFECTS (t
);
4187 TREE_SIDE_EFFECTS (t
) = side_effects
;
4188 TREE_THIS_VOLATILE (t
)
4189 = (TREE_CODE_CLASS (code
) == tcc_reference
4190 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4196 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4197 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
4199 bool constant
, read_only
, side_effects
;
4202 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
4204 t
= make_node_stat (code PASS_MEM_STAT
);
4207 side_effects
= TREE_SIDE_EFFECTS (t
);
4215 TREE_SIDE_EFFECTS (t
) = side_effects
;
4216 TREE_THIS_VOLATILE (t
)
4217 = (TREE_CODE_CLASS (code
) == tcc_reference
4218 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4223 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4224 on the pointer PTR. */
4227 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
4229 HOST_WIDE_INT offset
= 0;
4230 tree ptype
= TREE_TYPE (ptr
);
4232 /* For convenience allow addresses that collapse to a simple base
4234 if (TREE_CODE (ptr
) == ADDR_EXPR
4235 && (handled_component_p (TREE_OPERAND (ptr
, 0))
4236 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
4238 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
4240 ptr
= build_fold_addr_expr (ptr
);
4241 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
4243 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
4244 ptr
, build_int_cst (ptype
, offset
));
4245 SET_EXPR_LOCATION (tem
, loc
);
4249 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4252 mem_ref_offset (const_tree t
)
4254 tree toff
= TREE_OPERAND (t
, 1);
4255 return tree_to_double_int (toff
).sext (TYPE_PRECISION (TREE_TYPE (toff
)));
4258 /* Return the pointer-type relevant for TBAA purposes from the
4259 gimple memory reference tree T. This is the type to be used for
4260 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T. */
4263 reference_alias_ptr_type (const_tree t
)
4265 const_tree base
= t
;
4266 while (handled_component_p (base
))
4267 base
= TREE_OPERAND (base
, 0);
4268 if (TREE_CODE (base
) == MEM_REF
)
4269 return TREE_TYPE (TREE_OPERAND (base
, 1));
4270 else if (TREE_CODE (base
) == TARGET_MEM_REF
)
4271 return TREE_TYPE (TMR_OFFSET (base
));
4273 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (base
)));
4276 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4277 offsetted by OFFSET units. */
4280 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4282 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4283 build_fold_addr_expr (base
),
4284 build_int_cst (ptr_type_node
, offset
));
4285 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4286 recompute_tree_invariant_for_addr_expr (addr
);
4290 /* Similar except don't specify the TREE_TYPE
4291 and leave the TREE_SIDE_EFFECTS as 0.
4292 It is permissible for arguments to be null,
4293 or even garbage if their values do not matter. */
4296 build_nt (enum tree_code code
, ...)
4303 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4307 t
= make_node (code
);
4308 length
= TREE_CODE_LENGTH (code
);
4310 for (i
= 0; i
< length
; i
++)
4311 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4317 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4321 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
4326 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
4327 CALL_EXPR_FN (ret
) = fn
;
4328 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4329 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
4330 CALL_EXPR_ARG (ret
, ix
) = t
;
4334 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4335 We do NOT enter this node in any sort of symbol table.
4337 LOC is the location of the decl.
4339 layout_decl is used to set up the decl's storage layout.
4340 Other slots are initialized to 0 or null pointers. */
4343 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4344 tree type MEM_STAT_DECL
)
4348 t
= make_node_stat (code PASS_MEM_STAT
);
4349 DECL_SOURCE_LOCATION (t
) = loc
;
4351 /* if (type == error_mark_node)
4352 type = integer_type_node; */
4353 /* That is not done, deliberately, so that having error_mark_node
4354 as the type can suppress useless errors in the use of this variable. */
4356 DECL_NAME (t
) = name
;
4357 TREE_TYPE (t
) = type
;
4359 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4365 /* Builds and returns function declaration with NAME and TYPE. */
4368 build_fn_decl (const char *name
, tree type
)
4370 tree id
= get_identifier (name
);
4371 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4373 DECL_EXTERNAL (decl
) = 1;
4374 TREE_PUBLIC (decl
) = 1;
4375 DECL_ARTIFICIAL (decl
) = 1;
4376 TREE_NOTHROW (decl
) = 1;
4381 vec
<tree
, va_gc
> *all_translation_units
;
4383 /* Builds a new translation-unit decl with name NAME, queues it in the
4384 global list of translation-unit decls and returns it. */
4387 build_translation_unit_decl (tree name
)
4389 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4391 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4392 vec_safe_push (all_translation_units
, tu
);
4397 /* BLOCK nodes are used to represent the structure of binding contours
4398 and declarations, once those contours have been exited and their contents
4399 compiled. This information is used for outputting debugging info. */
4402 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4404 tree block
= make_node (BLOCK
);
4406 BLOCK_VARS (block
) = vars
;
4407 BLOCK_SUBBLOCKS (block
) = subblocks
;
4408 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4409 BLOCK_CHAIN (block
) = chain
;
4414 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4416 LOC is the location to use in tree T. */
4419 protected_set_expr_location (tree t
, location_t loc
)
4421 if (t
&& CAN_HAVE_LOCATION_P (t
))
4422 SET_EXPR_LOCATION (t
, loc
);
4425 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4429 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4431 DECL_ATTRIBUTES (ddecl
) = attribute
;
4435 /* Borrowed from hashtab.c iterative_hash implementation. */
4436 #define mix(a,b,c) \
4438 a -= b; a -= c; a ^= (c>>13); \
4439 b -= c; b -= a; b ^= (a<< 8); \
4440 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4441 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4442 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4443 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4444 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4445 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4446 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4450 /* Produce good hash value combining VAL and VAL2. */
4452 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
4454 /* the golden ratio; an arbitrary value. */
4455 hashval_t a
= 0x9e3779b9;
4461 /* Produce good hash value combining VAL and VAL2. */
4463 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
4465 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
4466 return iterative_hash_hashval_t (val
, val2
);
4469 hashval_t a
= (hashval_t
) val
;
4470 /* Avoid warnings about shifting of more than the width of the type on
4471 hosts that won't execute this path. */
4473 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
4475 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
4477 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
4478 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
4485 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4486 is ATTRIBUTE and its qualifiers are QUALS.
4488 Record such modified types already made so we don't make duplicates. */
4491 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4493 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4495 hashval_t hashcode
= 0;
4497 enum tree_code code
= TREE_CODE (ttype
);
4499 /* Building a distinct copy of a tagged type is inappropriate; it
4500 causes breakage in code that expects there to be a one-to-one
4501 relationship between a struct and its fields.
4502 build_duplicate_type is another solution (as used in
4503 handle_transparent_union_attribute), but that doesn't play well
4504 with the stronger C++ type identity model. */
4505 if (TREE_CODE (ttype
) == RECORD_TYPE
4506 || TREE_CODE (ttype
) == UNION_TYPE
4507 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4508 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4510 warning (OPT_Wattributes
,
4511 "ignoring attributes applied to %qT after definition",
4512 TYPE_MAIN_VARIANT (ttype
));
4513 return build_qualified_type (ttype
, quals
);
4516 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4517 ntype
= build_distinct_type_copy (ttype
);
4519 TYPE_ATTRIBUTES (ntype
) = attribute
;
4521 hashcode
= iterative_hash_object (code
, hashcode
);
4522 if (TREE_TYPE (ntype
))
4523 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
4525 hashcode
= attribute_hash_list (attribute
, hashcode
);
4527 switch (TREE_CODE (ntype
))
4530 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
4533 if (TYPE_DOMAIN (ntype
))
4534 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
4538 hashcode
= iterative_hash_object
4539 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
4540 hashcode
= iterative_hash_object
4541 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
4544 case FIXED_POINT_TYPE
:
4546 unsigned int precision
= TYPE_PRECISION (ntype
);
4547 hashcode
= iterative_hash_object (precision
, hashcode
);
4554 ntype
= type_hash_canon (hashcode
, ntype
);
4556 /* If the target-dependent attributes make NTYPE different from
4557 its canonical type, we will need to use structural equality
4558 checks for this type. */
4559 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4560 || !comp_type_attributes (ntype
, ttype
))
4561 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4562 else if (TYPE_CANONICAL (ntype
) == ntype
)
4563 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4565 ttype
= build_qualified_type (ntype
, quals
);
4567 else if (TYPE_QUALS (ttype
) != quals
)
4568 ttype
= build_qualified_type (ttype
, quals
);
4573 /* Compare two attributes for their value identity. Return true if the
4574 attribute values are known to be equal; otherwise return false.
4578 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4580 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4583 if (TREE_VALUE (attr1
) != NULL_TREE
4584 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4585 && TREE_VALUE (attr2
) != NULL
4586 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4587 return (simple_cst_list_equal (TREE_VALUE (attr1
),
4588 TREE_VALUE (attr2
)) == 1);
4590 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
4593 /* Return 0 if the attributes for two types are incompatible, 1 if they
4594 are compatible, and 2 if they are nearly compatible (which causes a
4595 warning to be generated). */
4597 comp_type_attributes (const_tree type1
, const_tree type2
)
4599 const_tree a1
= TYPE_ATTRIBUTES (type1
);
4600 const_tree a2
= TYPE_ATTRIBUTES (type2
);
4605 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4607 const struct attribute_spec
*as
;
4610 as
= lookup_attribute_spec (get_attribute_name (a
));
4611 if (!as
|| as
->affects_type_identity
== false)
4614 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
4615 if (!attr
|| !attribute_value_equal (a
, attr
))
4620 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4622 const struct attribute_spec
*as
;
4624 as
= lookup_attribute_spec (get_attribute_name (a
));
4625 if (!as
|| as
->affects_type_identity
== false)
4628 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
4630 /* We don't need to compare trees again, as we did this
4631 already in first loop. */
4633 /* All types - affecting identity - are equal, so
4634 there is no need to call target hook for comparison. */
4638 /* As some type combinations - like default calling-convention - might
4639 be compatible, we have to call the target hook to get the final result. */
4640 return targetm
.comp_type_attributes (type1
, type2
);
4643 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4646 Record such modified types already made so we don't make duplicates. */
4649 build_type_attribute_variant (tree ttype
, tree attribute
)
4651 return build_type_attribute_qual_variant (ttype
, attribute
,
4652 TYPE_QUALS (ttype
));
4656 /* Reset the expression *EXPR_P, a size or position.
4658 ??? We could reset all non-constant sizes or positions. But it's cheap
4659 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4661 We need to reset self-referential sizes or positions because they cannot
4662 be gimplified and thus can contain a CALL_EXPR after the gimplification
4663 is finished, which will run afoul of LTO streaming. And they need to be
4664 reset to something essentially dummy but not constant, so as to preserve
4665 the properties of the object they are attached to. */
4668 free_lang_data_in_one_sizepos (tree
*expr_p
)
4670 tree expr
= *expr_p
;
4671 if (CONTAINS_PLACEHOLDER_P (expr
))
4672 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
4676 /* Reset all the fields in a binfo node BINFO. We only keep
4677 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
4680 free_lang_data_in_binfo (tree binfo
)
4685 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
4687 BINFO_VIRTUALS (binfo
) = NULL_TREE
;
4688 BINFO_BASE_ACCESSES (binfo
) = NULL
;
4689 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
4690 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
4692 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo
), i
, t
)
4693 free_lang_data_in_binfo (t
);
4697 /* Reset all language specific information still present in TYPE. */
4700 free_lang_data_in_type (tree type
)
4702 gcc_assert (TYPE_P (type
));
4704 /* Give the FE a chance to remove its own data first. */
4705 lang_hooks
.free_lang_data (type
);
4707 TREE_LANG_FLAG_0 (type
) = 0;
4708 TREE_LANG_FLAG_1 (type
) = 0;
4709 TREE_LANG_FLAG_2 (type
) = 0;
4710 TREE_LANG_FLAG_3 (type
) = 0;
4711 TREE_LANG_FLAG_4 (type
) = 0;
4712 TREE_LANG_FLAG_5 (type
) = 0;
4713 TREE_LANG_FLAG_6 (type
) = 0;
4715 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4717 /* Remove the const and volatile qualifiers from arguments. The
4718 C++ front end removes them, but the C front end does not,
4719 leading to false ODR violation errors when merging two
4720 instances of the same function signature compiled by
4721 different front ends. */
4724 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
4726 tree arg_type
= TREE_VALUE (p
);
4728 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
4730 int quals
= TYPE_QUALS (arg_type
)
4732 & ~TYPE_QUAL_VOLATILE
;
4733 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
4734 free_lang_data_in_type (TREE_VALUE (p
));
4739 /* Remove members that are not actually FIELD_DECLs from the field
4740 list of an aggregate. These occur in C++. */
4741 if (RECORD_OR_UNION_TYPE_P (type
))
4745 /* Note that TYPE_FIELDS can be shared across distinct
4746 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4747 to be removed, we cannot set its TREE_CHAIN to NULL.
4748 Otherwise, we would not be able to find all the other fields
4749 in the other instances of this TREE_TYPE.
4751 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4753 member
= TYPE_FIELDS (type
);
4756 if (TREE_CODE (member
) == FIELD_DECL
4757 || TREE_CODE (member
) == TYPE_DECL
)
4760 TREE_CHAIN (prev
) = member
;
4762 TYPE_FIELDS (type
) = member
;
4766 member
= TREE_CHAIN (member
);
4770 TREE_CHAIN (prev
) = NULL_TREE
;
4772 TYPE_FIELDS (type
) = NULL_TREE
;
4774 TYPE_METHODS (type
) = NULL_TREE
;
4775 if (TYPE_BINFO (type
))
4776 free_lang_data_in_binfo (TYPE_BINFO (type
));
4780 /* For non-aggregate types, clear out the language slot (which
4781 overloads TYPE_BINFO). */
4782 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
4784 if (INTEGRAL_TYPE_P (type
)
4785 || SCALAR_FLOAT_TYPE_P (type
)
4786 || FIXED_POINT_TYPE_P (type
))
4788 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
4789 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
4793 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
4794 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
4796 if (TYPE_CONTEXT (type
)
4797 && TREE_CODE (TYPE_CONTEXT (type
)) == BLOCK
)
4799 tree ctx
= TYPE_CONTEXT (type
);
4802 ctx
= BLOCK_SUPERCONTEXT (ctx
);
4804 while (ctx
&& TREE_CODE (ctx
) == BLOCK
);
4805 TYPE_CONTEXT (type
) = ctx
;
4810 /* Return true if DECL may need an assembler name to be set. */
4813 need_assembler_name_p (tree decl
)
4815 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4816 if (TREE_CODE (decl
) != FUNCTION_DECL
4817 && TREE_CODE (decl
) != VAR_DECL
)
4820 /* If DECL already has its assembler name set, it does not need a
4822 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
4823 || DECL_ASSEMBLER_NAME_SET_P (decl
))
4826 /* Abstract decls do not need an assembler name. */
4827 if (DECL_ABSTRACT (decl
))
4830 /* For VAR_DECLs, only static, public and external symbols need an
4832 if (TREE_CODE (decl
) == VAR_DECL
4833 && !TREE_STATIC (decl
)
4834 && !TREE_PUBLIC (decl
)
4835 && !DECL_EXTERNAL (decl
))
4838 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4840 /* Do not set assembler name on builtins. Allow RTL expansion to
4841 decide whether to expand inline or via a regular call. */
4842 if (DECL_BUILT_IN (decl
)
4843 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
4846 /* Functions represented in the callgraph need an assembler name. */
4847 if (cgraph_get_node (decl
) != NULL
)
4850 /* Unused and not public functions don't need an assembler name. */
4851 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
4859 /* Reset all language specific information still present in symbol
4863 free_lang_data_in_decl (tree decl
)
4865 gcc_assert (DECL_P (decl
));
4867 /* Give the FE a chance to remove its own data first. */
4868 lang_hooks
.free_lang_data (decl
);
4870 TREE_LANG_FLAG_0 (decl
) = 0;
4871 TREE_LANG_FLAG_1 (decl
) = 0;
4872 TREE_LANG_FLAG_2 (decl
) = 0;
4873 TREE_LANG_FLAG_3 (decl
) = 0;
4874 TREE_LANG_FLAG_4 (decl
) = 0;
4875 TREE_LANG_FLAG_5 (decl
) = 0;
4876 TREE_LANG_FLAG_6 (decl
) = 0;
4878 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
4879 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
4880 if (TREE_CODE (decl
) == FIELD_DECL
)
4882 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
4883 if (TREE_CODE (DECL_CONTEXT (decl
)) == QUAL_UNION_TYPE
)
4884 DECL_QUALIFIER (decl
) = NULL_TREE
;
4887 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4889 struct cgraph_node
*node
;
4890 if (!(node
= cgraph_get_node (decl
))
4891 || (!node
->symbol
.definition
&& !node
->clones
))
4894 cgraph_release_function_body (node
);
4897 release_function_body (decl
);
4898 DECL_ARGUMENTS (decl
) = NULL
;
4899 DECL_RESULT (decl
) = NULL
;
4900 DECL_INITIAL (decl
) = error_mark_node
;
4903 if (gimple_has_body_p (decl
))
4907 /* If DECL has a gimple body, then the context for its
4908 arguments must be DECL. Otherwise, it doesn't really
4909 matter, as we will not be emitting any code for DECL. In
4910 general, there may be other instances of DECL created by
4911 the front end and since PARM_DECLs are generally shared,
4912 their DECL_CONTEXT changes as the replicas of DECL are
4913 created. The only time where DECL_CONTEXT is important
4914 is for the FUNCTION_DECLs that have a gimple body (since
4915 the PARM_DECL will be used in the function's body). */
4916 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
4917 DECL_CONTEXT (t
) = decl
;
4920 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
4921 At this point, it is not needed anymore. */
4922 DECL_SAVED_TREE (decl
) = NULL_TREE
;
4924 /* Clear the abstract origin if it refers to a method. Otherwise
4925 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
4926 origin will not be output correctly. */
4927 if (DECL_ABSTRACT_ORIGIN (decl
)
4928 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
4929 && RECORD_OR_UNION_TYPE_P
4930 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
4931 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
4933 /* Sometimes the C++ frontend doesn't manage to transform a temporary
4934 DECL_VINDEX referring to itself into a vtable slot number as it
4935 should. Happens with functions that are copied and then forgotten
4936 about. Just clear it, it won't matter anymore. */
4937 if (DECL_VINDEX (decl
) && !host_integerp (DECL_VINDEX (decl
), 0))
4938 DECL_VINDEX (decl
) = NULL_TREE
;
4940 else if (TREE_CODE (decl
) == VAR_DECL
)
4942 if ((DECL_EXTERNAL (decl
)
4943 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
4944 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
4945 DECL_INITIAL (decl
) = NULL_TREE
;
4947 else if (TREE_CODE (decl
) == TYPE_DECL
4948 || TREE_CODE (decl
) == FIELD_DECL
)
4949 DECL_INITIAL (decl
) = NULL_TREE
;
4950 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
4951 && DECL_INITIAL (decl
)
4952 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
4954 /* Strip builtins from the translation-unit BLOCK. We still have targets
4955 without builtin_decl_explicit support and also builtins are shared
4956 nodes and thus we can't use TREE_CHAIN in multiple lists. */
4957 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
4961 if (TREE_CODE (var
) == FUNCTION_DECL
4962 && DECL_BUILT_IN (var
))
4963 *nextp
= TREE_CHAIN (var
);
4965 nextp
= &TREE_CHAIN (var
);
4971 /* Data used when collecting DECLs and TYPEs for language data removal. */
4973 struct free_lang_data_d
4975 /* Worklist to avoid excessive recursion. */
4978 /* Set of traversed objects. Used to avoid duplicate visits. */
4979 struct pointer_set_t
*pset
;
4981 /* Array of symbols to process with free_lang_data_in_decl. */
4984 /* Array of types to process with free_lang_data_in_type. */
4989 /* Save all language fields needed to generate proper debug information
4990 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4993 save_debug_info_for_decl (tree t
)
4995 /*struct saved_debug_info_d *sdi;*/
4997 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
4999 /* FIXME. Partial implementation for saving debug info removed. */
5003 /* Save all language fields needed to generate proper debug information
5004 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5007 save_debug_info_for_type (tree t
)
5009 /*struct saved_debug_info_d *sdi;*/
5011 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
5013 /* FIXME. Partial implementation for saving debug info removed. */
5017 /* Add type or decl T to one of the list of tree nodes that need their
5018 language data removed. The lists are held inside FLD. */
5021 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
5025 fld
->decls
.safe_push (t
);
5026 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5027 save_debug_info_for_decl (t
);
5029 else if (TYPE_P (t
))
5031 fld
->types
.safe_push (t
);
5032 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5033 save_debug_info_for_type (t
);
5039 /* Push tree node T into FLD->WORKLIST. */
5042 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
5044 if (t
&& !is_lang_specific (t
) && !pointer_set_contains (fld
->pset
, t
))
5045 fld
->worklist
.safe_push ((t
));
5049 /* Operand callback helper for free_lang_data_in_node. *TP is the
5050 subtree operand being considered. */
5053 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
5056 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
5058 if (TREE_CODE (t
) == TREE_LIST
)
5061 /* Language specific nodes will be removed, so there is no need
5062 to gather anything under them. */
5063 if (is_lang_specific (t
))
5071 /* Note that walk_tree does not traverse every possible field in
5072 decls, so we have to do our own traversals here. */
5073 add_tree_to_fld_list (t
, fld
);
5075 fld_worklist_push (DECL_NAME (t
), fld
);
5076 fld_worklist_push (DECL_CONTEXT (t
), fld
);
5077 fld_worklist_push (DECL_SIZE (t
), fld
);
5078 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
5080 /* We are going to remove everything under DECL_INITIAL for
5081 TYPE_DECLs. No point walking them. */
5082 if (TREE_CODE (t
) != TYPE_DECL
)
5083 fld_worklist_push (DECL_INITIAL (t
), fld
);
5085 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
5086 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
5088 if (TREE_CODE (t
) == FUNCTION_DECL
)
5090 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
5091 fld_worklist_push (DECL_RESULT (t
), fld
);
5093 else if (TREE_CODE (t
) == TYPE_DECL
)
5095 fld_worklist_push (DECL_ARGUMENT_FLD (t
), fld
);
5096 fld_worklist_push (DECL_VINDEX (t
), fld
);
5097 fld_worklist_push (DECL_ORIGINAL_TYPE (t
), fld
);
5099 else if (TREE_CODE (t
) == FIELD_DECL
)
5101 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
5102 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
5103 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
5104 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
5106 else if (TREE_CODE (t
) == VAR_DECL
)
5108 fld_worklist_push (DECL_SECTION_NAME (t
), fld
);
5109 fld_worklist_push (DECL_COMDAT_GROUP (t
), fld
);
5112 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
5113 && DECL_HAS_VALUE_EXPR_P (t
))
5114 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
5116 if (TREE_CODE (t
) != FIELD_DECL
5117 && TREE_CODE (t
) != TYPE_DECL
)
5118 fld_worklist_push (TREE_CHAIN (t
), fld
);
5121 else if (TYPE_P (t
))
5123 /* Note that walk_tree does not traverse every possible field in
5124 types, so we have to do our own traversals here. */
5125 add_tree_to_fld_list (t
, fld
);
5127 if (!RECORD_OR_UNION_TYPE_P (t
))
5128 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
5129 fld_worklist_push (TYPE_SIZE (t
), fld
);
5130 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
5131 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
5132 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
5133 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
5134 fld_worklist_push (TYPE_NAME (t
), fld
);
5135 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5136 them and thus do not and want not to reach unused pointer types
5138 if (!POINTER_TYPE_P (t
))
5139 fld_worklist_push (TYPE_MINVAL (t
), fld
);
5140 if (!RECORD_OR_UNION_TYPE_P (t
))
5141 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
5142 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
5143 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5144 do not and want not to reach unused variants this way. */
5145 if (TYPE_CONTEXT (t
))
5147 tree ctx
= TYPE_CONTEXT (t
);
5148 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5149 So push that instead. */
5150 while (ctx
&& TREE_CODE (ctx
) == BLOCK
)
5151 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5152 fld_worklist_push (ctx
, fld
);
5154 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5155 and want not to reach unused types this way. */
5157 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
5161 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t
)), i
, tem
)
5162 fld_worklist_push (TREE_TYPE (tem
), fld
);
5163 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
5165 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5166 && TREE_CODE (tem
) == TREE_LIST
)
5169 fld_worklist_push (TREE_VALUE (tem
), fld
);
5170 tem
= TREE_CHAIN (tem
);
5174 if (RECORD_OR_UNION_TYPE_P (t
))
5177 /* Push all TYPE_FIELDS - there can be interleaving interesting
5178 and non-interesting things. */
5179 tem
= TYPE_FIELDS (t
);
5182 if (TREE_CODE (tem
) == FIELD_DECL
5183 || TREE_CODE (tem
) == TYPE_DECL
)
5184 fld_worklist_push (tem
, fld
);
5185 tem
= TREE_CHAIN (tem
);
5189 fld_worklist_push (TYPE_STUB_DECL (t
), fld
);
5192 else if (TREE_CODE (t
) == BLOCK
)
5195 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
5196 fld_worklist_push (tem
, fld
);
5197 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
5198 fld_worklist_push (tem
, fld
);
5199 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
5202 if (TREE_CODE (t
) != IDENTIFIER_NODE
5203 && CODE_CONTAINS_STRUCT (TREE_CODE (t
), TS_TYPED
))
5204 fld_worklist_push (TREE_TYPE (t
), fld
);
5210 /* Find decls and types in T. */
5213 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
5217 if (!pointer_set_contains (fld
->pset
, t
))
5218 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
5219 if (fld
->worklist
.is_empty ())
5221 t
= fld
->worklist
.pop ();
5225 /* Translate all the types in LIST with the corresponding runtime
5229 get_eh_types_for_runtime (tree list
)
5233 if (list
== NULL_TREE
)
5236 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5238 list
= TREE_CHAIN (list
);
5241 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5242 TREE_CHAIN (prev
) = n
;
5243 prev
= TREE_CHAIN (prev
);
5244 list
= TREE_CHAIN (list
);
5251 /* Find decls and types referenced in EH region R and store them in
5252 FLD->DECLS and FLD->TYPES. */
5255 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
5266 /* The types referenced in each catch must first be changed to the
5267 EH types used at runtime. This removes references to FE types
5269 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
5271 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
5272 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
5277 case ERT_ALLOWED_EXCEPTIONS
:
5278 r
->u
.allowed
.type_list
5279 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
5280 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
5283 case ERT_MUST_NOT_THROW
:
5284 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
5285 find_decls_types_r
, fld
, fld
->pset
);
5291 /* Find decls and types referenced in cgraph node N and store them in
5292 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5293 look for *every* kind of DECL and TYPE node reachable from N,
5294 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5295 NAMESPACE_DECLs, etc). */
5298 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5301 struct function
*fn
;
5305 find_decls_types (n
->symbol
.decl
, fld
);
5307 if (!gimple_has_body_p (n
->symbol
.decl
))
5310 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5312 fn
= DECL_STRUCT_FUNCTION (n
->symbol
.decl
);
5314 /* Traverse locals. */
5315 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5316 find_decls_types (t
, fld
);
5318 /* Traverse EH regions in FN. */
5321 FOR_ALL_EH_REGION_FN (r
, fn
)
5322 find_decls_types_in_eh_region (r
, fld
);
5325 /* Traverse every statement in FN. */
5326 FOR_EACH_BB_FN (bb
, fn
)
5328 gimple_stmt_iterator si
;
5331 for (si
= gsi_start_phis (bb
); !gsi_end_p (si
); gsi_next (&si
))
5333 gimple phi
= gsi_stmt (si
);
5335 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5337 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5338 find_decls_types (*arg_p
, fld
);
5342 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5344 gimple stmt
= gsi_stmt (si
);
5346 if (is_gimple_call (stmt
))
5347 find_decls_types (gimple_call_fntype (stmt
), fld
);
5349 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5351 tree arg
= gimple_op (stmt
, i
);
5352 find_decls_types (arg
, fld
);
5359 /* Find decls and types referenced in varpool node N and store them in
5360 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5361 look for *every* kind of DECL and TYPE node reachable from N,
5362 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5363 NAMESPACE_DECLs, etc). */
5366 find_decls_types_in_var (struct varpool_node
*v
, struct free_lang_data_d
*fld
)
5368 find_decls_types (v
->symbol
.decl
, fld
);
5371 /* If T needs an assembler name, have one created for it. */
5374 assign_assembler_name_if_neeeded (tree t
)
5376 if (need_assembler_name_p (t
))
5378 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5379 diagnostics that use input_location to show locus
5380 information. The problem here is that, at this point,
5381 input_location is generally anchored to the end of the file
5382 (since the parser is long gone), so we don't have a good
5383 position to pin it to.
5385 To alleviate this problem, this uses the location of T's
5386 declaration. Examples of this are
5387 testsuite/g++.dg/template/cond2.C and
5388 testsuite/g++.dg/template/pr35240.C. */
5389 location_t saved_location
= input_location
;
5390 input_location
= DECL_SOURCE_LOCATION (t
);
5392 decl_assembler_name (t
);
5394 input_location
= saved_location
;
5399 /* Free language specific information for every operand and expression
5400 in every node of the call graph. This process operates in three stages:
5402 1- Every callgraph node and varpool node is traversed looking for
5403 decls and types embedded in them. This is a more exhaustive
5404 search than that done by find_referenced_vars, because it will
5405 also collect individual fields, decls embedded in types, etc.
5407 2- All the decls found are sent to free_lang_data_in_decl.
5409 3- All the types found are sent to free_lang_data_in_type.
5411 The ordering between decls and types is important because
5412 free_lang_data_in_decl sets assembler names, which includes
5413 mangling. So types cannot be freed up until assembler names have
5417 free_lang_data_in_cgraph (void)
5419 struct cgraph_node
*n
;
5420 struct varpool_node
*v
;
5421 struct free_lang_data_d fld
;
5426 /* Initialize sets and arrays to store referenced decls and types. */
5427 fld
.pset
= pointer_set_create ();
5428 fld
.worklist
.create (0);
5429 fld
.decls
.create (100);
5430 fld
.types
.create (100);
5432 /* Find decls and types in the body of every function in the callgraph. */
5433 FOR_EACH_FUNCTION (n
)
5434 find_decls_types_in_node (n
, &fld
);
5436 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
5437 find_decls_types (p
->decl
, &fld
);
5439 /* Find decls and types in every varpool symbol. */
5440 FOR_EACH_VARIABLE (v
)
5441 find_decls_types_in_var (v
, &fld
);
5443 /* Set the assembler name on every decl found. We need to do this
5444 now because free_lang_data_in_decl will invalidate data needed
5445 for mangling. This breaks mangling on interdependent decls. */
5446 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5447 assign_assembler_name_if_neeeded (t
);
5449 /* Traverse every decl found freeing its language data. */
5450 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5451 free_lang_data_in_decl (t
);
5453 /* Traverse every type found freeing its language data. */
5454 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5455 free_lang_data_in_type (t
);
5457 pointer_set_destroy (fld
.pset
);
5458 fld
.worklist
.release ();
5459 fld
.decls
.release ();
5460 fld
.types
.release ();
5464 /* Free resources that are used by FE but are not needed once they are done. */
5467 free_lang_data (void)
5471 /* If we are the LTO frontend we have freed lang-specific data already. */
5473 || !flag_generate_lto
)
5476 /* Allocate and assign alias sets to the standard integer types
5477 while the slots are still in the way the frontends generated them. */
5478 for (i
= 0; i
< itk_none
; ++i
)
5479 if (integer_types
[i
])
5480 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5482 /* Traverse the IL resetting language specific information for
5483 operands, expressions, etc. */
5484 free_lang_data_in_cgraph ();
5486 /* Create gimple variants for common types. */
5487 ptrdiff_type_node
= integer_type_node
;
5488 fileptr_type_node
= ptr_type_node
;
5490 /* Reset some langhooks. Do not reset types_compatible_p, it may
5491 still be used indirectly via the get_alias_set langhook. */
5492 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5493 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5494 /* We do not want the default decl_assembler_name implementation,
5495 rather if we have fixed everything we want a wrapper around it
5496 asserting that all non-local symbols already got their assembler
5497 name and only produce assembler names for local symbols. Or rather
5498 make sure we never call decl_assembler_name on local symbols and
5499 devise a separate, middle-end private scheme for it. */
5501 /* Reset diagnostic machinery. */
5502 tree_diagnostics_defaults (global_dc
);
5510 const pass_data pass_data_ipa_free_lang_data
=
5512 SIMPLE_IPA_PASS
, /* type */
5513 "*free_lang_data", /* name */
5514 OPTGROUP_NONE
, /* optinfo_flags */
5515 false, /* has_gate */
5516 true, /* has_execute */
5517 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5518 0, /* properties_required */
5519 0, /* properties_provided */
5520 0, /* properties_destroyed */
5521 0, /* todo_flags_start */
5522 0, /* todo_flags_finish */
5525 class pass_ipa_free_lang_data
: public simple_ipa_opt_pass
5528 pass_ipa_free_lang_data(gcc::context
*ctxt
)
5529 : simple_ipa_opt_pass(pass_data_ipa_free_lang_data
, ctxt
)
5532 /* opt_pass methods: */
5533 unsigned int execute () { return free_lang_data (); }
5535 }; // class pass_ipa_free_lang_data
5539 simple_ipa_opt_pass
*
5540 make_pass_ipa_free_lang_data (gcc::context
*ctxt
)
5542 return new pass_ipa_free_lang_data (ctxt
);
5545 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
5546 ATTR_NAME. Also used internally by remove_attribute(). */
5548 private_is_attribute_p (const char *attr_name
, size_t attr_len
, const_tree ident
)
5550 size_t ident_len
= IDENTIFIER_LENGTH (ident
);
5552 if (ident_len
== attr_len
)
5554 if (strcmp (attr_name
, IDENTIFIER_POINTER (ident
)) == 0)
5557 else if (ident_len
== attr_len
+ 4)
5559 /* There is the possibility that ATTR is 'text' and IDENT is
5561 const char *p
= IDENTIFIER_POINTER (ident
);
5562 if (p
[0] == '_' && p
[1] == '_'
5563 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5564 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5571 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
5572 of ATTR_NAME, and LIST is not NULL_TREE. */
5574 private_lookup_attribute (const char *attr_name
, size_t attr_len
, tree list
)
5578 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5580 if (ident_len
== attr_len
)
5582 if (!strcmp (attr_name
,
5583 IDENTIFIER_POINTER (get_attribute_name (list
))))
5586 /* TODO: If we made sure that attributes were stored in the
5587 canonical form without '__...__' (ie, as in 'text' as opposed
5588 to '__text__') then we could avoid the following case. */
5589 else if (ident_len
== attr_len
+ 4)
5591 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5592 if (p
[0] == '_' && p
[1] == '_'
5593 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5594 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5597 list
= TREE_CHAIN (list
);
5603 /* A variant of lookup_attribute() that can be used with an identifier
5604 as the first argument, and where the identifier can be either
5605 'text' or '__text__'.
5607 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
5608 return a pointer to the attribute's list element if the attribute
5609 is part of the list, or NULL_TREE if not found. If the attribute
5610 appears more than once, this only returns the first occurrence; the
5611 TREE_CHAIN of the return value should be passed back in if further
5612 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
5613 can be in the form 'text' or '__text__'. */
5615 lookup_ident_attribute (tree attr_identifier
, tree list
)
5617 gcc_checking_assert (TREE_CODE (attr_identifier
) == IDENTIFIER_NODE
);
5621 gcc_checking_assert (TREE_CODE (get_attribute_name (list
))
5622 == IDENTIFIER_NODE
);
5624 /* Identifiers can be compared directly for equality. */
5625 if (attr_identifier
== get_attribute_name (list
))
5628 /* If they are not equal, they may still be one in the form
5629 'text' while the other one is in the form '__text__'. TODO:
5630 If we were storing attributes in normalized 'text' form, then
5631 this could all go away and we could take full advantage of
5632 the fact that we're comparing identifiers. :-) */
5634 size_t attr_len
= IDENTIFIER_LENGTH (attr_identifier
);
5635 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5637 if (ident_len
== attr_len
+ 4)
5639 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5640 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5641 if (p
[0] == '_' && p
[1] == '_'
5642 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5643 && strncmp (q
, p
+ 2, attr_len
) == 0)
5646 else if (ident_len
+ 4 == attr_len
)
5648 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5649 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5650 if (q
[0] == '_' && q
[1] == '_'
5651 && q
[attr_len
- 2] == '_' && q
[attr_len
- 1] == '_'
5652 && strncmp (q
+ 2, p
, ident_len
) == 0)
5656 list
= TREE_CHAIN (list
);
5662 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5666 remove_attribute (const char *attr_name
, tree list
)
5669 size_t attr_len
= strlen (attr_name
);
5671 gcc_checking_assert (attr_name
[0] != '_');
5673 for (p
= &list
; *p
; )
5676 /* TODO: If we were storing attributes in normalized form, here
5677 we could use a simple strcmp(). */
5678 if (private_is_attribute_p (attr_name
, attr_len
, get_attribute_name (l
)))
5679 *p
= TREE_CHAIN (l
);
5681 p
= &TREE_CHAIN (l
);
5687 /* Return an attribute list that is the union of a1 and a2. */
5690 merge_attributes (tree a1
, tree a2
)
5694 /* Either one unset? Take the set one. */
5696 if ((attributes
= a1
) == 0)
5699 /* One that completely contains the other? Take it. */
5701 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
5703 if (attribute_list_contained (a2
, a1
))
5707 /* Pick the longest list, and hang on the other list. */
5709 if (list_length (a1
) < list_length (a2
))
5710 attributes
= a2
, a2
= a1
;
5712 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
5715 for (a
= lookup_ident_attribute (get_attribute_name (a2
),
5717 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
5718 a
= lookup_ident_attribute (get_attribute_name (a2
),
5723 a1
= copy_node (a2
);
5724 TREE_CHAIN (a1
) = attributes
;
5733 /* Given types T1 and T2, merge their attributes and return
5737 merge_type_attributes (tree t1
, tree t2
)
5739 return merge_attributes (TYPE_ATTRIBUTES (t1
),
5740 TYPE_ATTRIBUTES (t2
));
5743 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5747 merge_decl_attributes (tree olddecl
, tree newdecl
)
5749 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
5750 DECL_ATTRIBUTES (newdecl
));
5753 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5755 /* Specialization of merge_decl_attributes for various Windows targets.
5757 This handles the following situation:
5759 __declspec (dllimport) int foo;
5762 The second instance of `foo' nullifies the dllimport. */
5765 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
5768 int delete_dllimport_p
= 1;
5770 /* What we need to do here is remove from `old' dllimport if it doesn't
5771 appear in `new'. dllimport behaves like extern: if a declaration is
5772 marked dllimport and a definition appears later, then the object
5773 is not dllimport'd. We also remove a `new' dllimport if the old list
5774 contains dllexport: dllexport always overrides dllimport, regardless
5775 of the order of declaration. */
5776 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
5777 delete_dllimport_p
= 0;
5778 else if (DECL_DLLIMPORT_P (new_tree
)
5779 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
5781 DECL_DLLIMPORT_P (new_tree
) = 0;
5782 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
5783 "dllimport ignored", new_tree
);
5785 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
5787 /* Warn about overriding a symbol that has already been used, e.g.:
5788 extern int __attribute__ ((dllimport)) foo;
5789 int* bar () {return &foo;}
5792 if (TREE_USED (old
))
5794 warning (0, "%q+D redeclared without dllimport attribute "
5795 "after being referenced with dll linkage", new_tree
);
5796 /* If we have used a variable's address with dllimport linkage,
5797 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5798 decl may already have had TREE_CONSTANT computed.
5799 We still remove the attribute so that assembler code refers
5800 to '&foo rather than '_imp__foo'. */
5801 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
5802 DECL_DLLIMPORT_P (new_tree
) = 1;
5805 /* Let an inline definition silently override the external reference,
5806 but otherwise warn about attribute inconsistency. */
5807 else if (TREE_CODE (new_tree
) == VAR_DECL
5808 || !DECL_DECLARED_INLINE_P (new_tree
))
5809 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
5810 "previous dllimport ignored", new_tree
);
5813 delete_dllimport_p
= 0;
5815 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
5817 if (delete_dllimport_p
)
5818 a
= remove_attribute ("dllimport", a
);
5823 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5824 struct attribute_spec.handler. */
5827 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
5833 /* These attributes may apply to structure and union types being created,
5834 but otherwise should pass to the declaration involved. */
5837 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
5838 | (int) ATTR_FLAG_ARRAY_NEXT
))
5840 *no_add_attrs
= true;
5841 return tree_cons (name
, args
, NULL_TREE
);
5843 if (TREE_CODE (node
) == RECORD_TYPE
5844 || TREE_CODE (node
) == UNION_TYPE
)
5846 node
= TYPE_NAME (node
);
5852 warning (OPT_Wattributes
, "%qE attribute ignored",
5854 *no_add_attrs
= true;
5859 if (TREE_CODE (node
) != FUNCTION_DECL
5860 && TREE_CODE (node
) != VAR_DECL
5861 && TREE_CODE (node
) != TYPE_DECL
)
5863 *no_add_attrs
= true;
5864 warning (OPT_Wattributes
, "%qE attribute ignored",
5869 if (TREE_CODE (node
) == TYPE_DECL
5870 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
5871 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
5873 *no_add_attrs
= true;
5874 warning (OPT_Wattributes
, "%qE attribute ignored",
5879 is_dllimport
= is_attribute_p ("dllimport", name
);
5881 /* Report error on dllimport ambiguities seen now before they cause
5885 /* Honor any target-specific overrides. */
5886 if (!targetm
.valid_dllimport_attribute_p (node
))
5887 *no_add_attrs
= true;
5889 else if (TREE_CODE (node
) == FUNCTION_DECL
5890 && DECL_DECLARED_INLINE_P (node
))
5892 warning (OPT_Wattributes
, "inline function %q+D declared as "
5893 " dllimport: attribute ignored", node
);
5894 *no_add_attrs
= true;
5896 /* Like MS, treat definition of dllimported variables and
5897 non-inlined functions on declaration as syntax errors. */
5898 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
5900 error ("function %q+D definition is marked dllimport", node
);
5901 *no_add_attrs
= true;
5904 else if (TREE_CODE (node
) == VAR_DECL
)
5906 if (DECL_INITIAL (node
))
5908 error ("variable %q+D definition is marked dllimport",
5910 *no_add_attrs
= true;
5913 /* `extern' needn't be specified with dllimport.
5914 Specify `extern' now and hope for the best. Sigh. */
5915 DECL_EXTERNAL (node
) = 1;
5916 /* Also, implicitly give dllimport'd variables declared within
5917 a function global scope, unless declared static. */
5918 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
5919 TREE_PUBLIC (node
) = 1;
5922 if (*no_add_attrs
== false)
5923 DECL_DLLIMPORT_P (node
) = 1;
5925 else if (TREE_CODE (node
) == FUNCTION_DECL
5926 && DECL_DECLARED_INLINE_P (node
)
5927 && flag_keep_inline_dllexport
)
5928 /* An exported function, even if inline, must be emitted. */
5929 DECL_EXTERNAL (node
) = 0;
5931 /* Report error if symbol is not accessible at global scope. */
5932 if (!TREE_PUBLIC (node
)
5933 && (TREE_CODE (node
) == VAR_DECL
5934 || TREE_CODE (node
) == FUNCTION_DECL
))
5936 error ("external linkage required for symbol %q+D because of "
5937 "%qE attribute", node
, name
);
5938 *no_add_attrs
= true;
5941 /* A dllexport'd entity must have default visibility so that other
5942 program units (shared libraries or the main executable) can see
5943 it. A dllimport'd entity must have default visibility so that
5944 the linker knows that undefined references within this program
5945 unit can be resolved by the dynamic linker. */
5948 if (DECL_VISIBILITY_SPECIFIED (node
)
5949 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
5950 error ("%qE implies default visibility, but %qD has already "
5951 "been declared with a different visibility",
5953 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
5954 DECL_VISIBILITY_SPECIFIED (node
) = 1;
5960 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
5962 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5963 of the various TYPE_QUAL values. */
5966 set_type_quals (tree type
, int type_quals
)
5968 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
5969 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
5970 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
5971 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
5974 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5977 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
5979 return (TYPE_QUALS (cand
) == type_quals
5980 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5981 /* Apparently this is needed for Objective-C. */
5982 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5983 /* Check alignment. */
5984 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
5985 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5986 TYPE_ATTRIBUTES (base
)));
5989 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5992 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
5994 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
5995 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5996 /* Apparently this is needed for Objective-C. */
5997 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5998 /* Check alignment. */
5999 && TYPE_ALIGN (cand
) == align
6000 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6001 TYPE_ATTRIBUTES (base
)));
6004 /* Return a version of the TYPE, qualified as indicated by the
6005 TYPE_QUALS, if one exists. If no qualified version exists yet,
6006 return NULL_TREE. */
6009 get_qualified_type (tree type
, int type_quals
)
6013 if (TYPE_QUALS (type
) == type_quals
)
6016 /* Search the chain of variants to see if there is already one there just
6017 like the one we need to have. If so, use that existing one. We must
6018 preserve the TYPE_NAME, since there is code that depends on this. */
6019 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6020 if (check_qualified_type (t
, type
, type_quals
))
6026 /* Like get_qualified_type, but creates the type if it does not
6027 exist. This function never returns NULL_TREE. */
6030 build_qualified_type (tree type
, int type_quals
)
6034 /* See if we already have the appropriate qualified variant. */
6035 t
= get_qualified_type (type
, type_quals
);
6037 /* If not, build it. */
6040 t
= build_variant_type_copy (type
);
6041 set_type_quals (t
, type_quals
);
6043 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6044 /* Propagate structural equality. */
6045 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6046 else if (TYPE_CANONICAL (type
) != type
)
6047 /* Build the underlying canonical type, since it is different
6049 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
6052 /* T is its own canonical type. */
6053 TYPE_CANONICAL (t
) = t
;
6060 /* Create a variant of type T with alignment ALIGN. */
6063 build_aligned_type (tree type
, unsigned int align
)
6067 if (TYPE_PACKED (type
)
6068 || TYPE_ALIGN (type
) == align
)
6071 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6072 if (check_aligned_type (t
, type
, align
))
6075 t
= build_variant_type_copy (type
);
6076 TYPE_ALIGN (t
) = align
;
6081 /* Create a new distinct copy of TYPE. The new type is made its own
6082 MAIN_VARIANT. If TYPE requires structural equality checks, the
6083 resulting type requires structural equality checks; otherwise, its
6084 TYPE_CANONICAL points to itself. */
6087 build_distinct_type_copy (tree type
)
6089 tree t
= copy_node (type
);
6091 TYPE_POINTER_TO (t
) = 0;
6092 TYPE_REFERENCE_TO (t
) = 0;
6094 /* Set the canonical type either to a new equivalence class, or
6095 propagate the need for structural equality checks. */
6096 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6097 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6099 TYPE_CANONICAL (t
) = t
;
6101 /* Make it its own variant. */
6102 TYPE_MAIN_VARIANT (t
) = t
;
6103 TYPE_NEXT_VARIANT (t
) = 0;
6105 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6106 whose TREE_TYPE is not t. This can also happen in the Ada
6107 frontend when using subtypes. */
6112 /* Create a new variant of TYPE, equivalent but distinct. This is so
6113 the caller can modify it. TYPE_CANONICAL for the return type will
6114 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6115 are considered equal by the language itself (or that both types
6116 require structural equality checks). */
6119 build_variant_type_copy (tree type
)
6121 tree t
, m
= TYPE_MAIN_VARIANT (type
);
6123 t
= build_distinct_type_copy (type
);
6125 /* Since we're building a variant, assume that it is a non-semantic
6126 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6127 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
6129 /* Add the new type to the chain of variants of TYPE. */
6130 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
6131 TYPE_NEXT_VARIANT (m
) = t
;
6132 TYPE_MAIN_VARIANT (t
) = m
;
6137 /* Return true if the from tree in both tree maps are equal. */
6140 tree_map_base_eq (const void *va
, const void *vb
)
6142 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
6143 *const b
= (const struct tree_map_base
*) vb
;
6144 return (a
->from
== b
->from
);
6147 /* Hash a from tree in a tree_base_map. */
6150 tree_map_base_hash (const void *item
)
6152 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
6155 /* Return true if this tree map structure is marked for garbage collection
6156 purposes. We simply return true if the from tree is marked, so that this
6157 structure goes away when the from tree goes away. */
6160 tree_map_base_marked_p (const void *p
)
6162 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
6165 /* Hash a from tree in a tree_map. */
6168 tree_map_hash (const void *item
)
6170 return (((const struct tree_map
*) item
)->hash
);
6173 /* Hash a from tree in a tree_decl_map. */
6176 tree_decl_map_hash (const void *item
)
6178 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
6181 /* Return the initialization priority for DECL. */
6184 decl_init_priority_lookup (tree decl
)
6186 struct tree_priority_map
*h
;
6187 struct tree_map_base in
;
6189 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6191 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6192 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
6195 /* Return the finalization priority for DECL. */
6198 decl_fini_priority_lookup (tree decl
)
6200 struct tree_priority_map
*h
;
6201 struct tree_map_base in
;
6203 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6205 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6206 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
6209 /* Return the initialization and finalization priority information for
6210 DECL. If there is no previous priority information, a freshly
6211 allocated structure is returned. */
6213 static struct tree_priority_map
*
6214 decl_priority_info (tree decl
)
6216 struct tree_priority_map in
;
6217 struct tree_priority_map
*h
;
6220 in
.base
.from
= decl
;
6221 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
6222 h
= (struct tree_priority_map
*) *loc
;
6225 h
= ggc_alloc_cleared_tree_priority_map ();
6227 h
->base
.from
= decl
;
6228 h
->init
= DEFAULT_INIT_PRIORITY
;
6229 h
->fini
= DEFAULT_INIT_PRIORITY
;
6235 /* Set the initialization priority for DECL to PRIORITY. */
6238 decl_init_priority_insert (tree decl
, priority_type priority
)
6240 struct tree_priority_map
*h
;
6242 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6243 if (priority
== DEFAULT_INIT_PRIORITY
)
6245 h
= decl_priority_info (decl
);
6249 /* Set the finalization priority for DECL to PRIORITY. */
6252 decl_fini_priority_insert (tree decl
, priority_type priority
)
6254 struct tree_priority_map
*h
;
6256 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6257 if (priority
== DEFAULT_INIT_PRIORITY
)
6259 h
= decl_priority_info (decl
);
6263 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6266 print_debug_expr_statistics (void)
6268 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6269 (long) htab_size (debug_expr_for_decl
),
6270 (long) htab_elements (debug_expr_for_decl
),
6271 htab_collisions (debug_expr_for_decl
));
6274 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6277 print_value_expr_statistics (void)
6279 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6280 (long) htab_size (value_expr_for_decl
),
6281 (long) htab_elements (value_expr_for_decl
),
6282 htab_collisions (value_expr_for_decl
));
6285 /* Lookup a debug expression for FROM, and return it if we find one. */
6288 decl_debug_expr_lookup (tree from
)
6290 struct tree_decl_map
*h
, in
;
6291 in
.base
.from
= from
;
6293 h
= (struct tree_decl_map
*)
6294 htab_find_with_hash (debug_expr_for_decl
, &in
, DECL_UID (from
));
6300 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6303 decl_debug_expr_insert (tree from
, tree to
)
6305 struct tree_decl_map
*h
;
6308 h
= ggc_alloc_tree_decl_map ();
6309 h
->base
.from
= from
;
6311 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, DECL_UID (from
),
6313 *(struct tree_decl_map
**) loc
= h
;
6316 /* Lookup a value expression for FROM, and return it if we find one. */
6319 decl_value_expr_lookup (tree from
)
6321 struct tree_decl_map
*h
, in
;
6322 in
.base
.from
= from
;
6324 h
= (struct tree_decl_map
*)
6325 htab_find_with_hash (value_expr_for_decl
, &in
, DECL_UID (from
));
6331 /* Insert a mapping FROM->TO in the value expression hashtable. */
6334 decl_value_expr_insert (tree from
, tree to
)
6336 struct tree_decl_map
*h
;
6339 h
= ggc_alloc_tree_decl_map ();
6340 h
->base
.from
= from
;
6342 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, DECL_UID (from
),
6344 *(struct tree_decl_map
**) loc
= h
;
6347 /* Lookup a vector of debug arguments for FROM, and return it if we
6351 decl_debug_args_lookup (tree from
)
6353 struct tree_vec_map
*h
, in
;
6355 if (!DECL_HAS_DEBUG_ARGS_P (from
))
6357 gcc_checking_assert (debug_args_for_decl
!= NULL
);
6358 in
.base
.from
= from
;
6359 h
= (struct tree_vec_map
*)
6360 htab_find_with_hash (debug_args_for_decl
, &in
, DECL_UID (from
));
6366 /* Insert a mapping FROM->empty vector of debug arguments in the value
6367 expression hashtable. */
6370 decl_debug_args_insert (tree from
)
6372 struct tree_vec_map
*h
;
6375 if (DECL_HAS_DEBUG_ARGS_P (from
))
6376 return decl_debug_args_lookup (from
);
6377 if (debug_args_for_decl
== NULL
)
6378 debug_args_for_decl
= htab_create_ggc (64, tree_vec_map_hash
,
6379 tree_vec_map_eq
, 0);
6380 h
= ggc_alloc_tree_vec_map ();
6381 h
->base
.from
= from
;
6383 loc
= htab_find_slot_with_hash (debug_args_for_decl
, h
, DECL_UID (from
),
6385 *(struct tree_vec_map
**) loc
= h
;
6386 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
6390 /* Hashing of types so that we don't make duplicates.
6391 The entry point is `type_hash_canon'. */
6393 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6394 with types in the TREE_VALUE slots), by adding the hash codes
6395 of the individual types. */
6398 type_hash_list (const_tree list
, hashval_t hashcode
)
6402 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6403 if (TREE_VALUE (tail
) != error_mark_node
)
6404 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
6410 /* These are the Hashtable callback functions. */
6412 /* Returns true iff the types are equivalent. */
6415 type_hash_eq (const void *va
, const void *vb
)
6417 const struct type_hash
*const a
= (const struct type_hash
*) va
,
6418 *const b
= (const struct type_hash
*) vb
;
6420 /* First test the things that are the same for all types. */
6421 if (a
->hash
!= b
->hash
6422 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6423 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6424 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6425 TYPE_ATTRIBUTES (b
->type
))
6426 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6427 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6430 /* Be careful about comparing arrays before and after the element type
6431 has been completed; don't compare TYPE_ALIGN unless both types are
6433 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6434 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6435 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6438 switch (TREE_CODE (a
->type
))
6443 case REFERENCE_TYPE
:
6448 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6451 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6452 && !(TYPE_VALUES (a
->type
)
6453 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6454 && TYPE_VALUES (b
->type
)
6455 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6456 && type_list_equal (TYPE_VALUES (a
->type
),
6457 TYPE_VALUES (b
->type
))))
6460 /* ... fall through ... */
6465 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6466 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6467 TYPE_MAX_VALUE (b
->type
)))
6468 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6469 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6470 TYPE_MIN_VALUE (b
->type
))));
6472 case FIXED_POINT_TYPE
:
6473 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6476 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6479 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6480 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6481 || (TYPE_ARG_TYPES (a
->type
)
6482 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6483 && TYPE_ARG_TYPES (b
->type
)
6484 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6485 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6486 TYPE_ARG_TYPES (b
->type
)))))
6490 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6494 case QUAL_UNION_TYPE
:
6495 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6496 || (TYPE_FIELDS (a
->type
)
6497 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6498 && TYPE_FIELDS (b
->type
)
6499 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6500 && type_list_equal (TYPE_FIELDS (a
->type
),
6501 TYPE_FIELDS (b
->type
))));
6504 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6505 || (TYPE_ARG_TYPES (a
->type
)
6506 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6507 && TYPE_ARG_TYPES (b
->type
)
6508 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6509 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6510 TYPE_ARG_TYPES (b
->type
))))
6518 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6519 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6524 /* Return the cached hash value. */
6527 type_hash_hash (const void *item
)
6529 return ((const struct type_hash
*) item
)->hash
;
6532 /* Look in the type hash table for a type isomorphic to TYPE.
6533 If one is found, return it. Otherwise return 0. */
6536 type_hash_lookup (hashval_t hashcode
, tree type
)
6538 struct type_hash
*h
, in
;
6540 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6541 must call that routine before comparing TYPE_ALIGNs. */
6547 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
6554 /* Add an entry to the type-hash-table
6555 for a type TYPE whose hash code is HASHCODE. */
6558 type_hash_add (hashval_t hashcode
, tree type
)
6560 struct type_hash
*h
;
6563 h
= ggc_alloc_type_hash ();
6566 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
6570 /* Given TYPE, and HASHCODE its hash code, return the canonical
6571 object for an identical type if one already exists.
6572 Otherwise, return TYPE, and record it as the canonical object.
6574 To use this function, first create a type of the sort you want.
6575 Then compute its hash code from the fields of the type that
6576 make it different from other similar types.
6577 Then call this function and use the value. */
6580 type_hash_canon (unsigned int hashcode
, tree type
)
6584 /* The hash table only contains main variants, so ensure that's what we're
6586 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6588 /* See if the type is in the hash table already. If so, return it.
6589 Otherwise, add the type. */
6590 t1
= type_hash_lookup (hashcode
, type
);
6593 if (GATHER_STATISTICS
)
6595 tree_code_counts
[(int) TREE_CODE (type
)]--;
6596 tree_node_counts
[(int) t_kind
]--;
6597 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type_non_common
);
6603 type_hash_add (hashcode
, type
);
6608 /* See if the data pointed to by the type hash table is marked. We consider
6609 it marked if the type is marked or if a debug type number or symbol
6610 table entry has been made for the type. */
6613 type_hash_marked_p (const void *p
)
6615 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
6617 return ggc_marked_p (type
);
6621 print_type_hash_statistics (void)
6623 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6624 (long) htab_size (type_hash_table
),
6625 (long) htab_elements (type_hash_table
),
6626 htab_collisions (type_hash_table
));
6629 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6630 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6631 by adding the hash codes of the individual attributes. */
6634 attribute_hash_list (const_tree list
, hashval_t hashcode
)
6638 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6639 /* ??? Do we want to add in TREE_VALUE too? */
6640 hashcode
= iterative_hash_object
6641 (IDENTIFIER_HASH_VALUE (get_attribute_name (tail
)), hashcode
);
6645 /* Given two lists of attributes, return true if list l2 is
6646 equivalent to l1. */
6649 attribute_list_equal (const_tree l1
, const_tree l2
)
6654 return attribute_list_contained (l1
, l2
)
6655 && attribute_list_contained (l2
, l1
);
6658 /* Given two lists of attributes, return true if list L2 is
6659 completely contained within L1. */
6660 /* ??? This would be faster if attribute names were stored in a canonicalized
6661 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6662 must be used to show these elements are equivalent (which they are). */
6663 /* ??? It's not clear that attributes with arguments will always be handled
6667 attribute_list_contained (const_tree l1
, const_tree l2
)
6671 /* First check the obvious, maybe the lists are identical. */
6675 /* Maybe the lists are similar. */
6676 for (t1
= l1
, t2
= l2
;
6678 && get_attribute_name (t1
) == get_attribute_name (t2
)
6679 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
6680 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6683 /* Maybe the lists are equal. */
6684 if (t1
== 0 && t2
== 0)
6687 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
6690 /* This CONST_CAST is okay because lookup_attribute does not
6691 modify its argument and the return value is assigned to a
6693 for (attr
= lookup_ident_attribute (get_attribute_name (t2
), CONST_CAST_TREE(l1
));
6694 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
6695 attr
= lookup_ident_attribute (get_attribute_name (t2
), TREE_CHAIN (attr
)))
6698 if (attr
== NULL_TREE
)
6705 /* Given two lists of types
6706 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6707 return 1 if the lists contain the same types in the same order.
6708 Also, the TREE_PURPOSEs must match. */
6711 type_list_equal (const_tree l1
, const_tree l2
)
6715 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6716 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6717 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6718 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6719 && (TREE_TYPE (TREE_PURPOSE (t1
))
6720 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6726 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6727 given by TYPE. If the argument list accepts variable arguments,
6728 then this function counts only the ordinary arguments. */
6731 type_num_arguments (const_tree type
)
6736 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
6737 /* If the function does not take a variable number of arguments,
6738 the last element in the list will have type `void'. */
6739 if (VOID_TYPE_P (TREE_VALUE (t
)))
6747 /* Nonzero if integer constants T1 and T2
6748 represent the same constant value. */
6751 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6756 if (t1
== 0 || t2
== 0)
6759 if (TREE_CODE (t1
) == INTEGER_CST
6760 && TREE_CODE (t2
) == INTEGER_CST
6761 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6762 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
6768 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6769 The precise way of comparison depends on their data type. */
6772 tree_int_cst_lt (const_tree t1
, const_tree t2
)
6777 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
6779 int t1_sgn
= tree_int_cst_sgn (t1
);
6780 int t2_sgn
= tree_int_cst_sgn (t2
);
6782 if (t1_sgn
< t2_sgn
)
6784 else if (t1_sgn
> t2_sgn
)
6786 /* Otherwise, both are non-negative, so we compare them as
6787 unsigned just in case one of them would overflow a signed
6790 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
6791 return INT_CST_LT (t1
, t2
);
6793 return INT_CST_LT_UNSIGNED (t1
, t2
);
6796 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6799 tree_int_cst_compare (const_tree t1
, const_tree t2
)
6801 if (tree_int_cst_lt (t1
, t2
))
6803 else if (tree_int_cst_lt (t2
, t1
))
6809 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6810 the host. If POS is zero, the value can be represented in a single
6811 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6812 be represented in a single unsigned HOST_WIDE_INT. */
6815 host_integerp (const_tree t
, int pos
)
6820 return (TREE_CODE (t
) == INTEGER_CST
6821 && ((TREE_INT_CST_HIGH (t
) == 0
6822 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
6823 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
6824 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
6825 && !TYPE_UNSIGNED (TREE_TYPE (t
)))
6826 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
6829 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6830 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6831 be non-negative. We must be able to satisfy the above conditions. */
6834 tree_low_cst (const_tree t
, int pos
)
6836 gcc_assert (host_integerp (t
, pos
));
6837 return TREE_INT_CST_LOW (t
);
6840 /* Return the HOST_WIDE_INT least significant bits of T, a sizetype
6841 kind INTEGER_CST. This makes sure to properly sign-extend the
6845 size_low_cst (const_tree t
)
6847 double_int d
= tree_to_double_int (t
);
6848 return d
.sext (TYPE_PRECISION (TREE_TYPE (t
))).low
;
6851 /* Return the most significant (sign) bit of T. */
6854 tree_int_cst_sign_bit (const_tree t
)
6856 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
6857 unsigned HOST_WIDE_INT w
;
6859 if (bitno
< HOST_BITS_PER_WIDE_INT
)
6860 w
= TREE_INT_CST_LOW (t
);
6863 w
= TREE_INT_CST_HIGH (t
);
6864 bitno
-= HOST_BITS_PER_WIDE_INT
;
6867 return (w
>> bitno
) & 1;
6870 /* Return an indication of the sign of the integer constant T.
6871 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6872 Note that -1 will never be returned if T's type is unsigned. */
6875 tree_int_cst_sgn (const_tree t
)
6877 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
6879 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6881 else if (TREE_INT_CST_HIGH (t
) < 0)
6887 /* Return the minimum number of bits needed to represent VALUE in a
6888 signed or unsigned type, UNSIGNEDP says which. */
6891 tree_int_cst_min_precision (tree value
, bool unsignedp
)
6893 /* If the value is negative, compute its negative minus 1. The latter
6894 adjustment is because the absolute value of the largest negative value
6895 is one larger than the largest positive value. This is equivalent to
6896 a bit-wise negation, so use that operation instead. */
6898 if (tree_int_cst_sgn (value
) < 0)
6899 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
6901 /* Return the number of bits needed, taking into account the fact
6902 that we need one more bit for a signed than unsigned type.
6903 If value is 0 or -1, the minimum precision is 1 no matter
6904 whether unsignedp is true or false. */
6906 if (integer_zerop (value
))
6909 return tree_floor_log2 (value
) + 1 + !unsignedp
;
6912 /* Compare two constructor-element-type constants. Return 1 if the lists
6913 are known to be equal; otherwise return 0. */
6916 simple_cst_list_equal (const_tree l1
, const_tree l2
)
6918 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
6920 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
6923 l1
= TREE_CHAIN (l1
);
6924 l2
= TREE_CHAIN (l2
);
6930 /* Return truthvalue of whether T1 is the same tree structure as T2.
6931 Return 1 if they are the same.
6932 Return 0 if they are understandably different.
6933 Return -1 if either contains tree structure not understood by
6937 simple_cst_equal (const_tree t1
, const_tree t2
)
6939 enum tree_code code1
, code2
;
6945 if (t1
== 0 || t2
== 0)
6948 code1
= TREE_CODE (t1
);
6949 code2
= TREE_CODE (t2
);
6951 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
6953 if (CONVERT_EXPR_CODE_P (code2
)
6954 || code2
== NON_LVALUE_EXPR
)
6955 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6957 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
6960 else if (CONVERT_EXPR_CODE_P (code2
)
6961 || code2
== NON_LVALUE_EXPR
)
6962 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
6970 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6971 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
6974 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
6977 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
6980 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
6981 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
6982 TREE_STRING_LENGTH (t1
)));
6986 unsigned HOST_WIDE_INT idx
;
6987 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
6988 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
6990 if (vec_safe_length (v1
) != vec_safe_length (v2
))
6993 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
6994 /* ??? Should we handle also fields here? */
6995 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
7001 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7004 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
7007 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
7010 const_tree arg1
, arg2
;
7011 const_call_expr_arg_iterator iter1
, iter2
;
7012 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
7013 arg2
= first_const_call_expr_arg (t2
, &iter2
);
7015 arg1
= next_const_call_expr_arg (&iter1
),
7016 arg2
= next_const_call_expr_arg (&iter2
))
7018 cmp
= simple_cst_equal (arg1
, arg2
);
7022 return arg1
== arg2
;
7026 /* Special case: if either target is an unallocated VAR_DECL,
7027 it means that it's going to be unified with whatever the
7028 TARGET_EXPR is really supposed to initialize, so treat it
7029 as being equivalent to anything. */
7030 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
7031 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
7032 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
7033 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
7034 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
7035 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
7038 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7043 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
7045 case WITH_CLEANUP_EXPR
:
7046 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7050 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
7053 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
7054 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7068 /* This general rule works for most tree codes. All exceptions should be
7069 handled above. If this is a language-specific tree code, we can't
7070 trust what might be in the operand, so say we don't know
7072 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
7075 switch (TREE_CODE_CLASS (code1
))
7079 case tcc_comparison
:
7080 case tcc_expression
:
7084 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
7086 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
7098 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7099 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7100 than U, respectively. */
7103 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
7105 if (tree_int_cst_sgn (t
) < 0)
7107 else if (TREE_INT_CST_HIGH (t
) != 0)
7109 else if (TREE_INT_CST_LOW (t
) == u
)
7111 else if (TREE_INT_CST_LOW (t
) < u
)
7117 /* Return true if SIZE represents a constant size that is in bounds of
7118 what the middle-end and the backend accepts (covering not more than
7119 half of the address-space). */
7122 valid_constant_size_p (const_tree size
)
7124 if (! host_integerp (size
, 1)
7125 || TREE_OVERFLOW (size
)
7126 || tree_int_cst_sign_bit (size
) != 0)
7131 /* Return the precision of the type, or for a complex or vector type the
7132 precision of the type of its elements. */
7135 element_precision (const_tree type
)
7137 enum tree_code code
= TREE_CODE (type
);
7138 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7139 type
= TREE_TYPE (type
);
7141 return TYPE_PRECISION (type
);
7144 /* Return true if CODE represents an associative tree code. Otherwise
7147 associative_tree_code (enum tree_code code
)
7166 /* Return true if CODE represents a commutative tree code. Otherwise
7169 commutative_tree_code (enum tree_code code
)
7175 case MULT_HIGHPART_EXPR
:
7183 case UNORDERED_EXPR
:
7187 case TRUTH_AND_EXPR
:
7188 case TRUTH_XOR_EXPR
:
7190 case WIDEN_MULT_EXPR
:
7191 case VEC_WIDEN_MULT_HI_EXPR
:
7192 case VEC_WIDEN_MULT_LO_EXPR
:
7193 case VEC_WIDEN_MULT_EVEN_EXPR
:
7194 case VEC_WIDEN_MULT_ODD_EXPR
:
7203 /* Return true if CODE represents a ternary tree code for which the
7204 first two operands are commutative. Otherwise return false. */
7206 commutative_ternary_tree_code (enum tree_code code
)
7210 case WIDEN_MULT_PLUS_EXPR
:
7211 case WIDEN_MULT_MINUS_EXPR
:
7220 /* Generate a hash value for an expression. This can be used iteratively
7221 by passing a previous result as the VAL argument.
7223 This function is intended to produce the same hash for expressions which
7224 would compare equal using operand_equal_p. */
7227 iterative_hash_expr (const_tree t
, hashval_t val
)
7230 enum tree_code code
;
7234 return iterative_hash_hashval_t (0, val
);
7236 code
= TREE_CODE (t
);
7240 /* Alas, constants aren't shared, so we can't rely on pointer
7243 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
7244 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
7247 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
7249 return iterative_hash_hashval_t (val2
, val
);
7253 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
7255 return iterative_hash_hashval_t (val2
, val
);
7258 return iterative_hash (TREE_STRING_POINTER (t
),
7259 TREE_STRING_LENGTH (t
), val
);
7261 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
7262 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
7266 for (i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
7267 val
= iterative_hash_expr (VECTOR_CST_ELT (t
, i
), val
);
7271 /* We can just compare by pointer. */
7272 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
7273 case PLACEHOLDER_EXPR
:
7274 /* The node itself doesn't matter. */
7277 /* A list of expressions, for a CALL_EXPR or as the elements of a
7279 for (; t
; t
= TREE_CHAIN (t
))
7280 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
7284 unsigned HOST_WIDE_INT idx
;
7286 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
7288 val
= iterative_hash_expr (field
, val
);
7289 val
= iterative_hash_expr (value
, val
);
7295 /* The type of the second operand is relevant, except for
7296 its top-level qualifiers. */
7297 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t
, 1)));
7299 val
= iterative_hash_object (TYPE_HASH (type
), val
);
7301 /* We could use the standard hash computation from this point
7303 val
= iterative_hash_object (code
, val
);
7304 val
= iterative_hash_expr (TREE_OPERAND (t
, 1), val
);
7305 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
7309 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7310 Otherwise nodes that compare equal according to operand_equal_p might
7311 get different hash codes. However, don't do this for machine specific
7312 or front end builtins, since the function code is overloaded in those
7314 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
7315 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t
)))
7317 t
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
7318 code
= TREE_CODE (t
);
7322 tclass
= TREE_CODE_CLASS (code
);
7324 if (tclass
== tcc_declaration
)
7326 /* DECL's have a unique ID */
7327 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
7331 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
7333 val
= iterative_hash_object (code
, val
);
7335 /* Don't hash the type, that can lead to having nodes which
7336 compare equal according to operand_equal_p, but which
7337 have different hash codes. */
7338 if (CONVERT_EXPR_CODE_P (code
)
7339 || code
== NON_LVALUE_EXPR
)
7341 /* Make sure to include signness in the hash computation. */
7342 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
7343 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
7346 else if (commutative_tree_code (code
))
7348 /* It's a commutative expression. We want to hash it the same
7349 however it appears. We do this by first hashing both operands
7350 and then rehashing based on the order of their independent
7352 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
7353 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
7357 t
= one
, one
= two
, two
= t
;
7359 val
= iterative_hash_hashval_t (one
, val
);
7360 val
= iterative_hash_hashval_t (two
, val
);
7363 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
7364 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
7370 /* Generate a hash value for a pair of expressions. This can be used
7371 iteratively by passing a previous result as the VAL argument.
7373 The same hash value is always returned for a given pair of expressions,
7374 regardless of the order in which they are presented. This is useful in
7375 hashing the operands of commutative functions. */
7378 iterative_hash_exprs_commutative (const_tree t1
,
7379 const_tree t2
, hashval_t val
)
7381 hashval_t one
= iterative_hash_expr (t1
, 0);
7382 hashval_t two
= iterative_hash_expr (t2
, 0);
7386 t
= one
, one
= two
, two
= t
;
7387 val
= iterative_hash_hashval_t (one
, val
);
7388 val
= iterative_hash_hashval_t (two
, val
);
7393 /* Constructors for pointer, array and function types.
7394 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7395 constructed by language-dependent code, not here.) */
7397 /* Construct, lay out and return the type of pointers to TO_TYPE with
7398 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7399 reference all of memory. If such a type has already been
7400 constructed, reuse it. */
7403 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
7408 if (to_type
== error_mark_node
)
7409 return error_mark_node
;
7411 /* If the pointed-to type has the may_alias attribute set, force
7412 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7413 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7414 can_alias_all
= true;
7416 /* In some cases, languages will have things that aren't a POINTER_TYPE
7417 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7418 In that case, return that type without regard to the rest of our
7421 ??? This is a kludge, but consistent with the way this function has
7422 always operated and there doesn't seem to be a good way to avoid this
7424 if (TYPE_POINTER_TO (to_type
) != 0
7425 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7426 return TYPE_POINTER_TO (to_type
);
7428 /* First, if we already have a type for pointers to TO_TYPE and it's
7429 the proper mode, use it. */
7430 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7431 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7434 t
= make_node (POINTER_TYPE
);
7436 TREE_TYPE (t
) = to_type
;
7437 SET_TYPE_MODE (t
, mode
);
7438 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7439 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7440 TYPE_POINTER_TO (to_type
) = t
;
7442 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7443 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7444 else if (TYPE_CANONICAL (to_type
) != to_type
)
7446 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7447 mode
, can_alias_all
);
7449 /* Lay out the type. This function has many callers that are concerned
7450 with expression-construction, and this simplifies them all. */
7456 /* By default build pointers in ptr_mode. */
7459 build_pointer_type (tree to_type
)
7461 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7462 : TYPE_ADDR_SPACE (to_type
);
7463 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7464 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7467 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7470 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
7475 if (to_type
== error_mark_node
)
7476 return error_mark_node
;
7478 /* If the pointed-to type has the may_alias attribute set, force
7479 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7480 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7481 can_alias_all
= true;
7483 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7484 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7485 In that case, return that type without regard to the rest of our
7488 ??? This is a kludge, but consistent with the way this function has
7489 always operated and there doesn't seem to be a good way to avoid this
7491 if (TYPE_REFERENCE_TO (to_type
) != 0
7492 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7493 return TYPE_REFERENCE_TO (to_type
);
7495 /* First, if we already have a type for pointers to TO_TYPE and it's
7496 the proper mode, use it. */
7497 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7498 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7501 t
= make_node (REFERENCE_TYPE
);
7503 TREE_TYPE (t
) = to_type
;
7504 SET_TYPE_MODE (t
, mode
);
7505 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7506 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7507 TYPE_REFERENCE_TO (to_type
) = t
;
7509 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7510 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7511 else if (TYPE_CANONICAL (to_type
) != to_type
)
7513 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7514 mode
, can_alias_all
);
7522 /* Build the node for the type of references-to-TO_TYPE by default
7526 build_reference_type (tree to_type
)
7528 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7529 : TYPE_ADDR_SPACE (to_type
);
7530 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7531 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7534 /* Build a type that is compatible with t but has no cv quals anywhere
7537 const char *const *const * -> char ***. */
7540 build_type_no_quals (tree t
)
7542 switch (TREE_CODE (t
))
7545 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7547 TYPE_REF_CAN_ALIAS_ALL (t
));
7548 case REFERENCE_TYPE
:
7550 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7552 TYPE_REF_CAN_ALIAS_ALL (t
));
7554 return TYPE_MAIN_VARIANT (t
);
7558 #define MAX_INT_CACHED_PREC \
7559 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7560 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7562 /* Builds a signed or unsigned integer type of precision PRECISION.
7563 Used for C bitfields whose precision does not match that of
7564 built-in target types. */
7566 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7572 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7574 if (precision
<= MAX_INT_CACHED_PREC
)
7576 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7581 itype
= make_node (INTEGER_TYPE
);
7582 TYPE_PRECISION (itype
) = precision
;
7585 fixup_unsigned_type (itype
);
7587 fixup_signed_type (itype
);
7590 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
7591 ret
= type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
7592 if (precision
<= MAX_INT_CACHED_PREC
)
7593 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7598 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7599 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7600 is true, reuse such a type that has already been constructed. */
7603 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7605 tree itype
= make_node (INTEGER_TYPE
);
7606 hashval_t hashcode
= 0;
7608 TREE_TYPE (itype
) = type
;
7610 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7611 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7613 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7614 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7615 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7616 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7617 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
7618 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7623 if ((TYPE_MIN_VALUE (itype
)
7624 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7625 || (TYPE_MAX_VALUE (itype
)
7626 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7628 /* Since we cannot reliably merge this type, we need to compare it using
7629 structural equality checks. */
7630 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7634 hashcode
= iterative_hash_expr (TYPE_MIN_VALUE (itype
), hashcode
);
7635 hashcode
= iterative_hash_expr (TYPE_MAX_VALUE (itype
), hashcode
);
7636 hashcode
= iterative_hash_hashval_t (TYPE_HASH (type
), hashcode
);
7637 itype
= type_hash_canon (hashcode
, itype
);
7642 /* Wrapper around build_range_type_1 with SHARED set to true. */
7645 build_range_type (tree type
, tree lowval
, tree highval
)
7647 return build_range_type_1 (type
, lowval
, highval
, true);
7650 /* Wrapper around build_range_type_1 with SHARED set to false. */
7653 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7655 return build_range_type_1 (type
, lowval
, highval
, false);
7658 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7659 MAXVAL should be the maximum value in the domain
7660 (one less than the length of the array).
7662 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7663 We don't enforce this limit, that is up to caller (e.g. language front end).
7664 The limit exists because the result is a signed type and we don't handle
7665 sizes that use more than one HOST_WIDE_INT. */
7668 build_index_type (tree maxval
)
7670 return build_range_type (sizetype
, size_zero_node
, maxval
);
7673 /* Return true if the debug information for TYPE, a subtype, should be emitted
7674 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7675 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7676 debug info and doesn't reflect the source code. */
7679 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7681 tree base_type
= TREE_TYPE (type
), low
, high
;
7683 /* Subrange types have a base type which is an integral type. */
7684 if (!INTEGRAL_TYPE_P (base_type
))
7687 /* Get the real bounds of the subtype. */
7688 if (lang_hooks
.types
.get_subrange_bounds
)
7689 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7692 low
= TYPE_MIN_VALUE (type
);
7693 high
= TYPE_MAX_VALUE (type
);
7696 /* If the type and its base type have the same representation and the same
7697 name, then the type is not a subrange but a copy of the base type. */
7698 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7699 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7700 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7701 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7702 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
7704 tree type_name
= TYPE_NAME (type
);
7705 tree base_type_name
= TYPE_NAME (base_type
);
7707 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
7708 type_name
= DECL_NAME (type_name
);
7710 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
7711 base_type_name
= DECL_NAME (base_type_name
);
7713 if (type_name
== base_type_name
)
7724 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7725 and number of elements specified by the range of values of INDEX_TYPE.
7726 If SHARED is true, reuse such a type that has already been constructed. */
7729 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
7733 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7735 error ("arrays of functions are not meaningful");
7736 elt_type
= integer_type_node
;
7739 t
= make_node (ARRAY_TYPE
);
7740 TREE_TYPE (t
) = elt_type
;
7741 TYPE_DOMAIN (t
) = index_type
;
7742 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7745 /* If the element type is incomplete at this point we get marked for
7746 structural equality. Do not record these types in the canonical
7748 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
7753 hashval_t hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), 0);
7755 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
7756 t
= type_hash_canon (hashcode
, t
);
7759 if (TYPE_CANONICAL (t
) == t
)
7761 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7762 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
7763 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7764 else if (TYPE_CANONICAL (elt_type
) != elt_type
7765 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7767 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7769 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7776 /* Wrapper around build_array_type_1 with SHARED set to true. */
7779 build_array_type (tree elt_type
, tree index_type
)
7781 return build_array_type_1 (elt_type
, index_type
, true);
7784 /* Wrapper around build_array_type_1 with SHARED set to false. */
7787 build_nonshared_array_type (tree elt_type
, tree index_type
)
7789 return build_array_type_1 (elt_type
, index_type
, false);
7792 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7796 build_array_type_nelts (tree elt_type
, unsigned HOST_WIDE_INT nelts
)
7798 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
7801 /* Recursively examines the array elements of TYPE, until a non-array
7802 element type is found. */
7805 strip_array_types (tree type
)
7807 while (TREE_CODE (type
) == ARRAY_TYPE
)
7808 type
= TREE_TYPE (type
);
7813 /* Computes the canonical argument types from the argument type list
7816 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7817 on entry to this function, or if any of the ARGTYPES are
7820 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7821 true on entry to this function, or if any of the ARGTYPES are
7824 Returns a canonical argument list, which may be ARGTYPES when the
7825 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7826 true) or would not differ from ARGTYPES. */
7829 maybe_canonicalize_argtypes(tree argtypes
,
7830 bool *any_structural_p
,
7831 bool *any_noncanonical_p
)
7834 bool any_noncanonical_argtypes_p
= false;
7836 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7838 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7839 /* Fail gracefully by stating that the type is structural. */
7840 *any_structural_p
= true;
7841 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7842 *any_structural_p
= true;
7843 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7844 || TREE_PURPOSE (arg
))
7845 /* If the argument has a default argument, we consider it
7846 non-canonical even though the type itself is canonical.
7847 That way, different variants of function and method types
7848 with default arguments will all point to the variant with
7849 no defaults as their canonical type. */
7850 any_noncanonical_argtypes_p
= true;
7853 if (*any_structural_p
)
7856 if (any_noncanonical_argtypes_p
)
7858 /* Build the canonical list of argument types. */
7859 tree canon_argtypes
= NULL_TREE
;
7860 bool is_void
= false;
7862 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7864 if (arg
== void_list_node
)
7867 canon_argtypes
= tree_cons (NULL_TREE
,
7868 TYPE_CANONICAL (TREE_VALUE (arg
)),
7872 canon_argtypes
= nreverse (canon_argtypes
);
7874 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7876 /* There is a non-canonical type. */
7877 *any_noncanonical_p
= true;
7878 return canon_argtypes
;
7881 /* The canonical argument types are the same as ARGTYPES. */
7885 /* Construct, lay out and return
7886 the type of functions returning type VALUE_TYPE
7887 given arguments of types ARG_TYPES.
7888 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7889 are data type nodes for the arguments of the function.
7890 If such a type has already been constructed, reuse it. */
7893 build_function_type (tree value_type
, tree arg_types
)
7896 hashval_t hashcode
= 0;
7897 bool any_structural_p
, any_noncanonical_p
;
7898 tree canon_argtypes
;
7900 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
7902 error ("function return type cannot be function");
7903 value_type
= integer_type_node
;
7906 /* Make a node of the sort we want. */
7907 t
= make_node (FUNCTION_TYPE
);
7908 TREE_TYPE (t
) = value_type
;
7909 TYPE_ARG_TYPES (t
) = arg_types
;
7911 /* If we already have such a type, use the old one. */
7912 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
7913 hashcode
= type_hash_list (arg_types
, hashcode
);
7914 t
= type_hash_canon (hashcode
, t
);
7916 /* Set up the canonical type. */
7917 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
7918 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
7919 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
7921 &any_noncanonical_p
);
7922 if (any_structural_p
)
7923 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7924 else if (any_noncanonical_p
)
7925 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
7928 if (!COMPLETE_TYPE_P (t
))
7933 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP and the
7934 return value if SKIP_RETURN is true. */
7937 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
,
7940 tree new_type
= NULL
;
7941 tree args
, new_args
= NULL
, t
;
7945 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
7946 args
= TREE_CHAIN (args
), i
++)
7947 if (!args_to_skip
|| !bitmap_bit_p (args_to_skip
, i
))
7948 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
7950 new_reversed
= nreverse (new_args
);
7954 TREE_CHAIN (new_args
) = void_list_node
;
7956 new_reversed
= void_list_node
;
7959 /* Use copy_node to preserve as much as possible from original type
7960 (debug info, attribute lists etc.)
7961 Exception is METHOD_TYPEs must have THIS argument.
7962 When we are asked to remove it, we need to build new FUNCTION_TYPE
7964 if (TREE_CODE (orig_type
) != METHOD_TYPE
7966 || !bitmap_bit_p (args_to_skip
, 0))
7968 new_type
= build_distinct_type_copy (orig_type
);
7969 TYPE_ARG_TYPES (new_type
) = new_reversed
;
7974 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
7976 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
7980 TREE_TYPE (new_type
) = void_type_node
;
7982 /* This is a new type, not a copy of an old type. Need to reassociate
7983 variants. We can handle everything except the main variant lazily. */
7984 t
= TYPE_MAIN_VARIANT (orig_type
);
7987 t
= build_function_type_skip_args (t
, args_to_skip
, skip_return
);
7988 TYPE_MAIN_VARIANT (new_type
) = t
;
7989 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
7990 TYPE_NEXT_VARIANT (t
) = new_type
;
7994 TYPE_MAIN_VARIANT (new_type
) = new_type
;
7995 TYPE_NEXT_VARIANT (new_type
) = NULL
;
8001 /* Build variant of function decl ORIG_DECL skipping ARGS_TO_SKIP and the
8002 return value if SKIP_RETURN is true.
8004 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
8005 linked by TREE_CHAIN directly. The caller is responsible for eliminating
8006 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
8009 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
,
8012 tree new_decl
= copy_node (orig_decl
);
8015 new_type
= TREE_TYPE (orig_decl
);
8016 if (prototype_p (new_type
)
8017 || (skip_return
&& !VOID_TYPE_P (TREE_TYPE (new_type
))))
8019 = build_function_type_skip_args (new_type
, args_to_skip
, skip_return
);
8020 TREE_TYPE (new_decl
) = new_type
;
8022 /* For declarations setting DECL_VINDEX (i.e. methods)
8023 we expect first argument to be THIS pointer. */
8024 if (args_to_skip
&& bitmap_bit_p (args_to_skip
, 0))
8025 DECL_VINDEX (new_decl
) = NULL_TREE
;
8027 /* When signature changes, we need to clear builtin info. */
8028 if (DECL_BUILT_IN (new_decl
)
8030 && !bitmap_empty_p (args_to_skip
))
8032 DECL_BUILT_IN_CLASS (new_decl
) = NOT_BUILT_IN
;
8033 DECL_FUNCTION_CODE (new_decl
) = (enum built_in_function
) 0;
8038 /* Build a function type. The RETURN_TYPE is the type returned by the
8039 function. If VAARGS is set, no void_type_node is appended to the
8040 the list. ARGP must be always be terminated be a NULL_TREE. */
8043 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
8047 t
= va_arg (argp
, tree
);
8048 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
8049 args
= tree_cons (NULL_TREE
, t
, args
);
8054 if (args
!= NULL_TREE
)
8055 args
= nreverse (args
);
8056 gcc_assert (last
!= void_list_node
);
8058 else if (args
== NULL_TREE
)
8059 args
= void_list_node
;
8063 args
= nreverse (args
);
8064 TREE_CHAIN (last
) = void_list_node
;
8066 args
= build_function_type (return_type
, args
);
8071 /* Build a function type. The RETURN_TYPE is the type returned by the
8072 function. If additional arguments are provided, they are
8073 additional argument types. The list of argument types must always
8074 be terminated by NULL_TREE. */
8077 build_function_type_list (tree return_type
, ...)
8082 va_start (p
, return_type
);
8083 args
= build_function_type_list_1 (false, return_type
, p
);
8088 /* Build a variable argument function type. The RETURN_TYPE is the
8089 type returned by the function. If additional arguments are provided,
8090 they are additional argument types. The list of argument types must
8091 always be terminated by NULL_TREE. */
8094 build_varargs_function_type_list (tree return_type
, ...)
8099 va_start (p
, return_type
);
8100 args
= build_function_type_list_1 (true, return_type
, p
);
8106 /* Build a function type. RETURN_TYPE is the type returned by the
8107 function; VAARGS indicates whether the function takes varargs. The
8108 function takes N named arguments, the types of which are provided in
8112 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
8116 tree t
= vaargs
? NULL_TREE
: void_list_node
;
8118 for (i
= n
- 1; i
>= 0; i
--)
8119 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
8121 return build_function_type (return_type
, t
);
8124 /* Build a function type. RETURN_TYPE is the type returned by the
8125 function. The function takes N named arguments, the types of which
8126 are provided in ARG_TYPES. */
8129 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8131 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
8134 /* Build a variable argument function type. RETURN_TYPE is the type
8135 returned by the function. The function takes N named arguments, the
8136 types of which are provided in ARG_TYPES. */
8139 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8141 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
8144 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8145 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8146 for the method. An implicit additional parameter (of type
8147 pointer-to-BASETYPE) is added to the ARGTYPES. */
8150 build_method_type_directly (tree basetype
,
8157 bool any_structural_p
, any_noncanonical_p
;
8158 tree canon_argtypes
;
8160 /* Make a node of the sort we want. */
8161 t
= make_node (METHOD_TYPE
);
8163 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8164 TREE_TYPE (t
) = rettype
;
8165 ptype
= build_pointer_type (basetype
);
8167 /* The actual arglist for this function includes a "hidden" argument
8168 which is "this". Put it into the list of argument types. */
8169 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
8170 TYPE_ARG_TYPES (t
) = argtypes
;
8172 /* If we already have such a type, use the old one. */
8173 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8174 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
8175 hashcode
= type_hash_list (argtypes
, hashcode
);
8176 t
= type_hash_canon (hashcode
, t
);
8178 /* Set up the canonical type. */
8180 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8181 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
8183 = (TYPE_CANONICAL (basetype
) != basetype
8184 || TYPE_CANONICAL (rettype
) != rettype
);
8185 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
8187 &any_noncanonical_p
);
8188 if (any_structural_p
)
8189 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8190 else if (any_noncanonical_p
)
8192 = build_method_type_directly (TYPE_CANONICAL (basetype
),
8193 TYPE_CANONICAL (rettype
),
8195 if (!COMPLETE_TYPE_P (t
))
8201 /* Construct, lay out and return the type of methods belonging to class
8202 BASETYPE and whose arguments and values are described by TYPE.
8203 If that type exists already, reuse it.
8204 TYPE must be a FUNCTION_TYPE node. */
8207 build_method_type (tree basetype
, tree type
)
8209 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
8211 return build_method_type_directly (basetype
,
8213 TYPE_ARG_TYPES (type
));
8216 /* Construct, lay out and return the type of offsets to a value
8217 of type TYPE, within an object of type BASETYPE.
8218 If a suitable offset type exists already, reuse it. */
8221 build_offset_type (tree basetype
, tree type
)
8224 hashval_t hashcode
= 0;
8226 /* Make a node of the sort we want. */
8227 t
= make_node (OFFSET_TYPE
);
8229 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8230 TREE_TYPE (t
) = type
;
8232 /* If we already have such a type, use the old one. */
8233 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8234 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
8235 t
= type_hash_canon (hashcode
, t
);
8237 if (!COMPLETE_TYPE_P (t
))
8240 if (TYPE_CANONICAL (t
) == t
)
8242 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8243 || TYPE_STRUCTURAL_EQUALITY_P (type
))
8244 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8245 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
8246 || TYPE_CANONICAL (type
) != type
)
8248 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
8249 TYPE_CANONICAL (type
));
8255 /* Create a complex type whose components are COMPONENT_TYPE. */
8258 build_complex_type (tree component_type
)
8263 gcc_assert (INTEGRAL_TYPE_P (component_type
)
8264 || SCALAR_FLOAT_TYPE_P (component_type
)
8265 || FIXED_POINT_TYPE_P (component_type
));
8267 /* Make a node of the sort we want. */
8268 t
= make_node (COMPLEX_TYPE
);
8270 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
8272 /* If we already have such a type, use the old one. */
8273 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
8274 t
= type_hash_canon (hashcode
, t
);
8276 if (!COMPLETE_TYPE_P (t
))
8279 if (TYPE_CANONICAL (t
) == t
)
8281 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
8282 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8283 else if (TYPE_CANONICAL (component_type
) != component_type
)
8285 = build_complex_type (TYPE_CANONICAL (component_type
));
8288 /* We need to create a name, since complex is a fundamental type. */
8289 if (! TYPE_NAME (t
))
8292 if (component_type
== char_type_node
)
8293 name
= "complex char";
8294 else if (component_type
== signed_char_type_node
)
8295 name
= "complex signed char";
8296 else if (component_type
== unsigned_char_type_node
)
8297 name
= "complex unsigned char";
8298 else if (component_type
== short_integer_type_node
)
8299 name
= "complex short int";
8300 else if (component_type
== short_unsigned_type_node
)
8301 name
= "complex short unsigned int";
8302 else if (component_type
== integer_type_node
)
8303 name
= "complex int";
8304 else if (component_type
== unsigned_type_node
)
8305 name
= "complex unsigned int";
8306 else if (component_type
== long_integer_type_node
)
8307 name
= "complex long int";
8308 else if (component_type
== long_unsigned_type_node
)
8309 name
= "complex long unsigned int";
8310 else if (component_type
== long_long_integer_type_node
)
8311 name
= "complex long long int";
8312 else if (component_type
== long_long_unsigned_type_node
)
8313 name
= "complex long long unsigned int";
8318 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
8319 get_identifier (name
), t
);
8322 return build_qualified_type (t
, TYPE_QUALS (component_type
));
8325 /* If TYPE is a real or complex floating-point type and the target
8326 does not directly support arithmetic on TYPE then return the wider
8327 type to be used for arithmetic on TYPE. Otherwise, return
8331 excess_precision_type (tree type
)
8333 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
8335 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
8336 switch (TREE_CODE (type
))
8339 switch (flt_eval_method
)
8342 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
8343 return double_type_node
;
8346 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
8347 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
8348 return long_double_type_node
;
8355 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
8357 switch (flt_eval_method
)
8360 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
8361 return complex_double_type_node
;
8364 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
8365 || (TYPE_MODE (TREE_TYPE (type
))
8366 == TYPE_MODE (double_type_node
)))
8367 return complex_long_double_type_node
;
8380 /* Return OP, stripped of any conversions to wider types as much as is safe.
8381 Converting the value back to OP's type makes a value equivalent to OP.
8383 If FOR_TYPE is nonzero, we return a value which, if converted to
8384 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8386 OP must have integer, real or enumeral type. Pointers are not allowed!
8388 There are some cases where the obvious value we could return
8389 would regenerate to OP if converted to OP's type,
8390 but would not extend like OP to wider types.
8391 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8392 For example, if OP is (unsigned short)(signed char)-1,
8393 we avoid returning (signed char)-1 if FOR_TYPE is int,
8394 even though extending that to an unsigned short would regenerate OP,
8395 since the result of extending (signed char)-1 to (int)
8396 is different from (int) OP. */
8399 get_unwidened (tree op
, tree for_type
)
8401 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8402 tree type
= TREE_TYPE (op
);
8404 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
8406 = (for_type
!= 0 && for_type
!= type
8407 && final_prec
> TYPE_PRECISION (type
)
8408 && TYPE_UNSIGNED (type
));
8411 while (CONVERT_EXPR_P (op
))
8415 /* TYPE_PRECISION on vector types has different meaning
8416 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8417 so avoid them here. */
8418 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
8421 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
8422 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
8424 /* Truncations are many-one so cannot be removed.
8425 Unless we are later going to truncate down even farther. */
8427 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
8430 /* See what's inside this conversion. If we decide to strip it,
8432 op
= TREE_OPERAND (op
, 0);
8434 /* If we have not stripped any zero-extensions (uns is 0),
8435 we can strip any kind of extension.
8436 If we have previously stripped a zero-extension,
8437 only zero-extensions can safely be stripped.
8438 Any extension can be stripped if the bits it would produce
8439 are all going to be discarded later by truncating to FOR_TYPE. */
8443 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
8445 /* TYPE_UNSIGNED says whether this is a zero-extension.
8446 Let's avoid computing it if it does not affect WIN
8447 and if UNS will not be needed again. */
8449 || CONVERT_EXPR_P (op
))
8450 && TYPE_UNSIGNED (TREE_TYPE (op
)))
8458 /* If we finally reach a constant see if it fits in for_type and
8459 in that case convert it. */
8461 && TREE_CODE (win
) == INTEGER_CST
8462 && TREE_TYPE (win
) != for_type
8463 && int_fits_type_p (win
, for_type
))
8464 win
= fold_convert (for_type
, win
);
8469 /* Return OP or a simpler expression for a narrower value
8470 which can be sign-extended or zero-extended to give back OP.
8471 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8472 or 0 if the value should be sign-extended. */
8475 get_narrower (tree op
, int *unsignedp_ptr
)
8480 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8482 while (TREE_CODE (op
) == NOP_EXPR
)
8485 = (TYPE_PRECISION (TREE_TYPE (op
))
8486 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8488 /* Truncations are many-one so cannot be removed. */
8492 /* See what's inside this conversion. If we decide to strip it,
8497 op
= TREE_OPERAND (op
, 0);
8498 /* An extension: the outermost one can be stripped,
8499 but remember whether it is zero or sign extension. */
8501 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8502 /* Otherwise, if a sign extension has been stripped,
8503 only sign extensions can now be stripped;
8504 if a zero extension has been stripped, only zero-extensions. */
8505 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8509 else /* bitschange == 0 */
8511 /* A change in nominal type can always be stripped, but we must
8512 preserve the unsignedness. */
8514 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8516 op
= TREE_OPERAND (op
, 0);
8517 /* Keep trying to narrow, but don't assign op to win if it
8518 would turn an integral type into something else. */
8519 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8526 if (TREE_CODE (op
) == COMPONENT_REF
8527 /* Since type_for_size always gives an integer type. */
8528 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8529 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8530 /* Ensure field is laid out already. */
8531 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8532 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
8534 unsigned HOST_WIDE_INT innerprec
8535 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
8536 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8537 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8538 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8540 /* We can get this structure field in a narrower type that fits it,
8541 but the resulting extension to its nominal type (a fullword type)
8542 must satisfy the same conditions as for other extensions.
8544 Do this only for fields that are aligned (not bit-fields),
8545 because when bit-field insns will be used there is no
8546 advantage in doing this. */
8548 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8549 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8550 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8554 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8555 win
= fold_convert (type
, op
);
8559 *unsignedp_ptr
= uns
;
8563 /* Returns true if integer constant C has a value that is permissible
8564 for type TYPE (an INTEGER_TYPE). */
8567 int_fits_type_p (const_tree c
, const_tree type
)
8569 tree type_low_bound
, type_high_bound
;
8570 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
8573 dc
= tree_to_double_int (c
);
8574 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
8577 type_low_bound
= TYPE_MIN_VALUE (type
);
8578 type_high_bound
= TYPE_MAX_VALUE (type
);
8580 /* If at least one bound of the type is a constant integer, we can check
8581 ourselves and maybe make a decision. If no such decision is possible, but
8582 this type is a subtype, try checking against that. Otherwise, use
8583 double_int_fits_to_tree_p, which checks against the precision.
8585 Compute the status for each possibly constant bound, and return if we see
8586 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8587 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8588 for "constant known to fit". */
8590 /* Check if c >= type_low_bound. */
8591 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8593 dd
= tree_to_double_int (type_low_bound
);
8594 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
8596 int c_neg
= (!unsc
&& dc
.is_negative ());
8597 int t_neg
= (unsc
&& dd
.is_negative ());
8599 if (c_neg
&& !t_neg
)
8601 if ((c_neg
|| !t_neg
) && dc
.ult (dd
))
8604 else if (dc
.cmp (dd
, unsc
) < 0)
8606 ok_for_low_bound
= true;
8609 ok_for_low_bound
= false;
8611 /* Check if c <= type_high_bound. */
8612 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8614 dd
= tree_to_double_int (type_high_bound
);
8615 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
8617 int c_neg
= (!unsc
&& dc
.is_negative ());
8618 int t_neg
= (unsc
&& dd
.is_negative ());
8620 if (t_neg
&& !c_neg
)
8622 if ((t_neg
|| !c_neg
) && dc
.ugt (dd
))
8625 else if (dc
.cmp (dd
, unsc
) > 0)
8627 ok_for_high_bound
= true;
8630 ok_for_high_bound
= false;
8632 /* If the constant fits both bounds, the result is known. */
8633 if (ok_for_low_bound
&& ok_for_high_bound
)
8636 /* Perform some generic filtering which may allow making a decision
8637 even if the bounds are not constant. First, negative integers
8638 never fit in unsigned types, */
8639 if (TYPE_UNSIGNED (type
) && !unsc
&& dc
.is_negative ())
8642 /* Second, narrower types always fit in wider ones. */
8643 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8646 /* Third, unsigned integers with top bit set never fit signed types. */
8647 if (! TYPE_UNSIGNED (type
) && unsc
)
8649 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
8650 if (prec
< HOST_BITS_PER_WIDE_INT
)
8652 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
8655 else if (((((unsigned HOST_WIDE_INT
) 1)
8656 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
8660 /* If we haven't been able to decide at this point, there nothing more we
8661 can check ourselves here. Look at the base type if we have one and it
8662 has the same precision. */
8663 if (TREE_CODE (type
) == INTEGER_TYPE
8664 && TREE_TYPE (type
) != 0
8665 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8667 type
= TREE_TYPE (type
);
8671 /* Or to double_int_fits_to_tree_p, if nothing else. */
8672 return double_int_fits_to_tree_p (type
, dc
);
8675 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8676 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8677 represented (assuming two's-complement arithmetic) within the bit
8678 precision of the type are returned instead. */
8681 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8683 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8684 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8685 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
8686 TYPE_UNSIGNED (type
));
8689 if (TYPE_UNSIGNED (type
))
8690 mpz_set_ui (min
, 0);
8694 mn
= double_int::mask (TYPE_PRECISION (type
) - 1);
8695 mn
= (mn
+ double_int_one
).sext (TYPE_PRECISION (type
));
8696 mpz_set_double_int (min
, mn
, false);
8700 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8701 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8702 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
8703 TYPE_UNSIGNED (type
));
8706 if (TYPE_UNSIGNED (type
))
8707 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
)),
8710 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
) - 1),
8715 /* Return true if VAR is an automatic variable defined in function FN. */
8718 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8720 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8721 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8722 || TREE_CODE (var
) == PARM_DECL
)
8723 && ! TREE_STATIC (var
))
8724 || TREE_CODE (var
) == LABEL_DECL
8725 || TREE_CODE (var
) == RESULT_DECL
));
8728 /* Subprogram of following function. Called by walk_tree.
8730 Return *TP if it is an automatic variable or parameter of the
8731 function passed in as DATA. */
8734 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8736 tree fn
= (tree
) data
;
8741 else if (DECL_P (*tp
)
8742 && auto_var_in_fn_p (*tp
, fn
))
8748 /* Returns true if T is, contains, or refers to a type with variable
8749 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8750 arguments, but not the return type. If FN is nonzero, only return
8751 true if a modifier of the type or position of FN is a variable or
8752 parameter inside FN.
8754 This concept is more general than that of C99 'variably modified types':
8755 in C99, a struct type is never variably modified because a VLA may not
8756 appear as a structure member. However, in GNU C code like:
8758 struct S { int i[f()]; };
8760 is valid, and other languages may define similar constructs. */
8763 variably_modified_type_p (tree type
, tree fn
)
8767 /* Test if T is either variable (if FN is zero) or an expression containing
8768 a variable in FN. If TYPE isn't gimplified, return true also if
8769 gimplify_one_sizepos would gimplify the expression into a local
8771 #define RETURN_TRUE_IF_VAR(T) \
8772 do { tree _t = (T); \
8773 if (_t != NULL_TREE \
8774 && _t != error_mark_node \
8775 && TREE_CODE (_t) != INTEGER_CST \
8776 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8778 || (!TYPE_SIZES_GIMPLIFIED (type) \
8779 && !is_gimple_sizepos (_t)) \
8780 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8781 return true; } while (0)
8783 if (type
== error_mark_node
)
8786 /* If TYPE itself has variable size, it is variably modified. */
8787 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8788 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8790 switch (TREE_CODE (type
))
8793 case REFERENCE_TYPE
:
8795 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8801 /* If TYPE is a function type, it is variably modified if the
8802 return type is variably modified. */
8803 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8809 case FIXED_POINT_TYPE
:
8812 /* Scalar types are variably modified if their end points
8814 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8815 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8820 case QUAL_UNION_TYPE
:
8821 /* We can't see if any of the fields are variably-modified by the
8822 definition we normally use, since that would produce infinite
8823 recursion via pointers. */
8824 /* This is variably modified if some field's type is. */
8825 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8826 if (TREE_CODE (t
) == FIELD_DECL
)
8828 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8829 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8830 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8832 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8833 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8838 /* Do not call ourselves to avoid infinite recursion. This is
8839 variably modified if the element type is. */
8840 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8841 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8848 /* The current language may have other cases to check, but in general,
8849 all other types are not variably modified. */
8850 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8852 #undef RETURN_TRUE_IF_VAR
8855 /* Given a DECL or TYPE, return the scope in which it was declared, or
8856 NULL_TREE if there is no containing scope. */
8859 get_containing_scope (const_tree t
)
8861 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8864 /* Return the innermost context enclosing DECL that is
8865 a FUNCTION_DECL, or zero if none. */
8868 decl_function_context (const_tree decl
)
8872 if (TREE_CODE (decl
) == ERROR_MARK
)
8875 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8876 where we look up the function at runtime. Such functions always take
8877 a first argument of type 'pointer to real context'.
8879 C++ should really be fixed to use DECL_CONTEXT for the real context,
8880 and use something else for the "virtual context". */
8881 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
8884 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8886 context
= DECL_CONTEXT (decl
);
8888 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8890 if (TREE_CODE (context
) == BLOCK
)
8891 context
= BLOCK_SUPERCONTEXT (context
);
8893 context
= get_containing_scope (context
);
8899 /* Return the innermost context enclosing DECL that is
8900 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8901 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8904 decl_type_context (const_tree decl
)
8906 tree context
= DECL_CONTEXT (decl
);
8909 switch (TREE_CODE (context
))
8911 case NAMESPACE_DECL
:
8912 case TRANSLATION_UNIT_DECL
:
8917 case QUAL_UNION_TYPE
:
8922 context
= DECL_CONTEXT (context
);
8926 context
= BLOCK_SUPERCONTEXT (context
);
8936 /* CALL is a CALL_EXPR. Return the declaration for the function
8937 called, or NULL_TREE if the called function cannot be
8941 get_callee_fndecl (const_tree call
)
8945 if (call
== error_mark_node
)
8946 return error_mark_node
;
8948 /* It's invalid to call this function with anything but a
8950 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8952 /* The first operand to the CALL is the address of the function
8954 addr
= CALL_EXPR_FN (call
);
8958 /* If this is a readonly function pointer, extract its initial value. */
8959 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
8960 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
8961 && DECL_INITIAL (addr
))
8962 addr
= DECL_INITIAL (addr
);
8964 /* If the address is just `&f' for some function `f', then we know
8965 that `f' is being called. */
8966 if (TREE_CODE (addr
) == ADDR_EXPR
8967 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
8968 return TREE_OPERAND (addr
, 0);
8970 /* We couldn't figure out what was being called. */
8974 /* Print debugging information about tree nodes generated during the compile,
8975 and any language-specific information. */
8978 dump_tree_statistics (void)
8980 if (GATHER_STATISTICS
)
8983 int total_nodes
, total_bytes
;
8984 fprintf (stderr
, "Kind Nodes Bytes\n");
8985 fprintf (stderr
, "---------------------------------------\n");
8986 total_nodes
= total_bytes
= 0;
8987 for (i
= 0; i
< (int) all_kinds
; i
++)
8989 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
8990 tree_node_counts
[i
], tree_node_sizes
[i
]);
8991 total_nodes
+= tree_node_counts
[i
];
8992 total_bytes
+= tree_node_sizes
[i
];
8994 fprintf (stderr
, "---------------------------------------\n");
8995 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
8996 fprintf (stderr
, "---------------------------------------\n");
8997 fprintf (stderr
, "Code Nodes\n");
8998 fprintf (stderr
, "----------------------------\n");
8999 for (i
= 0; i
< (int) MAX_TREE_CODES
; i
++)
9000 fprintf (stderr
, "%-20s %7d\n", tree_code_name
[i
], tree_code_counts
[i
]);
9001 fprintf (stderr
, "----------------------------\n");
9002 ssanames_print_statistics ();
9003 phinodes_print_statistics ();
9006 fprintf (stderr
, "(No per-node statistics)\n");
9008 print_type_hash_statistics ();
9009 print_debug_expr_statistics ();
9010 print_value_expr_statistics ();
9011 lang_hooks
.print_statistics ();
9014 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9016 /* Generate a crc32 of a byte. */
9019 crc32_unsigned_bits (unsigned chksum
, unsigned value
, unsigned bits
)
9023 for (ix
= bits
; ix
--; value
<<= 1)
9027 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
9034 /* Generate a crc32 of a 32-bit unsigned. */
9037 crc32_unsigned (unsigned chksum
, unsigned value
)
9039 return crc32_unsigned_bits (chksum
, value
, 32);
9042 /* Generate a crc32 of a byte. */
9045 crc32_byte (unsigned chksum
, char byte
)
9047 return crc32_unsigned_bits (chksum
, (unsigned) byte
<< 24, 8);
9050 /* Generate a crc32 of a string. */
9053 crc32_string (unsigned chksum
, const char *string
)
9057 chksum
= crc32_byte (chksum
, *string
);
9063 /* P is a string that will be used in a symbol. Mask out any characters
9064 that are not valid in that context. */
9067 clean_symbol_name (char *p
)
9071 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9074 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9081 /* Generate a name for a special-purpose function.
9082 The generated name may need to be unique across the whole link.
9083 Changes to this function may also require corresponding changes to
9084 xstrdup_mask_random.
9085 TYPE is some string to identify the purpose of this function to the
9086 linker or collect2; it must start with an uppercase letter,
9088 I - for constructors
9090 N - for C++ anonymous namespaces
9091 F - for DWARF unwind frame information. */
9094 get_file_function_name (const char *type
)
9100 /* If we already have a name we know to be unique, just use that. */
9101 if (first_global_object_name
)
9102 p
= q
= ASTRDUP (first_global_object_name
);
9103 /* If the target is handling the constructors/destructors, they
9104 will be local to this file and the name is only necessary for
9106 We also assign sub_I and sub_D sufixes to constructors called from
9107 the global static constructors. These are always local. */
9108 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
9109 || (strncmp (type
, "sub_", 4) == 0
9110 && (type
[4] == 'I' || type
[4] == 'D')))
9112 const char *file
= main_input_filename
;
9114 file
= input_filename
;
9115 /* Just use the file's basename, because the full pathname
9116 might be quite long. */
9117 p
= q
= ASTRDUP (lbasename (file
));
9121 /* Otherwise, the name must be unique across the entire link.
9122 We don't have anything that we know to be unique to this translation
9123 unit, so use what we do have and throw in some randomness. */
9125 const char *name
= weak_global_object_name
;
9126 const char *file
= main_input_filename
;
9131 file
= input_filename
;
9133 len
= strlen (file
);
9134 q
= (char *) alloca (9 + 17 + len
+ 1);
9135 memcpy (q
, file
, len
+ 1);
9137 snprintf (q
+ len
, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
9138 crc32_string (0, name
), get_random_seed (false));
9143 clean_symbol_name (q
);
9144 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
9147 /* Set up the name of the file-level functions we may need.
9148 Use a global object (which is already required to be unique over
9149 the program) rather than the file name (which imposes extra
9151 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
9153 return get_identifier (buf
);
9156 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9158 /* Complain that the tree code of NODE does not match the expected 0
9159 terminated list of trailing codes. The trailing code list can be
9160 empty, for a more vague error message. FILE, LINE, and FUNCTION
9161 are of the caller. */
9164 tree_check_failed (const_tree node
, const char *file
,
9165 int line
, const char *function
, ...)
9169 unsigned length
= 0;
9172 va_start (args
, function
);
9173 while ((code
= va_arg (args
, int)))
9174 length
+= 4 + strlen (tree_code_name
[code
]);
9179 va_start (args
, function
);
9180 length
+= strlen ("expected ");
9181 buffer
= tmp
= (char *) alloca (length
);
9183 while ((code
= va_arg (args
, int)))
9185 const char *prefix
= length
? " or " : "expected ";
9187 strcpy (tmp
+ length
, prefix
);
9188 length
+= strlen (prefix
);
9189 strcpy (tmp
+ length
, tree_code_name
[code
]);
9190 length
+= strlen (tree_code_name
[code
]);
9195 buffer
= "unexpected node";
9197 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9198 buffer
, tree_code_name
[TREE_CODE (node
)],
9199 function
, trim_filename (file
), line
);
9202 /* Complain that the tree code of NODE does match the expected 0
9203 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9207 tree_not_check_failed (const_tree node
, const char *file
,
9208 int line
, const char *function
, ...)
9212 unsigned length
= 0;
9215 va_start (args
, function
);
9216 while ((code
= va_arg (args
, int)))
9217 length
+= 4 + strlen (tree_code_name
[code
]);
9219 va_start (args
, function
);
9220 buffer
= (char *) alloca (length
);
9222 while ((code
= va_arg (args
, int)))
9226 strcpy (buffer
+ length
, " or ");
9229 strcpy (buffer
+ length
, tree_code_name
[code
]);
9230 length
+= strlen (tree_code_name
[code
]);
9234 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9235 buffer
, tree_code_name
[TREE_CODE (node
)],
9236 function
, trim_filename (file
), line
);
9239 /* Similar to tree_check_failed, except that we check for a class of tree
9240 code, given in CL. */
9243 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9244 const char *file
, int line
, const char *function
)
9247 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9248 TREE_CODE_CLASS_STRING (cl
),
9249 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9250 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9253 /* Similar to tree_check_failed, except that instead of specifying a
9254 dozen codes, use the knowledge that they're all sequential. */
9257 tree_range_check_failed (const_tree node
, const char *file
, int line
,
9258 const char *function
, enum tree_code c1
,
9262 unsigned length
= 0;
9265 for (c
= c1
; c
<= c2
; ++c
)
9266 length
+= 4 + strlen (tree_code_name
[c
]);
9268 length
+= strlen ("expected ");
9269 buffer
= (char *) alloca (length
);
9272 for (c
= c1
; c
<= c2
; ++c
)
9274 const char *prefix
= length
? " or " : "expected ";
9276 strcpy (buffer
+ length
, prefix
);
9277 length
+= strlen (prefix
);
9278 strcpy (buffer
+ length
, tree_code_name
[c
]);
9279 length
+= strlen (tree_code_name
[c
]);
9282 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9283 buffer
, tree_code_name
[TREE_CODE (node
)],
9284 function
, trim_filename (file
), line
);
9288 /* Similar to tree_check_failed, except that we check that a tree does
9289 not have the specified code, given in CL. */
9292 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9293 const char *file
, int line
, const char *function
)
9296 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9297 TREE_CODE_CLASS_STRING (cl
),
9298 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9299 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9303 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9306 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
9307 const char *function
, enum omp_clause_code code
)
9309 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9310 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
9311 function
, trim_filename (file
), line
);
9315 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9318 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
9319 const char *function
, enum omp_clause_code c1
,
9320 enum omp_clause_code c2
)
9323 unsigned length
= 0;
9326 for (c
= c1
; c
<= c2
; ++c
)
9327 length
+= 4 + strlen (omp_clause_code_name
[c
]);
9329 length
+= strlen ("expected ");
9330 buffer
= (char *) alloca (length
);
9333 for (c
= c1
; c
<= c2
; ++c
)
9335 const char *prefix
= length
? " or " : "expected ";
9337 strcpy (buffer
+ length
, prefix
);
9338 length
+= strlen (prefix
);
9339 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
9340 length
+= strlen (omp_clause_code_name
[c
]);
9343 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9344 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
9345 function
, trim_filename (file
), line
);
9349 #undef DEFTREESTRUCT
9350 #define DEFTREESTRUCT(VAL, NAME) NAME,
9352 static const char *ts_enum_names
[] = {
9353 #include "treestruct.def"
9355 #undef DEFTREESTRUCT
9357 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9359 /* Similar to tree_class_check_failed, except that we check for
9360 whether CODE contains the tree structure identified by EN. */
9363 tree_contains_struct_check_failed (const_tree node
,
9364 const enum tree_node_structure_enum en
,
9365 const char *file
, int line
,
9366 const char *function
)
9369 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9371 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9375 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9376 (dynamically sized) vector. */
9379 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9380 const char *function
)
9383 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9384 idx
+ 1, len
, function
, trim_filename (file
), line
);
9387 /* Similar to above, except that the check is for the bounds of the operand
9388 vector of an expression node EXP. */
9391 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
9392 int line
, const char *function
)
9394 int code
= TREE_CODE (exp
);
9396 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9397 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
9398 function
, trim_filename (file
), line
);
9401 /* Similar to above, except that the check is for the number of
9402 operands of an OMP_CLAUSE node. */
9405 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
9406 int line
, const char *function
)
9409 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9410 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
9411 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
9412 trim_filename (file
), line
);
9414 #endif /* ENABLE_TREE_CHECKING */
9416 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9417 and mapped to the machine mode MODE. Initialize its fields and build
9418 the information necessary for debugging output. */
9421 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
9424 hashval_t hashcode
= 0;
9426 t
= make_node (VECTOR_TYPE
);
9427 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
9428 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
9429 SET_TYPE_MODE (t
, mode
);
9431 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
9432 SET_TYPE_STRUCTURAL_EQUALITY (t
);
9433 else if (TYPE_CANONICAL (innertype
) != innertype
9434 || mode
!= VOIDmode
)
9436 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
9440 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
9441 hashcode
= iterative_hash_host_wide_int (nunits
, hashcode
);
9442 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
9443 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (t
)), hashcode
);
9444 t
= type_hash_canon (hashcode
, t
);
9446 /* We have built a main variant, based on the main variant of the
9447 inner type. Use it to build the variant we return. */
9448 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
9449 && TREE_TYPE (t
) != innertype
)
9450 return build_type_attribute_qual_variant (t
,
9451 TYPE_ATTRIBUTES (innertype
),
9452 TYPE_QUALS (innertype
));
9458 make_or_reuse_type (unsigned size
, int unsignedp
)
9460 if (size
== INT_TYPE_SIZE
)
9461 return unsignedp
? unsigned_type_node
: integer_type_node
;
9462 if (size
== CHAR_TYPE_SIZE
)
9463 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
9464 if (size
== SHORT_TYPE_SIZE
)
9465 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
9466 if (size
== LONG_TYPE_SIZE
)
9467 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
9468 if (size
== LONG_LONG_TYPE_SIZE
)
9469 return (unsignedp
? long_long_unsigned_type_node
9470 : long_long_integer_type_node
);
9471 if (size
== 128 && int128_integer_type_node
)
9472 return (unsignedp
? int128_unsigned_type_node
9473 : int128_integer_type_node
);
9476 return make_unsigned_type (size
);
9478 return make_signed_type (size
);
9481 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9484 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
9488 if (size
== SHORT_FRACT_TYPE_SIZE
)
9489 return unsignedp
? sat_unsigned_short_fract_type_node
9490 : sat_short_fract_type_node
;
9491 if (size
== FRACT_TYPE_SIZE
)
9492 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9493 if (size
== LONG_FRACT_TYPE_SIZE
)
9494 return unsignedp
? sat_unsigned_long_fract_type_node
9495 : sat_long_fract_type_node
;
9496 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9497 return unsignedp
? sat_unsigned_long_long_fract_type_node
9498 : sat_long_long_fract_type_node
;
9502 if (size
== SHORT_FRACT_TYPE_SIZE
)
9503 return unsignedp
? unsigned_short_fract_type_node
9504 : short_fract_type_node
;
9505 if (size
== FRACT_TYPE_SIZE
)
9506 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9507 if (size
== LONG_FRACT_TYPE_SIZE
)
9508 return unsignedp
? unsigned_long_fract_type_node
9509 : long_fract_type_node
;
9510 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9511 return unsignedp
? unsigned_long_long_fract_type_node
9512 : long_long_fract_type_node
;
9515 return make_fract_type (size
, unsignedp
, satp
);
9518 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9521 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9525 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9526 return unsignedp
? sat_unsigned_short_accum_type_node
9527 : sat_short_accum_type_node
;
9528 if (size
== ACCUM_TYPE_SIZE
)
9529 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9530 if (size
== LONG_ACCUM_TYPE_SIZE
)
9531 return unsignedp
? sat_unsigned_long_accum_type_node
9532 : sat_long_accum_type_node
;
9533 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9534 return unsignedp
? sat_unsigned_long_long_accum_type_node
9535 : sat_long_long_accum_type_node
;
9539 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9540 return unsignedp
? unsigned_short_accum_type_node
9541 : short_accum_type_node
;
9542 if (size
== ACCUM_TYPE_SIZE
)
9543 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9544 if (size
== LONG_ACCUM_TYPE_SIZE
)
9545 return unsignedp
? unsigned_long_accum_type_node
9546 : long_accum_type_node
;
9547 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9548 return unsignedp
? unsigned_long_long_accum_type_node
9549 : long_long_accum_type_node
;
9552 return make_accum_type (size
, unsignedp
, satp
);
9555 /* Create nodes for all integer types (and error_mark_node) using the sizes
9556 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9557 SHORT_DOUBLE specifies whether double should be of the same precision
9561 build_common_tree_nodes (bool signed_char
, bool short_double
)
9563 error_mark_node
= make_node (ERROR_MARK
);
9564 TREE_TYPE (error_mark_node
) = error_mark_node
;
9566 initialize_sizetypes ();
9568 /* Define both `signed char' and `unsigned char'. */
9569 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9570 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9571 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9572 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9574 /* Define `char', which is like either `signed char' or `unsigned char'
9575 but not the same as either. */
9578 ? make_signed_type (CHAR_TYPE_SIZE
)
9579 : make_unsigned_type (CHAR_TYPE_SIZE
));
9580 TYPE_STRING_FLAG (char_type_node
) = 1;
9582 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9583 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9584 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9585 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9586 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9587 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9588 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9589 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9590 #if HOST_BITS_PER_WIDE_INT >= 64
9591 /* TODO: This isn't correct, but as logic depends at the moment on
9592 host's instead of target's wide-integer.
9593 If there is a target not supporting TImode, but has an 128-bit
9594 integer-scalar register, this target check needs to be adjusted. */
9595 if (targetm
.scalar_mode_supported_p (TImode
))
9597 int128_integer_type_node
= make_signed_type (128);
9598 int128_unsigned_type_node
= make_unsigned_type (128);
9602 /* Define a boolean type. This type only represents boolean values but
9603 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9604 Front ends which want to override this size (i.e. Java) can redefine
9605 boolean_type_node before calling build_common_tree_nodes_2. */
9606 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9607 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9608 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9609 TYPE_PRECISION (boolean_type_node
) = 1;
9611 /* Define what type to use for size_t. */
9612 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
9613 size_type_node
= unsigned_type_node
;
9614 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
9615 size_type_node
= long_unsigned_type_node
;
9616 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
9617 size_type_node
= long_long_unsigned_type_node
;
9618 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
9619 size_type_node
= short_unsigned_type_node
;
9623 /* Fill in the rest of the sized types. Reuse existing type nodes
9625 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9626 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9627 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9628 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9629 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9631 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9632 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9633 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9634 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9635 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9637 access_public_node
= get_identifier ("public");
9638 access_protected_node
= get_identifier ("protected");
9639 access_private_node
= get_identifier ("private");
9641 /* Define these next since types below may used them. */
9642 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9643 integer_one_node
= build_int_cst (integer_type_node
, 1);
9644 integer_three_node
= build_int_cst (integer_type_node
, 3);
9645 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9647 size_zero_node
= size_int (0);
9648 size_one_node
= size_int (1);
9649 bitsize_zero_node
= bitsize_int (0);
9650 bitsize_one_node
= bitsize_int (1);
9651 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9653 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9654 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9656 void_type_node
= make_node (VOID_TYPE
);
9657 layout_type (void_type_node
);
9659 /* We are not going to have real types in C with less than byte alignment,
9660 so we might as well not have any types that claim to have it. */
9661 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
9662 TYPE_USER_ALIGN (void_type_node
) = 0;
9664 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9665 layout_type (TREE_TYPE (null_pointer_node
));
9667 ptr_type_node
= build_pointer_type (void_type_node
);
9669 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9670 fileptr_type_node
= ptr_type_node
;
9672 float_type_node
= make_node (REAL_TYPE
);
9673 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9674 layout_type (float_type_node
);
9676 double_type_node
= make_node (REAL_TYPE
);
9678 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
9680 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9681 layout_type (double_type_node
);
9683 long_double_type_node
= make_node (REAL_TYPE
);
9684 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9685 layout_type (long_double_type_node
);
9687 float_ptr_type_node
= build_pointer_type (float_type_node
);
9688 double_ptr_type_node
= build_pointer_type (double_type_node
);
9689 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9690 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9692 /* Fixed size integer types. */
9693 uint16_type_node
= build_nonstandard_integer_type (16, true);
9694 uint32_type_node
= build_nonstandard_integer_type (32, true);
9695 uint64_type_node
= build_nonstandard_integer_type (64, true);
9697 /* Decimal float types. */
9698 dfloat32_type_node
= make_node (REAL_TYPE
);
9699 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9700 layout_type (dfloat32_type_node
);
9701 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9702 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
9704 dfloat64_type_node
= make_node (REAL_TYPE
);
9705 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9706 layout_type (dfloat64_type_node
);
9707 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9708 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
9710 dfloat128_type_node
= make_node (REAL_TYPE
);
9711 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9712 layout_type (dfloat128_type_node
);
9713 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9714 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
9716 complex_integer_type_node
= build_complex_type (integer_type_node
);
9717 complex_float_type_node
= build_complex_type (float_type_node
);
9718 complex_double_type_node
= build_complex_type (double_type_node
);
9719 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
9721 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9722 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9723 sat_ ## KIND ## _type_node = \
9724 make_sat_signed_ ## KIND ## _type (SIZE); \
9725 sat_unsigned_ ## KIND ## _type_node = \
9726 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9727 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9728 unsigned_ ## KIND ## _type_node = \
9729 make_unsigned_ ## KIND ## _type (SIZE);
9731 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9732 sat_ ## WIDTH ## KIND ## _type_node = \
9733 make_sat_signed_ ## KIND ## _type (SIZE); \
9734 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9735 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9736 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9737 unsigned_ ## WIDTH ## KIND ## _type_node = \
9738 make_unsigned_ ## KIND ## _type (SIZE);
9740 /* Make fixed-point type nodes based on four different widths. */
9741 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9742 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9743 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9744 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9745 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9747 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9748 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9749 NAME ## _type_node = \
9750 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9751 u ## NAME ## _type_node = \
9752 make_or_reuse_unsigned_ ## KIND ## _type \
9753 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9754 sat_ ## NAME ## _type_node = \
9755 make_or_reuse_sat_signed_ ## KIND ## _type \
9756 (GET_MODE_BITSIZE (MODE ## mode)); \
9757 sat_u ## NAME ## _type_node = \
9758 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9759 (GET_MODE_BITSIZE (U ## MODE ## mode));
9761 /* Fixed-point type and mode nodes. */
9762 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9763 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9764 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9765 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9766 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9767 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9768 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9769 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9770 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9771 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9772 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9775 tree t
= targetm
.build_builtin_va_list ();
9777 /* Many back-ends define record types without setting TYPE_NAME.
9778 If we copied the record type here, we'd keep the original
9779 record type without a name. This breaks name mangling. So,
9780 don't copy record types and let c_common_nodes_and_builtins()
9781 declare the type to be __builtin_va_list. */
9782 if (TREE_CODE (t
) != RECORD_TYPE
)
9783 t
= build_variant_type_copy (t
);
9785 va_list_type_node
= t
;
9789 /* Modify DECL for given flags. */
9791 set_call_expr_flags (tree decl
, int flags
)
9793 if (flags
& ECF_NOTHROW
)
9794 TREE_NOTHROW (decl
) = 1;
9795 if (flags
& ECF_CONST
)
9796 TREE_READONLY (decl
) = 1;
9797 if (flags
& ECF_PURE
)
9798 DECL_PURE_P (decl
) = 1;
9799 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
9800 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9801 if (flags
& ECF_NOVOPS
)
9802 DECL_IS_NOVOPS (decl
) = 1;
9803 if (flags
& ECF_NORETURN
)
9804 TREE_THIS_VOLATILE (decl
) = 1;
9805 if (flags
& ECF_MALLOC
)
9806 DECL_IS_MALLOC (decl
) = 1;
9807 if (flags
& ECF_RETURNS_TWICE
)
9808 DECL_IS_RETURNS_TWICE (decl
) = 1;
9809 if (flags
& ECF_LEAF
)
9810 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9811 NULL
, DECL_ATTRIBUTES (decl
));
9812 if ((flags
& ECF_TM_PURE
) && flag_tm
)
9813 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("transaction_pure"),
9814 NULL
, DECL_ATTRIBUTES (decl
));
9815 /* Looping const or pure is implied by noreturn.
9816 There is currently no way to declare looping const or looping pure alone. */
9817 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
9818 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
9822 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9825 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9826 const char *library_name
, int ecf_flags
)
9830 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9831 library_name
, NULL_TREE
);
9832 set_call_expr_flags (decl
, ecf_flags
);
9834 set_builtin_decl (code
, decl
, true);
9837 /* Call this function after instantiating all builtins that the language
9838 front end cares about. This will build the rest of the builtins that
9839 are relied upon by the tree optimizers and the middle-end. */
9842 build_common_builtin_nodes (void)
9847 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
9849 ftype
= build_function_type (void_type_node
, void_list_node
);
9850 local_define_builtin ("__builtin_unreachable", ftype
, BUILT_IN_UNREACHABLE
,
9851 "__builtin_unreachable",
9852 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
9853 | ECF_CONST
| ECF_LEAF
);
9856 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
9857 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9859 ftype
= build_function_type_list (ptr_type_node
,
9860 ptr_type_node
, const_ptr_type_node
,
9861 size_type_node
, NULL_TREE
);
9863 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
9864 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9865 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9866 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9867 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9868 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9871 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
9873 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9874 const_ptr_type_node
, size_type_node
,
9876 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9877 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9880 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
9882 ftype
= build_function_type_list (ptr_type_node
,
9883 ptr_type_node
, integer_type_node
,
9884 size_type_node
, NULL_TREE
);
9885 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9886 "memset", ECF_NOTHROW
| ECF_LEAF
);
9889 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
9891 ftype
= build_function_type_list (ptr_type_node
,
9892 size_type_node
, NULL_TREE
);
9893 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
9894 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9897 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
9898 size_type_node
, NULL_TREE
);
9899 local_define_builtin ("__builtin_alloca_with_align", ftype
,
9900 BUILT_IN_ALLOCA_WITH_ALIGN
, "alloca",
9901 ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9903 /* If we're checking the stack, `alloca' can throw. */
9904 if (flag_stack_check
)
9906 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA
)) = 0;
9907 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
)) = 0;
9910 ftype
= build_function_type_list (void_type_node
,
9911 ptr_type_node
, ptr_type_node
,
9912 ptr_type_node
, NULL_TREE
);
9913 local_define_builtin ("__builtin_init_trampoline", ftype
,
9914 BUILT_IN_INIT_TRAMPOLINE
,
9915 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
9916 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
9917 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
9918 "__builtin_init_heap_trampoline",
9919 ECF_NOTHROW
| ECF_LEAF
);
9921 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9922 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
9923 BUILT_IN_ADJUST_TRAMPOLINE
,
9924 "__builtin_adjust_trampoline",
9925 ECF_CONST
| ECF_NOTHROW
);
9927 ftype
= build_function_type_list (void_type_node
,
9928 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9929 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
9930 BUILT_IN_NONLOCAL_GOTO
,
9931 "__builtin_nonlocal_goto",
9932 ECF_NORETURN
| ECF_NOTHROW
);
9934 ftype
= build_function_type_list (void_type_node
,
9935 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9936 local_define_builtin ("__builtin_setjmp_setup", ftype
,
9937 BUILT_IN_SETJMP_SETUP
,
9938 "__builtin_setjmp_setup", ECF_NOTHROW
);
9940 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9941 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
9942 BUILT_IN_SETJMP_DISPATCHER
,
9943 "__builtin_setjmp_dispatcher",
9944 ECF_PURE
| ECF_NOTHROW
);
9946 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9947 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
9948 BUILT_IN_SETJMP_RECEIVER
,
9949 "__builtin_setjmp_receiver", ECF_NOTHROW
);
9951 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
9952 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
9953 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
9955 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9956 local_define_builtin ("__builtin_stack_restore", ftype
,
9957 BUILT_IN_STACK_RESTORE
,
9958 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
9960 /* If there's a possibility that we might use the ARM EABI, build the
9961 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9962 if (targetm
.arm_eabi_unwinder
)
9964 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9965 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
9966 BUILT_IN_CXA_END_CLEANUP
,
9967 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
9970 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9971 local_define_builtin ("__builtin_unwind_resume", ftype
,
9972 BUILT_IN_UNWIND_RESUME
,
9973 ((targetm_common
.except_unwind_info (&global_options
)
9975 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9978 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
9980 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
9982 local_define_builtin ("__builtin_return_address", ftype
,
9983 BUILT_IN_RETURN_ADDRESS
,
9984 "__builtin_return_address",
9988 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
9989 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9991 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
9992 ptr_type_node
, NULL_TREE
);
9993 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
9994 local_define_builtin ("__cyg_profile_func_enter", ftype
,
9995 BUILT_IN_PROFILE_FUNC_ENTER
,
9996 "__cyg_profile_func_enter", 0);
9997 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9998 local_define_builtin ("__cyg_profile_func_exit", ftype
,
9999 BUILT_IN_PROFILE_FUNC_EXIT
,
10000 "__cyg_profile_func_exit", 0);
10003 /* The exception object and filter values from the runtime. The argument
10004 must be zero before exception lowering, i.e. from the front end. After
10005 exception lowering, it will be the region number for the exception
10006 landing pad. These functions are PURE instead of CONST to prevent
10007 them from being hoisted past the exception edge that will initialize
10008 its value in the landing pad. */
10009 ftype
= build_function_type_list (ptr_type_node
,
10010 integer_type_node
, NULL_TREE
);
10011 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
10012 /* Only use TM_PURE if we we have TM language support. */
10013 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
10014 ecf_flags
|= ECF_TM_PURE
;
10015 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
10016 "__builtin_eh_pointer", ecf_flags
);
10018 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
10019 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
10020 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
10021 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10023 ftype
= build_function_type_list (void_type_node
,
10024 integer_type_node
, integer_type_node
,
10026 local_define_builtin ("__builtin_eh_copy_values", ftype
,
10027 BUILT_IN_EH_COPY_VALUES
,
10028 "__builtin_eh_copy_values", ECF_NOTHROW
);
10030 /* Complex multiplication and division. These are handled as builtins
10031 rather than optabs because emit_library_call_value doesn't support
10032 complex. Further, we can do slightly better with folding these
10033 beasties if the real and complex parts of the arguments are separate. */
10037 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
10039 char mode_name_buf
[4], *q
;
10041 enum built_in_function mcode
, dcode
;
10042 tree type
, inner_type
;
10043 const char *prefix
= "__";
10045 if (targetm
.libfunc_gnu_prefix
)
10048 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
10051 inner_type
= TREE_TYPE (type
);
10053 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
10054 inner_type
, inner_type
, NULL_TREE
);
10056 mcode
= ((enum built_in_function
)
10057 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10058 dcode
= ((enum built_in_function
)
10059 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10061 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
10065 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
10067 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
10068 built_in_names
[mcode
],
10069 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10071 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
10073 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
10074 built_in_names
[dcode
],
10075 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10080 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10083 If we requested a pointer to a vector, build up the pointers that
10084 we stripped off while looking for the inner type. Similarly for
10085 return values from functions.
10087 The argument TYPE is the top of the chain, and BOTTOM is the
10088 new type which we will point to. */
10091 reconstruct_complex_type (tree type
, tree bottom
)
10095 if (TREE_CODE (type
) == POINTER_TYPE
)
10097 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10098 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
10099 TYPE_REF_CAN_ALIAS_ALL (type
));
10101 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
10103 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10104 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
10105 TYPE_REF_CAN_ALIAS_ALL (type
));
10107 else if (TREE_CODE (type
) == ARRAY_TYPE
)
10109 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10110 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
10112 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
10114 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10115 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
10117 else if (TREE_CODE (type
) == METHOD_TYPE
)
10119 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10120 /* The build_method_type_directly() routine prepends 'this' to argument list,
10121 so we must compensate by getting rid of it. */
10123 = build_method_type_directly
10124 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
10126 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
10128 else if (TREE_CODE (type
) == OFFSET_TYPE
)
10130 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10131 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
10136 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
10137 TYPE_QUALS (type
));
10140 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10143 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
10147 switch (GET_MODE_CLASS (mode
))
10149 case MODE_VECTOR_INT
:
10150 case MODE_VECTOR_FLOAT
:
10151 case MODE_VECTOR_FRACT
:
10152 case MODE_VECTOR_UFRACT
:
10153 case MODE_VECTOR_ACCUM
:
10154 case MODE_VECTOR_UACCUM
:
10155 nunits
= GET_MODE_NUNITS (mode
);
10159 /* Check that there are no leftover bits. */
10160 gcc_assert (GET_MODE_BITSIZE (mode
)
10161 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
10163 nunits
= GET_MODE_BITSIZE (mode
)
10164 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
10168 gcc_unreachable ();
10171 return make_vector_type (innertype
, nunits
, mode
);
10174 /* Similarly, but takes the inner type and number of units, which must be
10178 build_vector_type (tree innertype
, int nunits
)
10180 return make_vector_type (innertype
, nunits
, VOIDmode
);
10183 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10186 build_opaque_vector_type (tree innertype
, int nunits
)
10188 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
10190 /* We always build the non-opaque variant before the opaque one,
10191 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10192 cand
= TYPE_NEXT_VARIANT (t
);
10194 && TYPE_VECTOR_OPAQUE (cand
)
10195 && check_qualified_type (cand
, t
, TYPE_QUALS (t
)))
10197 /* Othewise build a variant type and make sure to queue it after
10198 the non-opaque type. */
10199 cand
= build_distinct_type_copy (t
);
10200 TYPE_VECTOR_OPAQUE (cand
) = true;
10201 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
10202 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
10203 TYPE_NEXT_VARIANT (t
) = cand
;
10204 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
10209 /* Given an initializer INIT, return TRUE if INIT is zero or some
10210 aggregate of zeros. Otherwise return FALSE. */
10212 initializer_zerop (const_tree init
)
10218 switch (TREE_CODE (init
))
10221 return integer_zerop (init
);
10224 /* ??? Note that this is not correct for C4X float formats. There,
10225 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10226 negative exponent. */
10227 return real_zerop (init
)
10228 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
10231 return fixed_zerop (init
);
10234 return integer_zerop (init
)
10235 || (real_zerop (init
)
10236 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10237 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
10242 for (i
= 0; i
< VECTOR_CST_NELTS (init
); ++i
)
10243 if (!initializer_zerop (VECTOR_CST_ELT (init
, i
)))
10250 unsigned HOST_WIDE_INT idx
;
10252 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10253 if (!initializer_zerop (elt
))
10262 /* We need to loop through all elements to handle cases like
10263 "\0" and "\0foobar". */
10264 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
10265 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10276 /* Check if vector VEC consists of all the equal elements and
10277 that the number of elements corresponds to the type of VEC.
10278 The function returns first element of the vector
10279 or NULL_TREE if the vector is not uniform. */
10281 uniform_vector_p (const_tree vec
)
10286 if (vec
== NULL_TREE
)
10289 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10291 if (TREE_CODE (vec
) == VECTOR_CST
)
10293 first
= VECTOR_CST_ELT (vec
, 0);
10294 for (i
= 1; i
< VECTOR_CST_NELTS (vec
); ++i
)
10295 if (!operand_equal_p (first
, VECTOR_CST_ELT (vec
, i
), 0))
10301 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
10303 first
= error_mark_node
;
10305 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10312 if (!operand_equal_p (first
, t
, 0))
10315 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
10324 /* Build an empty statement at location LOC. */
10327 build_empty_stmt (location_t loc
)
10329 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10330 SET_EXPR_LOCATION (t
, loc
);
10335 /* Build an OpenMP clause with code CODE. LOC is the location of the
10339 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10344 length
= omp_clause_num_ops
[code
];
10345 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10347 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10349 t
= ggc_alloc_tree_node (size
);
10350 memset (t
, 0, size
);
10351 TREE_SET_CODE (t
, OMP_CLAUSE
);
10352 OMP_CLAUSE_SET_CODE (t
, code
);
10353 OMP_CLAUSE_LOCATION (t
) = loc
;
10358 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10359 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10360 Except for the CODE and operand count field, other storage for the
10361 object is initialized to zeros. */
10364 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
10367 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10369 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10370 gcc_assert (len
>= 1);
10372 record_node_allocation_statistics (code
, length
);
10374 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10376 TREE_SET_CODE (t
, code
);
10378 /* Can't use TREE_OPERAND to store the length because if checking is
10379 enabled, it will try to check the length before we store it. :-P */
10380 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10385 /* Helper function for build_call_* functions; build a CALL_EXPR with
10386 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10387 the argument slots. */
10390 build_call_1 (tree return_type
, tree fn
, int nargs
)
10394 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10395 TREE_TYPE (t
) = return_type
;
10396 CALL_EXPR_FN (t
) = fn
;
10397 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10402 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10403 FN and a null static chain slot. NARGS is the number of call arguments
10404 which are specified as "..." arguments. */
10407 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10411 va_start (args
, nargs
);
10412 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10417 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10418 FN and a null static chain slot. NARGS is the number of call arguments
10419 which are specified as a va_list ARGS. */
10422 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10427 t
= build_call_1 (return_type
, fn
, nargs
);
10428 for (i
= 0; i
< nargs
; i
++)
10429 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10430 process_call_operands (t
);
10434 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10435 FN and a null static chain slot. NARGS is the number of call arguments
10436 which are specified as a tree array ARGS. */
10439 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10440 int nargs
, const tree
*args
)
10445 t
= build_call_1 (return_type
, fn
, nargs
);
10446 for (i
= 0; i
< nargs
; i
++)
10447 CALL_EXPR_ARG (t
, i
) = args
[i
];
10448 process_call_operands (t
);
10449 SET_EXPR_LOCATION (t
, loc
);
10453 /* Like build_call_array, but takes a vec. */
10456 build_call_vec (tree return_type
, tree fn
, vec
<tree
, va_gc
> *args
)
10461 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10462 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10463 CALL_EXPR_ARG (ret
, ix
) = t
;
10464 process_call_operands (ret
);
10469 /* Returns true if it is possible to prove that the index of
10470 an array access REF (an ARRAY_REF expression) falls into the
10474 in_array_bounds_p (tree ref
)
10476 tree idx
= TREE_OPERAND (ref
, 1);
10479 if (TREE_CODE (idx
) != INTEGER_CST
)
10482 min
= array_ref_low_bound (ref
);
10483 max
= array_ref_up_bound (ref
);
10486 || TREE_CODE (min
) != INTEGER_CST
10487 || TREE_CODE (max
) != INTEGER_CST
)
10490 if (tree_int_cst_lt (idx
, min
)
10491 || tree_int_cst_lt (max
, idx
))
10497 /* Returns true if it is possible to prove that the range of
10498 an array access REF (an ARRAY_RANGE_REF expression) falls
10499 into the array bounds. */
10502 range_in_array_bounds_p (tree ref
)
10504 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
10505 tree range_min
, range_max
, min
, max
;
10507 range_min
= TYPE_MIN_VALUE (domain_type
);
10508 range_max
= TYPE_MAX_VALUE (domain_type
);
10511 || TREE_CODE (range_min
) != INTEGER_CST
10512 || TREE_CODE (range_max
) != INTEGER_CST
)
10515 min
= array_ref_low_bound (ref
);
10516 max
= array_ref_up_bound (ref
);
10519 || TREE_CODE (min
) != INTEGER_CST
10520 || TREE_CODE (max
) != INTEGER_CST
)
10523 if (tree_int_cst_lt (range_min
, min
)
10524 || tree_int_cst_lt (max
, range_max
))
10530 /* Return true if T (assumed to be a DECL) must be assigned a memory
10534 needs_to_live_in_memory (const_tree t
)
10536 return (TREE_ADDRESSABLE (t
)
10537 || is_global_var (t
)
10538 || (TREE_CODE (t
) == RESULT_DECL
10539 && !DECL_BY_REFERENCE (t
)
10540 && aggregate_value_p (t
, current_function_decl
)));
10543 /* Return value of a constant X and sign-extend it. */
10546 int_cst_value (const_tree x
)
10548 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10549 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
10551 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10552 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10553 || TREE_INT_CST_HIGH (x
) == -1);
10555 if (bits
< HOST_BITS_PER_WIDE_INT
)
10557 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10559 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
10561 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
10567 /* Return value of a constant X and sign-extend it. */
10570 widest_int_cst_value (const_tree x
)
10572 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10573 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
10575 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
10576 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= HOST_BITS_PER_DOUBLE_INT
);
10577 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
10578 << HOST_BITS_PER_WIDE_INT
);
10580 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10581 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10582 || TREE_INT_CST_HIGH (x
) == -1);
10585 if (bits
< HOST_BITS_PER_WIDEST_INT
)
10587 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10589 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
10591 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
10597 /* If TYPE is an integral or pointer type, return an integer type with
10598 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10599 if TYPE is already an integer type of signedness UNSIGNEDP. */
10602 signed_or_unsigned_type_for (int unsignedp
, tree type
)
10604 if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
) == unsignedp
)
10607 if (TREE_CODE (type
) == VECTOR_TYPE
)
10609 tree inner
= TREE_TYPE (type
);
10610 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
10613 if (inner
== inner2
)
10615 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
10618 if (!INTEGRAL_TYPE_P (type
)
10619 && !POINTER_TYPE_P (type
))
10622 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
10625 /* If TYPE is an integral or pointer type, return an integer type with
10626 the same precision which is unsigned, or itself if TYPE is already an
10627 unsigned integer type. */
10630 unsigned_type_for (tree type
)
10632 return signed_or_unsigned_type_for (1, type
);
10635 /* If TYPE is an integral or pointer type, return an integer type with
10636 the same precision which is signed, or itself if TYPE is already a
10637 signed integer type. */
10640 signed_type_for (tree type
)
10642 return signed_or_unsigned_type_for (0, type
);
10645 /* If TYPE is a vector type, return a signed integer vector type with the
10646 same width and number of subparts. Otherwise return boolean_type_node. */
10649 truth_type_for (tree type
)
10651 if (TREE_CODE (type
) == VECTOR_TYPE
)
10653 tree elem
= lang_hooks
.types
.type_for_size
10654 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type
))), 0);
10655 return build_opaque_vector_type (elem
, TYPE_VECTOR_SUBPARTS (type
));
10658 return boolean_type_node
;
10661 /* Returns the largest value obtainable by casting something in INNER type to
10665 upper_bound_in_type (tree outer
, tree inner
)
10668 unsigned int det
= 0;
10669 unsigned oprec
= TYPE_PRECISION (outer
);
10670 unsigned iprec
= TYPE_PRECISION (inner
);
10673 /* Compute a unique number for every combination. */
10674 det
|= (oprec
> iprec
) ? 4 : 0;
10675 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10676 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10678 /* Determine the exponent to use. */
10683 /* oprec <= iprec, outer: signed, inner: don't care. */
10688 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10692 /* oprec > iprec, outer: signed, inner: signed. */
10696 /* oprec > iprec, outer: signed, inner: unsigned. */
10700 /* oprec > iprec, outer: unsigned, inner: signed. */
10704 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10708 gcc_unreachable ();
10711 /* Compute 2^^prec - 1. */
10712 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10715 high
.low
= ((~(unsigned HOST_WIDE_INT
) 0)
10716 >> (HOST_BITS_PER_WIDE_INT
- prec
));
10720 high
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10721 >> (HOST_BITS_PER_DOUBLE_INT
- prec
));
10722 high
.low
= ~(unsigned HOST_WIDE_INT
) 0;
10725 return double_int_to_tree (outer
, high
);
10728 /* Returns the smallest value obtainable by casting something in INNER type to
10732 lower_bound_in_type (tree outer
, tree inner
)
10735 unsigned oprec
= TYPE_PRECISION (outer
);
10736 unsigned iprec
= TYPE_PRECISION (inner
);
10738 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10740 if (TYPE_UNSIGNED (outer
)
10741 /* If we are widening something of an unsigned type, OUTER type
10742 contains all values of INNER type. In particular, both INNER
10743 and OUTER types have zero in common. */
10744 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10745 low
.low
= low
.high
= 0;
10748 /* If we are widening a signed type to another signed type, we
10749 want to obtain -2^^(iprec-1). If we are keeping the
10750 precision or narrowing to a signed type, we want to obtain
10752 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10754 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10756 low
.high
= ~(unsigned HOST_WIDE_INT
) 0;
10757 low
.low
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
10761 low
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10762 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
10767 return double_int_to_tree (outer
, low
);
10770 /* Return nonzero if two operands that are suitable for PHI nodes are
10771 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10772 SSA_NAME or invariant. Note that this is strictly an optimization.
10773 That is, callers of this function can directly call operand_equal_p
10774 and get the same result, only slower. */
10777 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10781 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10783 return operand_equal_p (arg0
, arg1
, 0);
10786 /* Returns number of zeros at the end of binary representation of X.
10788 ??? Use ffs if available? */
10791 num_ending_zeros (const_tree x
)
10793 unsigned HOST_WIDE_INT fr
, nfr
;
10794 unsigned num
, abits
;
10795 tree type
= TREE_TYPE (x
);
10797 if (TREE_INT_CST_LOW (x
) == 0)
10799 num
= HOST_BITS_PER_WIDE_INT
;
10800 fr
= TREE_INT_CST_HIGH (x
);
10805 fr
= TREE_INT_CST_LOW (x
);
10808 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
10811 if (nfr
<< abits
== fr
)
10818 if (num
> TYPE_PRECISION (type
))
10819 num
= TYPE_PRECISION (type
);
10821 return build_int_cst_type (type
, num
);
10825 #define WALK_SUBTREE(NODE) \
10828 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10834 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10835 be walked whenever a type is seen in the tree. Rest of operands and return
10836 value are as for walk_tree. */
10839 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10840 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10842 tree result
= NULL_TREE
;
10844 switch (TREE_CODE (type
))
10847 case REFERENCE_TYPE
:
10848 /* We have to worry about mutually recursive pointers. These can't
10849 be written in C. They can in Ada. It's pathological, but
10850 there's an ACATS test (c38102a) that checks it. Deal with this
10851 by checking if we're pointing to another pointer, that one
10852 points to another pointer, that one does too, and we have no htab.
10853 If so, get a hash table. We check three levels deep to avoid
10854 the cost of the hash table if we don't need one. */
10855 if (POINTER_TYPE_P (TREE_TYPE (type
))
10856 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10857 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10860 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10868 /* ... fall through ... */
10871 WALK_SUBTREE (TREE_TYPE (type
));
10875 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10877 /* Fall through. */
10879 case FUNCTION_TYPE
:
10880 WALK_SUBTREE (TREE_TYPE (type
));
10884 /* We never want to walk into default arguments. */
10885 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
10886 WALK_SUBTREE (TREE_VALUE (arg
));
10891 /* Don't follow this nodes's type if a pointer for fear that
10892 we'll have infinite recursion. If we have a PSET, then we
10895 || (!POINTER_TYPE_P (TREE_TYPE (type
))
10896 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
10897 WALK_SUBTREE (TREE_TYPE (type
));
10898 WALK_SUBTREE (TYPE_DOMAIN (type
));
10902 WALK_SUBTREE (TREE_TYPE (type
));
10903 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
10913 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10914 called with the DATA and the address of each sub-tree. If FUNC returns a
10915 non-NULL value, the traversal is stopped, and the value returned by FUNC
10916 is returned. If PSET is non-NULL it is used to record the nodes visited,
10917 and to avoid visiting a node more than once. */
10920 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10921 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10923 enum tree_code code
;
10927 #define WALK_SUBTREE_TAIL(NODE) \
10931 goto tail_recurse; \
10936 /* Skip empty subtrees. */
10940 /* Don't walk the same tree twice, if the user has requested
10941 that we avoid doing so. */
10942 if (pset
&& pointer_set_insert (pset
, *tp
))
10945 /* Call the function. */
10947 result
= (*func
) (tp
, &walk_subtrees
, data
);
10949 /* If we found something, return it. */
10953 code
= TREE_CODE (*tp
);
10955 /* Even if we didn't, FUNC may have decided that there was nothing
10956 interesting below this point in the tree. */
10957 if (!walk_subtrees
)
10959 /* But we still need to check our siblings. */
10960 if (code
== TREE_LIST
)
10961 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10962 else if (code
== OMP_CLAUSE
)
10963 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10970 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
10971 if (result
|| !walk_subtrees
)
10978 case IDENTIFIER_NODE
:
10985 case PLACEHOLDER_EXPR
:
10989 /* None of these have subtrees other than those already walked
10994 WALK_SUBTREE (TREE_VALUE (*tp
));
10995 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11000 int len
= TREE_VEC_LENGTH (*tp
);
11005 /* Walk all elements but the first. */
11007 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
11009 /* Now walk the first one as a tail call. */
11010 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
11014 WALK_SUBTREE (TREE_REALPART (*tp
));
11015 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
11019 unsigned HOST_WIDE_INT idx
;
11020 constructor_elt
*ce
;
11022 for (idx
= 0; vec_safe_iterate(CONSTRUCTOR_ELTS (*tp
), idx
, &ce
); idx
++)
11023 WALK_SUBTREE (ce
->value
);
11028 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
11033 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
11035 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11036 into declarations that are just mentioned, rather than
11037 declared; they don't really belong to this part of the tree.
11038 And, we can see cycles: the initializer for a declaration
11039 can refer to the declaration itself. */
11040 WALK_SUBTREE (DECL_INITIAL (decl
));
11041 WALK_SUBTREE (DECL_SIZE (decl
));
11042 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
11044 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
11047 case STATEMENT_LIST
:
11049 tree_stmt_iterator i
;
11050 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
11051 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11056 switch (OMP_CLAUSE_CODE (*tp
))
11058 case OMP_CLAUSE_PRIVATE
:
11059 case OMP_CLAUSE_SHARED
:
11060 case OMP_CLAUSE_FIRSTPRIVATE
:
11061 case OMP_CLAUSE_COPYIN
:
11062 case OMP_CLAUSE_COPYPRIVATE
:
11063 case OMP_CLAUSE_FINAL
:
11064 case OMP_CLAUSE_IF
:
11065 case OMP_CLAUSE_NUM_THREADS
:
11066 case OMP_CLAUSE_SCHEDULE
:
11067 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
11070 case OMP_CLAUSE_NOWAIT
:
11071 case OMP_CLAUSE_ORDERED
:
11072 case OMP_CLAUSE_DEFAULT
:
11073 case OMP_CLAUSE_UNTIED
:
11074 case OMP_CLAUSE_MERGEABLE
:
11075 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11077 case OMP_CLAUSE_LASTPRIVATE
:
11078 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11079 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
11080 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11082 case OMP_CLAUSE_COLLAPSE
:
11085 for (i
= 0; i
< 3; i
++)
11086 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11087 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11090 case OMP_CLAUSE_REDUCTION
:
11093 for (i
= 0; i
< 4; i
++)
11094 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11095 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11099 gcc_unreachable ();
11107 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11108 But, we only want to walk once. */
11109 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11110 for (i
= 0; i
< len
; ++i
)
11111 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11112 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11116 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11117 defining. We only want to walk into these fields of a type in this
11118 case and not in the general case of a mere reference to the type.
11120 The criterion is as follows: if the field can be an expression, it
11121 must be walked only here. This should be in keeping with the fields
11122 that are directly gimplified in gimplify_type_sizes in order for the
11123 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11124 variable-sized types.
11126 Note that DECLs get walked as part of processing the BIND_EXPR. */
11127 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11129 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11130 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11133 /* Call the function for the type. See if it returns anything or
11134 doesn't want us to continue. If we are to continue, walk both
11135 the normal fields and those for the declaration case. */
11136 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11137 if (result
|| !walk_subtrees
)
11140 /* But do not walk a pointed-to type since it may itself need to
11141 be walked in the declaration case if it isn't anonymous. */
11142 if (!POINTER_TYPE_P (*type_p
))
11144 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11149 /* If this is a record type, also walk the fields. */
11150 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11154 for (field
= TYPE_FIELDS (*type_p
); field
;
11155 field
= DECL_CHAIN (field
))
11157 /* We'd like to look at the type of the field, but we can
11158 easily get infinite recursion. So assume it's pointed
11159 to elsewhere in the tree. Also, ignore things that
11161 if (TREE_CODE (field
) != FIELD_DECL
)
11164 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11165 WALK_SUBTREE (DECL_SIZE (field
));
11166 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11167 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11168 WALK_SUBTREE (DECL_QUALIFIER (field
));
11172 /* Same for scalar types. */
11173 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11174 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11175 || TREE_CODE (*type_p
) == INTEGER_TYPE
11176 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11177 || TREE_CODE (*type_p
) == REAL_TYPE
)
11179 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11180 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11183 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11184 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11189 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11193 /* Walk over all the sub-trees of this operand. */
11194 len
= TREE_OPERAND_LENGTH (*tp
);
11196 /* Go through the subtrees. We need to do this in forward order so
11197 that the scope of a FOR_EXPR is handled properly. */
11200 for (i
= 0; i
< len
- 1; ++i
)
11201 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11202 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11205 /* If this is a type, walk the needed fields in the type. */
11206 else if (TYPE_P (*tp
))
11207 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11211 /* We didn't find what we were looking for. */
11214 #undef WALK_SUBTREE_TAIL
11216 #undef WALK_SUBTREE
11218 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11221 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11225 struct pointer_set_t
*pset
;
11227 pset
= pointer_set_create ();
11228 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
11229 pointer_set_destroy (pset
);
11235 tree_block (tree t
)
11237 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11239 if (IS_EXPR_CODE_CLASS (c
))
11240 return LOCATION_BLOCK (t
->exp
.locus
);
11241 gcc_unreachable ();
11246 tree_set_block (tree t
, tree b
)
11248 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11250 if (IS_EXPR_CODE_CLASS (c
))
11253 t
->exp
.locus
= COMBINE_LOCATION_DATA (line_table
, t
->exp
.locus
, b
);
11255 t
->exp
.locus
= LOCATION_LOCUS (t
->exp
.locus
);
11258 gcc_unreachable ();
11261 /* Create a nameless artificial label and put it in the current
11262 function context. The label has a location of LOC. Returns the
11263 newly created label. */
11266 create_artificial_label (location_t loc
)
11268 tree lab
= build_decl (loc
,
11269 LABEL_DECL
, NULL_TREE
, void_type_node
);
11271 DECL_ARTIFICIAL (lab
) = 1;
11272 DECL_IGNORED_P (lab
) = 1;
11273 DECL_CONTEXT (lab
) = current_function_decl
;
11277 /* Given a tree, try to return a useful variable name that we can use
11278 to prefix a temporary that is being assigned the value of the tree.
11279 I.E. given <temp> = &A, return A. */
11284 tree stripped_decl
;
11287 STRIP_NOPS (stripped_decl
);
11288 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11289 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11290 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11292 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11295 return IDENTIFIER_POINTER (name
);
11299 switch (TREE_CODE (stripped_decl
))
11302 return get_name (TREE_OPERAND (stripped_decl
, 0));
11309 /* Return true if TYPE has a variable argument list. */
11312 stdarg_p (const_tree fntype
)
11314 function_args_iterator args_iter
;
11315 tree n
= NULL_TREE
, t
;
11320 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
11325 return n
!= NULL_TREE
&& n
!= void_type_node
;
11328 /* Return true if TYPE has a prototype. */
11331 prototype_p (tree fntype
)
11335 gcc_assert (fntype
!= NULL_TREE
);
11337 t
= TYPE_ARG_TYPES (fntype
);
11338 return (t
!= NULL_TREE
);
11341 /* If BLOCK is inlined from an __attribute__((__artificial__))
11342 routine, return pointer to location from where it has been
11345 block_nonartificial_location (tree block
)
11347 location_t
*ret
= NULL
;
11349 while (block
&& TREE_CODE (block
) == BLOCK
11350 && BLOCK_ABSTRACT_ORIGIN (block
))
11352 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11354 while (TREE_CODE (ao
) == BLOCK
11355 && BLOCK_ABSTRACT_ORIGIN (ao
)
11356 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
11357 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
11359 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11361 /* If AO is an artificial inline, point RET to the
11362 call site locus at which it has been inlined and continue
11363 the loop, in case AO's caller is also an artificial
11365 if (DECL_DECLARED_INLINE_P (ao
)
11366 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11367 ret
= &BLOCK_SOURCE_LOCATION (block
);
11371 else if (TREE_CODE (ao
) != BLOCK
)
11374 block
= BLOCK_SUPERCONTEXT (block
);
11380 /* If EXP is inlined from an __attribute__((__artificial__))
11381 function, return the location of the original call expression. */
11384 tree_nonartificial_location (tree exp
)
11386 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11391 return EXPR_LOCATION (exp
);
11395 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11398 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11401 cl_option_hash_hash (const void *x
)
11403 const_tree
const t
= (const_tree
) x
;
11407 hashval_t hash
= 0;
11409 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11411 p
= (const char *)TREE_OPTIMIZATION (t
);
11412 len
= sizeof (struct cl_optimization
);
11415 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11417 p
= (const char *)TREE_TARGET_OPTION (t
);
11418 len
= sizeof (struct cl_target_option
);
11422 gcc_unreachable ();
11424 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11426 for (i
= 0; i
< len
; i
++)
11428 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
11433 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11434 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11438 cl_option_hash_eq (const void *x
, const void *y
)
11440 const_tree
const xt
= (const_tree
) x
;
11441 const_tree
const yt
= (const_tree
) y
;
11446 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11449 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11451 xp
= (const char *)TREE_OPTIMIZATION (xt
);
11452 yp
= (const char *)TREE_OPTIMIZATION (yt
);
11453 len
= sizeof (struct cl_optimization
);
11456 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11458 xp
= (const char *)TREE_TARGET_OPTION (xt
);
11459 yp
= (const char *)TREE_TARGET_OPTION (yt
);
11460 len
= sizeof (struct cl_target_option
);
11464 gcc_unreachable ();
11466 return (memcmp (xp
, yp
, len
) == 0);
11469 /* Build an OPTIMIZATION_NODE based on the current options. */
11472 build_optimization_node (void)
11477 /* Use the cache of optimization nodes. */
11479 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
11482 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
11486 /* Insert this one into the hash table. */
11487 t
= cl_optimization_node
;
11490 /* Make a new node for next time round. */
11491 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
11497 /* Build a TARGET_OPTION_NODE based on the current options. */
11500 build_target_option_node (void)
11505 /* Use the cache of optimization nodes. */
11507 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
11510 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
11514 /* Insert this one into the hash table. */
11515 t
= cl_target_option_node
;
11518 /* Make a new node for next time round. */
11519 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
11525 /* Determine the "ultimate origin" of a block. The block may be an inlined
11526 instance of an inlined instance of a block which is local to an inline
11527 function, so we have to trace all of the way back through the origin chain
11528 to find out what sort of node actually served as the original seed for the
11532 block_ultimate_origin (const_tree block
)
11534 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
11536 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
11537 nodes in the function to point to themselves; ignore that if
11538 we're trying to output the abstract instance of this function. */
11539 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
11542 if (immediate_origin
== NULL_TREE
)
11547 tree lookahead
= immediate_origin
;
11551 ret_val
= lookahead
;
11552 lookahead
= (TREE_CODE (ret_val
) == BLOCK
11553 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
11555 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
11557 /* The block's abstract origin chain may not be the *ultimate* origin of
11558 the block. It could lead to a DECL that has an abstract origin set.
11559 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11560 will give us if it has one). Note that DECL's abstract origins are
11561 supposed to be the most distant ancestor (or so decl_ultimate_origin
11562 claims), so we don't need to loop following the DECL origins. */
11563 if (DECL_P (ret_val
))
11564 return DECL_ORIGIN (ret_val
);
11570 /* Return true if T1 and T2 are equivalent lists. */
11573 list_equal_p (const_tree t1
, const_tree t2
)
11575 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
11576 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
11581 /* Return true iff conversion in EXP generates no instruction. Mark
11582 it inline so that we fully inline into the stripping functions even
11583 though we have two uses of this function. */
11586 tree_nop_conversion (const_tree exp
)
11588 tree outer_type
, inner_type
;
11590 if (!CONVERT_EXPR_P (exp
)
11591 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
11593 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
11596 outer_type
= TREE_TYPE (exp
);
11597 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11602 /* Use precision rather then machine mode when we can, which gives
11603 the correct answer even for submode (bit-field) types. */
11604 if ((INTEGRAL_TYPE_P (outer_type
)
11605 || POINTER_TYPE_P (outer_type
)
11606 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
11607 && (INTEGRAL_TYPE_P (inner_type
)
11608 || POINTER_TYPE_P (inner_type
)
11609 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
11610 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
11612 /* Otherwise fall back on comparing machine modes (e.g. for
11613 aggregate types, floats). */
11614 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
11617 /* Return true iff conversion in EXP generates no instruction. Don't
11618 consider conversions changing the signedness. */
11621 tree_sign_nop_conversion (const_tree exp
)
11623 tree outer_type
, inner_type
;
11625 if (!tree_nop_conversion (exp
))
11628 outer_type
= TREE_TYPE (exp
);
11629 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11631 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
11632 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
11635 /* Strip conversions from EXP according to tree_nop_conversion and
11636 return the resulting expression. */
11639 tree_strip_nop_conversions (tree exp
)
11641 while (tree_nop_conversion (exp
))
11642 exp
= TREE_OPERAND (exp
, 0);
11646 /* Strip conversions from EXP according to tree_sign_nop_conversion
11647 and return the resulting expression. */
11650 tree_strip_sign_nop_conversions (tree exp
)
11652 while (tree_sign_nop_conversion (exp
))
11653 exp
= TREE_OPERAND (exp
, 0);
11657 /* Avoid any floating point extensions from EXP. */
11659 strip_float_extensions (tree exp
)
11661 tree sub
, expt
, subt
;
11663 /* For floating point constant look up the narrowest type that can hold
11664 it properly and handle it like (type)(narrowest_type)constant.
11665 This way we can optimize for instance a=a*2.0 where "a" is float
11666 but 2.0 is double constant. */
11667 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
11669 REAL_VALUE_TYPE orig
;
11672 orig
= TREE_REAL_CST (exp
);
11673 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
11674 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
11675 type
= float_type_node
;
11676 else if (TYPE_PRECISION (TREE_TYPE (exp
))
11677 > TYPE_PRECISION (double_type_node
)
11678 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
11679 type
= double_type_node
;
11681 return build_real (type
, real_value_truncate (TYPE_MODE (type
), orig
));
11684 if (!CONVERT_EXPR_P (exp
))
11687 sub
= TREE_OPERAND (exp
, 0);
11688 subt
= TREE_TYPE (sub
);
11689 expt
= TREE_TYPE (exp
);
11691 if (!FLOAT_TYPE_P (subt
))
11694 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
11697 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
11700 return strip_float_extensions (sub
);
11703 /* Strip out all handled components that produce invariant
11707 strip_invariant_refs (const_tree op
)
11709 while (handled_component_p (op
))
11711 switch (TREE_CODE (op
))
11714 case ARRAY_RANGE_REF
:
11715 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
11716 || TREE_OPERAND (op
, 2) != NULL_TREE
11717 || TREE_OPERAND (op
, 3) != NULL_TREE
)
11721 case COMPONENT_REF
:
11722 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
11728 op
= TREE_OPERAND (op
, 0);
11734 static GTY(()) tree gcc_eh_personality_decl
;
11736 /* Return the GCC personality function decl. */
11739 lhd_gcc_personality (void)
11741 if (!gcc_eh_personality_decl
)
11742 gcc_eh_personality_decl
= build_personality_function ("gcc");
11743 return gcc_eh_personality_decl
;
11746 /* For languages with One Definition Rule, work out if
11747 trees are actually the same even if the tree representation
11748 differs. This handles only decls appearing in TYPE_NAME
11749 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11750 RECORD_TYPE and IDENTIFIER_NODE. */
11753 same_for_odr (tree t1
, tree t2
)
11759 /* C and C++ FEs differ by using IDENTIFIER_NODE and TYPE_DECL. */
11760 if (TREE_CODE (t1
) == IDENTIFIER_NODE
11761 && TREE_CODE (t2
) == TYPE_DECL
11762 && DECL_FILE_SCOPE_P (t1
))
11764 t2
= DECL_NAME (t2
);
11765 gcc_assert (TREE_CODE (t2
) == IDENTIFIER_NODE
);
11767 if (TREE_CODE (t2
) == IDENTIFIER_NODE
11768 && TREE_CODE (t1
) == TYPE_DECL
11769 && DECL_FILE_SCOPE_P (t2
))
11771 t1
= DECL_NAME (t1
);
11772 gcc_assert (TREE_CODE (t1
) == IDENTIFIER_NODE
);
11774 if (TREE_CODE (t1
) != TREE_CODE (t2
))
11777 return types_same_for_odr (t1
, t2
);
11779 return decls_same_for_odr (t1
, t2
);
11783 /* For languages with One Definition Rule, work out if
11784 decls are actually the same even if the tree representation
11785 differs. This handles only decls appearing in TYPE_NAME
11786 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11787 RECORD_TYPE and IDENTIFIER_NODE. */
11790 decls_same_for_odr (tree decl1
, tree decl2
)
11792 if (decl1
&& TREE_CODE (decl1
) == TYPE_DECL
11793 && DECL_ORIGINAL_TYPE (decl1
))
11794 decl1
= DECL_ORIGINAL_TYPE (decl1
);
11795 if (decl2
&& TREE_CODE (decl2
) == TYPE_DECL
11796 && DECL_ORIGINAL_TYPE (decl2
))
11797 decl2
= DECL_ORIGINAL_TYPE (decl2
);
11798 if (decl1
== decl2
)
11800 if (!decl1
|| !decl2
)
11802 gcc_checking_assert (DECL_P (decl1
) && DECL_P (decl2
));
11803 if (TREE_CODE (decl1
) != TREE_CODE (decl2
))
11805 if (TREE_CODE (decl1
) == TRANSLATION_UNIT_DECL
)
11807 if (TREE_CODE (decl1
) != NAMESPACE_DECL
11808 && TREE_CODE (decl1
) != TYPE_DECL
)
11810 if (!DECL_NAME (decl1
))
11812 gcc_checking_assert (TREE_CODE (DECL_NAME (decl1
)) == IDENTIFIER_NODE
);
11813 gcc_checking_assert (!DECL_NAME (decl2
)
11814 || TREE_CODE (DECL_NAME (decl2
)) == IDENTIFIER_NODE
);
11815 if (DECL_NAME (decl1
) != DECL_NAME (decl2
))
11817 return same_for_odr (DECL_CONTEXT (decl1
),
11818 DECL_CONTEXT (decl2
));
11821 /* For languages with One Definition Rule, work out if
11822 types are same even if the tree representation differs.
11823 This is non-trivial for LTO where minnor differences in
11824 the type representation may have prevented type merging
11825 to merge two copies of otherwise equivalent type. */
11828 types_same_for_odr (tree type1
, tree type2
)
11830 gcc_checking_assert (TYPE_P (type1
) && TYPE_P (type2
));
11831 type1
= TYPE_MAIN_VARIANT (type1
);
11832 type2
= TYPE_MAIN_VARIANT (type2
);
11833 if (type1
== type2
)
11836 /* If types are not structuraly same, do not bother to contnue.
11837 Match in the remainder of code would mean ODR violation. */
11838 if (!types_compatible_p (type1
, type2
))
11841 #ifndef ENABLE_CHECKING
11846 /* Check for anonymous namespaces. Those have !TREE_PUBLIC
11847 on the corresponding TYPE_STUB_DECL. */
11848 if (TYPE_STUB_DECL (type1
) != TYPE_STUB_DECL (type2
)
11849 && (!TYPE_STUB_DECL (type1
)
11850 || !TYPE_STUB_DECL (type2
)
11851 || !TREE_PUBLIC (TYPE_STUB_DECL (type1
))
11852 || !TREE_PUBLIC (TYPE_STUB_DECL (type2
))))
11855 if (!TYPE_NAME (type1
))
11857 if (!decls_same_for_odr (TYPE_NAME (type1
), TYPE_NAME (type2
)))
11859 if (!same_for_odr (TYPE_CONTEXT (type1
), TYPE_CONTEXT (type2
)))
11861 /* When not in LTO the MAIN_VARIANT check should be the same. */
11862 gcc_assert (in_lto_p
);
11867 /* Try to find a base info of BINFO that would have its field decl at offset
11868 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
11869 found, return, otherwise return NULL_TREE. */
11872 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
11874 tree type
= BINFO_TYPE (binfo
);
11878 HOST_WIDE_INT pos
, size
;
11882 if (types_same_for_odr (type
, expected_type
))
11887 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
11889 if (TREE_CODE (fld
) != FIELD_DECL
)
11892 pos
= int_bit_position (fld
);
11893 size
= tree_low_cst (DECL_SIZE (fld
), 1);
11894 if (pos
<= offset
&& (pos
+ size
) > offset
)
11897 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
11900 if (!DECL_ARTIFICIAL (fld
))
11902 binfo
= TYPE_BINFO (TREE_TYPE (fld
));
11906 /* Offset 0 indicates the primary base, whose vtable contents are
11907 represented in the binfo for the derived class. */
11908 else if (offset
!= 0)
11910 tree base_binfo
, found_binfo
= NULL_TREE
;
11911 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11912 if (types_same_for_odr (TREE_TYPE (base_binfo
), TREE_TYPE (fld
)))
11914 found_binfo
= base_binfo
;
11919 binfo
= found_binfo
;
11922 type
= TREE_TYPE (fld
);
11927 /* Returns true if X is a typedef decl. */
11930 is_typedef_decl (tree x
)
11932 return (x
&& TREE_CODE (x
) == TYPE_DECL
11933 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
11936 /* Returns true iff TYPE is a type variant created for a typedef. */
11939 typedef_variant_p (tree type
)
11941 return is_typedef_decl (TYPE_NAME (type
));
11944 /* Warn about a use of an identifier which was marked deprecated. */
11946 warn_deprecated_use (tree node
, tree attr
)
11950 if (node
== 0 || !warn_deprecated_decl
)
11956 attr
= DECL_ATTRIBUTES (node
);
11957 else if (TYPE_P (node
))
11959 tree decl
= TYPE_STUB_DECL (node
);
11961 attr
= lookup_attribute ("deprecated",
11962 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
11967 attr
= lookup_attribute ("deprecated", attr
);
11970 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
11976 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
11978 warning (OPT_Wdeprecated_declarations
,
11979 "%qD is deprecated (declared at %r%s:%d%R): %s",
11980 node
, "locus", xloc
.file
, xloc
.line
, msg
);
11982 warning (OPT_Wdeprecated_declarations
,
11983 "%qD is deprecated (declared at %r%s:%d%R)",
11984 node
, "locus", xloc
.file
, xloc
.line
);
11986 else if (TYPE_P (node
))
11988 tree what
= NULL_TREE
;
11989 tree decl
= TYPE_STUB_DECL (node
);
11991 if (TYPE_NAME (node
))
11993 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
11994 what
= TYPE_NAME (node
);
11995 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
11996 && DECL_NAME (TYPE_NAME (node
)))
11997 what
= DECL_NAME (TYPE_NAME (node
));
12002 expanded_location xloc
12003 = expand_location (DECL_SOURCE_LOCATION (decl
));
12007 warning (OPT_Wdeprecated_declarations
,
12008 "%qE is deprecated (declared at %r%s:%d%R): %s",
12009 what
, "locus", xloc
.file
, xloc
.line
, msg
);
12011 warning (OPT_Wdeprecated_declarations
,
12012 "%qE is deprecated (declared at %r%s:%d%R)",
12013 what
, "locus", xloc
.file
, xloc
.line
);
12018 warning (OPT_Wdeprecated_declarations
,
12019 "type is deprecated (declared at %r%s:%d%R): %s",
12020 "locus", xloc
.file
, xloc
.line
, msg
);
12022 warning (OPT_Wdeprecated_declarations
,
12023 "type is deprecated (declared at %r%s:%d%R)",
12024 "locus", xloc
.file
, xloc
.line
);
12032 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
12035 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
12040 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
12043 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
12049 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12050 somewhere in it. */
12053 contains_bitfld_component_ref_p (const_tree ref
)
12055 while (handled_component_p (ref
))
12057 if (TREE_CODE (ref
) == COMPONENT_REF
12058 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
12060 ref
= TREE_OPERAND (ref
, 0);
12066 #include "gt-tree.h"