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"
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 static 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 2, /* OMP_CLAUSE_LINEAR */
240 2, /* OMP_CLAUSE_ALIGNED */
241 1, /* OMP_CLAUSE_DEPEND */
242 1, /* OMP_CLAUSE_UNIFORM */
243 2, /* OMP_CLAUSE_FROM */
244 2, /* OMP_CLAUSE_TO */
245 2, /* OMP_CLAUSE_MAP */
246 1, /* OMP_CLAUSE__LOOPTEMP_ */
247 1, /* OMP_CLAUSE_IF */
248 1, /* OMP_CLAUSE_NUM_THREADS */
249 1, /* OMP_CLAUSE_SCHEDULE */
250 0, /* OMP_CLAUSE_NOWAIT */
251 0, /* OMP_CLAUSE_ORDERED */
252 0, /* OMP_CLAUSE_DEFAULT */
253 3, /* OMP_CLAUSE_COLLAPSE */
254 0, /* OMP_CLAUSE_UNTIED */
255 1, /* OMP_CLAUSE_FINAL */
256 0, /* OMP_CLAUSE_MERGEABLE */
257 1, /* OMP_CLAUSE_DEVICE */
258 1, /* OMP_CLAUSE_DIST_SCHEDULE */
259 0, /* OMP_CLAUSE_INBRANCH */
260 0, /* OMP_CLAUSE_NOTINBRANCH */
261 1, /* OMP_CLAUSE_NUM_TEAMS */
262 1, /* OMP_CLAUSE_THREAD_LIMIT */
263 0, /* OMP_CLAUSE_PROC_BIND */
264 1, /* OMP_CLAUSE_SAFELEN */
265 1, /* OMP_CLAUSE_SIMDLEN */
266 0, /* OMP_CLAUSE_FOR */
267 0, /* OMP_CLAUSE_PARALLEL */
268 0, /* OMP_CLAUSE_SECTIONS */
269 0, /* OMP_CLAUSE_TASKGROUP */
270 1, /* OMP_CLAUSE__SIMDUID_ */
273 const char * const omp_clause_code_name
[] =
318 /* Return the tree node structure used by tree code CODE. */
320 static inline enum tree_node_structure_enum
321 tree_node_structure_for_code (enum tree_code code
)
323 switch (TREE_CODE_CLASS (code
))
325 case tcc_declaration
:
330 return TS_FIELD_DECL
;
336 return TS_LABEL_DECL
;
338 return TS_RESULT_DECL
;
339 case DEBUG_EXPR_DECL
:
342 return TS_CONST_DECL
;
346 return TS_FUNCTION_DECL
;
347 case TRANSLATION_UNIT_DECL
:
348 return TS_TRANSLATION_UNIT_DECL
;
350 return TS_DECL_NON_COMMON
;
354 return TS_TYPE_NON_COMMON
;
363 default: /* tcc_constant and tcc_exceptional */
368 /* tcc_constant cases. */
369 case INTEGER_CST
: return TS_INT_CST
;
370 case REAL_CST
: return TS_REAL_CST
;
371 case FIXED_CST
: return TS_FIXED_CST
;
372 case COMPLEX_CST
: return TS_COMPLEX
;
373 case VECTOR_CST
: return TS_VECTOR
;
374 case STRING_CST
: return TS_STRING
;
375 /* tcc_exceptional cases. */
376 case ERROR_MARK
: return TS_COMMON
;
377 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
378 case TREE_LIST
: return TS_LIST
;
379 case TREE_VEC
: return TS_VEC
;
380 case SSA_NAME
: return TS_SSA_NAME
;
381 case PLACEHOLDER_EXPR
: return TS_COMMON
;
382 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
383 case BLOCK
: return TS_BLOCK
;
384 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
385 case TREE_BINFO
: return TS_BINFO
;
386 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
387 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
388 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
396 /* Initialize tree_contains_struct to describe the hierarchy of tree
400 initialize_tree_contains_struct (void)
404 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
407 enum tree_node_structure_enum ts_code
;
409 code
= (enum tree_code
) i
;
410 ts_code
= tree_node_structure_for_code (code
);
412 /* Mark the TS structure itself. */
413 tree_contains_struct
[code
][ts_code
] = 1;
415 /* Mark all the structures that TS is derived from. */
433 case TS_STATEMENT_LIST
:
434 MARK_TS_TYPED (code
);
438 case TS_DECL_MINIMAL
:
444 case TS_OPTIMIZATION
:
445 case TS_TARGET_OPTION
:
446 MARK_TS_COMMON (code
);
449 case TS_TYPE_WITH_LANG_SPECIFIC
:
450 MARK_TS_TYPE_COMMON (code
);
453 case TS_TYPE_NON_COMMON
:
454 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
458 MARK_TS_DECL_MINIMAL (code
);
463 MARK_TS_DECL_COMMON (code
);
466 case TS_DECL_NON_COMMON
:
467 MARK_TS_DECL_WITH_VIS (code
);
470 case TS_DECL_WITH_VIS
:
474 MARK_TS_DECL_WRTL (code
);
478 MARK_TS_DECL_COMMON (code
);
482 MARK_TS_DECL_WITH_VIS (code
);
486 case TS_FUNCTION_DECL
:
487 MARK_TS_DECL_NON_COMMON (code
);
490 case TS_TRANSLATION_UNIT_DECL
:
491 MARK_TS_DECL_COMMON (code
);
499 /* Basic consistency checks for attributes used in fold. */
500 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
501 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
502 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
503 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
504 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
505 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
506 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
507 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
508 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
509 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
510 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
511 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
512 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
513 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
514 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
515 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
516 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
517 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
518 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
519 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
520 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
521 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
522 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
523 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
524 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
525 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
526 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
527 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
528 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
529 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
530 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
531 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
532 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
533 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
534 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
535 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
536 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
537 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
546 /* Initialize the hash table of types. */
547 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
550 debug_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
551 tree_decl_map_eq
, 0);
553 value_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
554 tree_decl_map_eq
, 0);
555 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
556 tree_priority_map_eq
, 0);
558 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
559 int_cst_hash_eq
, NULL
);
561 int_cst_node
= make_node (INTEGER_CST
);
563 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
564 cl_option_hash_eq
, NULL
);
566 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
567 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
569 /* Initialize the tree_contains_struct array. */
570 initialize_tree_contains_struct ();
571 lang_hooks
.init_ts ();
575 /* The name of the object as the assembler will see it (but before any
576 translations made by ASM_OUTPUT_LABELREF). Often this is the same
577 as DECL_NAME. It is an IDENTIFIER_NODE. */
579 decl_assembler_name (tree decl
)
581 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
582 lang_hooks
.set_decl_assembler_name (decl
);
583 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
586 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
589 decl_assembler_name_equal (tree decl
, const_tree asmname
)
591 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
592 const char *decl_str
;
593 const char *asmname_str
;
596 if (decl_asmname
== asmname
)
599 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
600 asmname_str
= IDENTIFIER_POINTER (asmname
);
603 /* If the target assembler name was set by the user, things are trickier.
604 We have a leading '*' to begin with. After that, it's arguable what
605 is the correct thing to do with -fleading-underscore. Arguably, we've
606 historically been doing the wrong thing in assemble_alias by always
607 printing the leading underscore. Since we're not changing that, make
608 sure user_label_prefix follows the '*' before matching. */
609 if (decl_str
[0] == '*')
611 size_t ulp_len
= strlen (user_label_prefix
);
617 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
618 decl_str
+= ulp_len
, test
=true;
622 if (asmname_str
[0] == '*')
624 size_t ulp_len
= strlen (user_label_prefix
);
630 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
631 asmname_str
+= ulp_len
, test
=true;
638 return strcmp (decl_str
, asmname_str
) == 0;
641 /* Hash asmnames ignoring the user specified marks. */
644 decl_assembler_name_hash (const_tree asmname
)
646 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
648 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
649 size_t ulp_len
= strlen (user_label_prefix
);
653 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
656 return htab_hash_string (decl_str
);
659 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
662 /* Compute the number of bytes occupied by a tree with code CODE.
663 This function cannot be used for nodes that have variable sizes,
664 including TREE_VEC, STRING_CST, and CALL_EXPR. */
666 tree_code_size (enum tree_code code
)
668 switch (TREE_CODE_CLASS (code
))
670 case tcc_declaration
: /* A decl node */
675 return sizeof (struct tree_field_decl
);
677 return sizeof (struct tree_parm_decl
);
679 return sizeof (struct tree_var_decl
);
681 return sizeof (struct tree_label_decl
);
683 return sizeof (struct tree_result_decl
);
685 return sizeof (struct tree_const_decl
);
687 return sizeof (struct tree_type_decl
);
689 return sizeof (struct tree_function_decl
);
690 case DEBUG_EXPR_DECL
:
691 return sizeof (struct tree_decl_with_rtl
);
693 return sizeof (struct tree_decl_non_common
);
697 case tcc_type
: /* a type node */
698 return sizeof (struct tree_type_non_common
);
700 case tcc_reference
: /* a reference */
701 case tcc_expression
: /* an expression */
702 case tcc_statement
: /* an expression with side effects */
703 case tcc_comparison
: /* a comparison expression */
704 case tcc_unary
: /* a unary arithmetic expression */
705 case tcc_binary
: /* a binary arithmetic expression */
706 return (sizeof (struct tree_exp
)
707 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
709 case tcc_constant
: /* a constant */
712 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
713 case REAL_CST
: return sizeof (struct tree_real_cst
);
714 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
715 case COMPLEX_CST
: return sizeof (struct tree_complex
);
716 case VECTOR_CST
: return sizeof (struct tree_vector
);
717 case STRING_CST
: gcc_unreachable ();
719 return lang_hooks
.tree_size (code
);
722 case tcc_exceptional
: /* something random, like an identifier. */
725 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
726 case TREE_LIST
: return sizeof (struct tree_list
);
729 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
732 case OMP_CLAUSE
: gcc_unreachable ();
734 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
736 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
737 case BLOCK
: return sizeof (struct tree_block
);
738 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
739 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
740 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
743 return lang_hooks
.tree_size (code
);
751 /* Compute the number of bytes occupied by NODE. This routine only
752 looks at TREE_CODE, except for those nodes that have variable sizes. */
754 tree_size (const_tree node
)
756 const enum tree_code code
= TREE_CODE (node
);
760 return (offsetof (struct tree_binfo
, base_binfos
)
762 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
765 return (sizeof (struct tree_vec
)
766 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
769 return (sizeof (struct tree_vector
)
770 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node
)) - 1) * sizeof (tree
));
773 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
776 return (sizeof (struct tree_omp_clause
)
777 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
781 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
782 return (sizeof (struct tree_exp
)
783 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
785 return tree_code_size (code
);
789 /* Record interesting allocation statistics for a tree node with CODE
793 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
794 size_t length ATTRIBUTE_UNUSED
)
796 enum tree_code_class type
= TREE_CODE_CLASS (code
);
799 if (!GATHER_STATISTICS
)
804 case tcc_declaration
: /* A decl node */
808 case tcc_type
: /* a type node */
812 case tcc_statement
: /* an expression with side effects */
816 case tcc_reference
: /* a reference */
820 case tcc_expression
: /* an expression */
821 case tcc_comparison
: /* a comparison expression */
822 case tcc_unary
: /* a unary arithmetic expression */
823 case tcc_binary
: /* a binary arithmetic expression */
827 case tcc_constant
: /* a constant */
831 case tcc_exceptional
: /* something random, like an identifier. */
834 case IDENTIFIER_NODE
:
847 kind
= ssa_name_kind
;
859 kind
= omp_clause_kind
;
876 tree_code_counts
[(int) code
]++;
877 tree_node_counts
[(int) kind
]++;
878 tree_node_sizes
[(int) kind
] += length
;
881 /* Allocate and return a new UID from the DECL_UID namespace. */
884 allocate_decl_uid (void)
886 return next_decl_uid
++;
889 /* Return a newly allocated node of code CODE. For decl and type
890 nodes, some other fields are initialized. The rest of the node is
891 initialized to zero. This function cannot be used for TREE_VEC or
892 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
894 Achoo! I got a code in the node. */
897 make_node_stat (enum tree_code code MEM_STAT_DECL
)
900 enum tree_code_class type
= TREE_CODE_CLASS (code
);
901 size_t length
= tree_code_size (code
);
903 record_node_allocation_statistics (code
, length
);
905 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
906 TREE_SET_CODE (t
, code
);
911 TREE_SIDE_EFFECTS (t
) = 1;
914 case tcc_declaration
:
915 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
917 if (code
== FUNCTION_DECL
)
919 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
920 DECL_MODE (t
) = FUNCTION_MODE
;
925 DECL_SOURCE_LOCATION (t
) = input_location
;
926 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
927 DECL_UID (t
) = --next_debug_decl_uid
;
930 DECL_UID (t
) = allocate_decl_uid ();
931 SET_DECL_PT_UID (t
, -1);
933 if (TREE_CODE (t
) == LABEL_DECL
)
934 LABEL_DECL_UID (t
) = -1;
939 TYPE_UID (t
) = next_type_uid
++;
940 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
941 TYPE_USER_ALIGN (t
) = 0;
942 TYPE_MAIN_VARIANT (t
) = t
;
943 TYPE_CANONICAL (t
) = t
;
945 /* Default to no attributes for type, but let target change that. */
946 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
947 targetm
.set_default_type_attributes (t
);
949 /* We have not yet computed the alias set for this type. */
950 TYPE_ALIAS_SET (t
) = -1;
954 TREE_CONSTANT (t
) = 1;
963 case PREDECREMENT_EXPR
:
964 case PREINCREMENT_EXPR
:
965 case POSTDECREMENT_EXPR
:
966 case POSTINCREMENT_EXPR
:
967 /* All of these have side-effects, no matter what their
969 TREE_SIDE_EFFECTS (t
) = 1;
978 /* Other classes need no special treatment. */
985 /* Return a new node with the same contents as NODE except that its
986 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
989 copy_node_stat (tree node MEM_STAT_DECL
)
992 enum tree_code code
= TREE_CODE (node
);
995 gcc_assert (code
!= STATEMENT_LIST
);
997 length
= tree_size (node
);
998 record_node_allocation_statistics (code
, length
);
999 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1000 memcpy (t
, node
, length
);
1002 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1004 TREE_ASM_WRITTEN (t
) = 0;
1005 TREE_VISITED (t
) = 0;
1007 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
1009 if (code
== DEBUG_EXPR_DECL
)
1010 DECL_UID (t
) = --next_debug_decl_uid
;
1013 DECL_UID (t
) = allocate_decl_uid ();
1014 if (DECL_PT_UID_SET_P (node
))
1015 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
1017 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
1018 && DECL_HAS_VALUE_EXPR_P (node
))
1020 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
1021 DECL_HAS_VALUE_EXPR_P (t
) = 1;
1023 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
1024 if (TREE_CODE (node
) == VAR_DECL
)
1025 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
1026 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
1028 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
1029 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
1031 if (TREE_CODE (node
) == FUNCTION_DECL
)
1032 DECL_STRUCT_FUNCTION (t
) = NULL
;
1034 else if (TREE_CODE_CLASS (code
) == tcc_type
)
1036 TYPE_UID (t
) = next_type_uid
++;
1037 /* The following is so that the debug code for
1038 the copy is different from the original type.
1039 The two statements usually duplicate each other
1040 (because they clear fields of the same union),
1041 but the optimizer should catch that. */
1042 TYPE_SYMTAB_POINTER (t
) = 0;
1043 TYPE_SYMTAB_ADDRESS (t
) = 0;
1045 /* Do not copy the values cache. */
1046 if (TYPE_CACHED_VALUES_P (t
))
1048 TYPE_CACHED_VALUES_P (t
) = 0;
1049 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1056 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1057 For example, this can copy a list made of TREE_LIST nodes. */
1060 copy_list (tree list
)
1068 head
= prev
= copy_node (list
);
1069 next
= TREE_CHAIN (list
);
1072 TREE_CHAIN (prev
) = copy_node (next
);
1073 prev
= TREE_CHAIN (prev
);
1074 next
= TREE_CHAIN (next
);
1080 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1083 build_int_cst (tree type
, HOST_WIDE_INT low
)
1085 /* Support legacy code. */
1087 type
= integer_type_node
;
1089 return double_int_to_tree (type
, double_int::from_shwi (low
));
1092 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1095 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1099 return double_int_to_tree (type
, double_int::from_shwi (low
));
1102 /* Constructs tree in type TYPE from with value given by CST. Signedness
1103 of CST is assumed to be the same as the signedness of TYPE. */
1106 double_int_to_tree (tree type
, double_int cst
)
1108 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1110 cst
= cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1112 return build_int_cst_wide (type
, cst
.low
, cst
.high
);
1115 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1116 to be the same as the signedness of TYPE. */
1119 double_int_fits_to_tree_p (const_tree type
, double_int cst
)
1121 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1124 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1129 /* We force the double_int CST to the range of the type TYPE by sign or
1130 zero extending it. OVERFLOWABLE indicates if we are interested in
1131 overflow of the value, when >0 we are only interested in signed
1132 overflow, for <0 we are interested in any overflow. OVERFLOWED
1133 indicates whether overflow has already occurred. CONST_OVERFLOWED
1134 indicates whether constant overflow has already occurred. We force
1135 T's value to be within range of T's type (by setting to 0 or 1 all
1136 the bits outside the type's range). We set TREE_OVERFLOWED if,
1137 OVERFLOWED is nonzero,
1138 or OVERFLOWABLE is >0 and signed overflow occurs
1139 or OVERFLOWABLE is <0 and any overflow occurs
1140 We return a new tree node for the extended double_int. The node
1141 is shared if no overflow flags are set. */
1145 force_fit_type_double (tree type
, double_int cst
, int overflowable
,
1148 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1150 /* If we need to set overflow flags, return a new unshared node. */
1151 if (overflowed
|| !double_int_fits_to_tree_p (type
, cst
))
1155 || (overflowable
> 0 && sign_extended_type
))
1157 tree t
= make_node (INTEGER_CST
);
1159 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1160 TREE_TYPE (t
) = type
;
1161 TREE_OVERFLOW (t
) = 1;
1166 /* Else build a shared node. */
1167 return double_int_to_tree (type
, cst
);
1170 /* These are the hash table functions for the hash table of INTEGER_CST
1171 nodes of a sizetype. */
1173 /* Return the hash code code X, an INTEGER_CST. */
1176 int_cst_hash_hash (const void *x
)
1178 const_tree
const t
= (const_tree
) x
;
1180 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
1181 ^ htab_hash_pointer (TREE_TYPE (t
)));
1184 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1185 is the same as that given by *Y, which is the same. */
1188 int_cst_hash_eq (const void *x
, const void *y
)
1190 const_tree
const xt
= (const_tree
) x
;
1191 const_tree
const yt
= (const_tree
) y
;
1193 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
1194 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
1195 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
1198 /* Create an INT_CST node of TYPE and value HI:LOW.
1199 The returned node is always shared. For small integers we use a
1200 per-type vector cache, for larger ones we use a single hash table. */
1203 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
1211 switch (TREE_CODE (type
))
1214 gcc_assert (hi
== 0 && low
== 0);
1218 case REFERENCE_TYPE
:
1219 /* Cache NULL pointer. */
1228 /* Cache false or true. */
1236 if (TYPE_UNSIGNED (type
))
1239 limit
= INTEGER_SHARE_LIMIT
;
1240 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1246 limit
= INTEGER_SHARE_LIMIT
+ 1;
1247 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1249 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1263 /* Look for it in the type's vector of small shared ints. */
1264 if (!TYPE_CACHED_VALUES_P (type
))
1266 TYPE_CACHED_VALUES_P (type
) = 1;
1267 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1270 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1273 /* Make sure no one is clobbering the shared constant. */
1274 gcc_assert (TREE_TYPE (t
) == type
);
1275 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
1276 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
1280 /* Create a new shared int. */
1281 t
= make_node (INTEGER_CST
);
1283 TREE_INT_CST_LOW (t
) = low
;
1284 TREE_INT_CST_HIGH (t
) = hi
;
1285 TREE_TYPE (t
) = type
;
1287 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1292 /* Use the cache of larger shared ints. */
1295 TREE_INT_CST_LOW (int_cst_node
) = low
;
1296 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
1297 TREE_TYPE (int_cst_node
) = type
;
1299 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1303 /* Insert this one into the hash table. */
1306 /* Make a new node for next time round. */
1307 int_cst_node
= make_node (INTEGER_CST
);
1315 cache_integer_cst (tree t
)
1317 tree type
= TREE_TYPE (t
);
1318 HOST_WIDE_INT hi
= TREE_INT_CST_HIGH (t
);
1319 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (t
);
1323 gcc_assert (!TREE_OVERFLOW (t
));
1325 switch (TREE_CODE (type
))
1328 gcc_assert (hi
== 0 && low
== 0);
1332 case REFERENCE_TYPE
:
1333 /* Cache NULL pointer. */
1342 /* Cache false or true. */
1350 if (TYPE_UNSIGNED (type
))
1353 limit
= INTEGER_SHARE_LIMIT
;
1354 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1360 limit
= INTEGER_SHARE_LIMIT
+ 1;
1361 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1363 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1377 /* Look for it in the type's vector of small shared ints. */
1378 if (!TYPE_CACHED_VALUES_P (type
))
1380 TYPE_CACHED_VALUES_P (type
) = 1;
1381 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1384 gcc_assert (TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) == NULL_TREE
);
1385 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1389 /* Use the cache of larger shared ints. */
1392 slot
= htab_find_slot (int_cst_hash_table
, t
, INSERT
);
1393 /* If there is already an entry for the number verify it's the
1397 gcc_assert (TREE_INT_CST_LOW ((tree
)*slot
) == low
1398 && TREE_INT_CST_HIGH ((tree
)*slot
) == hi
);
1401 /* Otherwise insert this one into the hash table. */
1407 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1408 and the rest are zeros. */
1411 build_low_bits_mask (tree type
, unsigned bits
)
1415 gcc_assert (bits
<= TYPE_PRECISION (type
));
1417 if (bits
== TYPE_PRECISION (type
)
1418 && !TYPE_UNSIGNED (type
))
1419 /* Sign extended all-ones mask. */
1420 mask
= double_int_minus_one
;
1422 mask
= double_int::mask (bits
);
1424 return build_int_cst_wide (type
, mask
.low
, mask
.high
);
1427 /* Checks that X is integer constant that can be expressed in (unsigned)
1428 HOST_WIDE_INT without loss of precision. */
1431 cst_and_fits_in_hwi (const_tree x
)
1433 if (TREE_CODE (x
) != INTEGER_CST
)
1436 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1439 return (TREE_INT_CST_HIGH (x
) == 0
1440 || TREE_INT_CST_HIGH (x
) == -1);
1443 /* Build a newly constructed TREE_VEC node of length LEN. */
1446 make_vector_stat (unsigned len MEM_STAT_DECL
)
1449 unsigned length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vector
);
1451 record_node_allocation_statistics (VECTOR_CST
, length
);
1453 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1455 TREE_SET_CODE (t
, VECTOR_CST
);
1456 TREE_CONSTANT (t
) = 1;
1461 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1462 are in a list pointed to by VALS. */
1465 build_vector_stat (tree type
, tree
*vals MEM_STAT_DECL
)
1469 tree v
= make_vector (TYPE_VECTOR_SUBPARTS (type
));
1470 TREE_TYPE (v
) = type
;
1472 /* Iterate through elements and check for overflow. */
1473 for (cnt
= 0; cnt
< TYPE_VECTOR_SUBPARTS (type
); ++cnt
)
1475 tree value
= vals
[cnt
];
1477 VECTOR_CST_ELT (v
, cnt
) = value
;
1479 /* Don't crash if we get an address constant. */
1480 if (!CONSTANT_CLASS_P (value
))
1483 over
|= TREE_OVERFLOW (value
);
1486 TREE_OVERFLOW (v
) = over
;
1490 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1491 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1494 build_vector_from_ctor (tree type
, vec
<constructor_elt
, va_gc
> *v
)
1496 tree
*vec
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (type
));
1497 unsigned HOST_WIDE_INT idx
;
1500 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1502 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1503 vec
[idx
] = build_zero_cst (TREE_TYPE (type
));
1505 return build_vector (type
, vec
);
1508 /* Build a vector of type VECTYPE where all the elements are SCs. */
1510 build_vector_from_val (tree vectype
, tree sc
)
1512 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1514 if (sc
== error_mark_node
)
1517 /* Verify that the vector type is suitable for SC. Note that there
1518 is some inconsistency in the type-system with respect to restrict
1519 qualifications of pointers. Vector types always have a main-variant
1520 element type and the qualification is applied to the vector-type.
1521 So TREE_TYPE (vector-type) does not return a properly qualified
1522 vector element-type. */
1523 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1524 TREE_TYPE (vectype
)));
1526 if (CONSTANT_CLASS_P (sc
))
1528 tree
*v
= XALLOCAVEC (tree
, nunits
);
1529 for (i
= 0; i
< nunits
; ++i
)
1531 return build_vector (vectype
, v
);
1535 vec
<constructor_elt
, va_gc
> *v
;
1536 vec_alloc (v
, nunits
);
1537 for (i
= 0; i
< nunits
; ++i
)
1538 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1539 return build_constructor (vectype
, v
);
1543 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1544 are in the vec pointed to by VALS. */
1546 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals
)
1548 tree c
= make_node (CONSTRUCTOR
);
1550 constructor_elt
*elt
;
1551 bool constant_p
= true;
1552 bool side_effects_p
= false;
1554 TREE_TYPE (c
) = type
;
1555 CONSTRUCTOR_ELTS (c
) = vals
;
1557 FOR_EACH_VEC_SAFE_ELT (vals
, i
, elt
)
1559 /* Mostly ctors will have elts that don't have side-effects, so
1560 the usual case is to scan all the elements. Hence a single
1561 loop for both const and side effects, rather than one loop
1562 each (with early outs). */
1563 if (!TREE_CONSTANT (elt
->value
))
1565 if (TREE_SIDE_EFFECTS (elt
->value
))
1566 side_effects_p
= true;
1569 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
1570 TREE_CONSTANT (c
) = constant_p
;
1575 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1578 build_constructor_single (tree type
, tree index
, tree value
)
1580 vec
<constructor_elt
, va_gc
> *v
;
1581 constructor_elt elt
= {index
, value
};
1584 v
->quick_push (elt
);
1586 return build_constructor (type
, v
);
1590 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1591 are in a list pointed to by VALS. */
1593 build_constructor_from_list (tree type
, tree vals
)
1596 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1600 vec_alloc (v
, list_length (vals
));
1601 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1602 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1605 return build_constructor (type
, v
);
1608 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1609 of elements, provided as index/value pairs. */
1612 build_constructor_va (tree type
, int nelts
, ...)
1614 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1617 va_start (p
, nelts
);
1618 vec_alloc (v
, nelts
);
1621 tree index
= va_arg (p
, tree
);
1622 tree value
= va_arg (p
, tree
);
1623 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
1626 return build_constructor (type
, v
);
1629 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1632 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1635 FIXED_VALUE_TYPE
*fp
;
1637 v
= make_node (FIXED_CST
);
1638 fp
= ggc_alloc_fixed_value ();
1639 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1641 TREE_TYPE (v
) = type
;
1642 TREE_FIXED_CST_PTR (v
) = fp
;
1646 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1649 build_real (tree type
, REAL_VALUE_TYPE d
)
1652 REAL_VALUE_TYPE
*dp
;
1655 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1656 Consider doing it via real_convert now. */
1658 v
= make_node (REAL_CST
);
1659 dp
= ggc_alloc_real_value ();
1660 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1662 TREE_TYPE (v
) = type
;
1663 TREE_REAL_CST_PTR (v
) = dp
;
1664 TREE_OVERFLOW (v
) = overflow
;
1668 /* Return a new REAL_CST node whose type is TYPE
1669 and whose value is the integer value of the INTEGER_CST node I. */
1672 real_value_from_int_cst (const_tree type
, const_tree i
)
1676 /* Clear all bits of the real value type so that we can later do
1677 bitwise comparisons to see if two values are the same. */
1678 memset (&d
, 0, sizeof d
);
1680 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1681 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1682 TYPE_UNSIGNED (TREE_TYPE (i
)));
1686 /* Given a tree representing an integer constant I, return a tree
1687 representing the same value as a floating-point constant of type TYPE. */
1690 build_real_from_int_cst (tree type
, const_tree i
)
1693 int overflow
= TREE_OVERFLOW (i
);
1695 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1697 TREE_OVERFLOW (v
) |= overflow
;
1701 /* Return a newly constructed STRING_CST node whose value is
1702 the LEN characters at STR.
1703 Note that for a C string literal, LEN should include the trailing NUL.
1704 The TREE_TYPE is not initialized. */
1707 build_string (int len
, const char *str
)
1712 /* Do not waste bytes provided by padding of struct tree_string. */
1713 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1715 record_node_allocation_statistics (STRING_CST
, length
);
1717 s
= ggc_alloc_tree_node (length
);
1719 memset (s
, 0, sizeof (struct tree_typed
));
1720 TREE_SET_CODE (s
, STRING_CST
);
1721 TREE_CONSTANT (s
) = 1;
1722 TREE_STRING_LENGTH (s
) = len
;
1723 memcpy (s
->string
.str
, str
, len
);
1724 s
->string
.str
[len
] = '\0';
1729 /* Return a newly constructed COMPLEX_CST node whose value is
1730 specified by the real and imaginary parts REAL and IMAG.
1731 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1732 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1735 build_complex (tree type
, tree real
, tree imag
)
1737 tree t
= make_node (COMPLEX_CST
);
1739 TREE_REALPART (t
) = real
;
1740 TREE_IMAGPART (t
) = imag
;
1741 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1742 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1746 /* Return a constant of arithmetic type TYPE which is the
1747 multiplicative identity of the set TYPE. */
1750 build_one_cst (tree type
)
1752 switch (TREE_CODE (type
))
1754 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1755 case POINTER_TYPE
: case REFERENCE_TYPE
:
1757 return build_int_cst (type
, 1);
1760 return build_real (type
, dconst1
);
1762 case FIXED_POINT_TYPE
:
1763 /* We can only generate 1 for accum types. */
1764 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1765 return build_fixed (type
, FCONST1 (TYPE_MODE (type
)));
1769 tree scalar
= build_one_cst (TREE_TYPE (type
));
1771 return build_vector_from_val (type
, scalar
);
1775 return build_complex (type
,
1776 build_one_cst (TREE_TYPE (type
)),
1777 build_zero_cst (TREE_TYPE (type
)));
1784 /* Return an integer of type TYPE containing all 1's in as much precision as
1785 it contains, or a complex or vector whose subparts are such integers. */
1788 build_all_ones_cst (tree type
)
1790 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1792 tree scalar
= build_all_ones_cst (TREE_TYPE (type
));
1793 return build_complex (type
, scalar
, scalar
);
1796 return build_minus_one_cst (type
);
1799 /* Return a constant of arithmetic type TYPE which is the
1800 opposite of the multiplicative identity of the set TYPE. */
1803 build_minus_one_cst (tree type
)
1805 switch (TREE_CODE (type
))
1807 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1808 case POINTER_TYPE
: case REFERENCE_TYPE
:
1810 return build_int_cst (type
, -1);
1813 return build_real (type
, dconstm1
);
1815 case FIXED_POINT_TYPE
:
1816 /* We can only generate 1 for accum types. */
1817 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1818 return build_fixed (type
, fixed_from_double_int (double_int_minus_one
,
1823 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
1825 return build_vector_from_val (type
, scalar
);
1829 return build_complex (type
,
1830 build_minus_one_cst (TREE_TYPE (type
)),
1831 build_zero_cst (TREE_TYPE (type
)));
1838 /* Build 0 constant of type TYPE. This is used by constructor folding
1839 and thus the constant should be represented in memory by
1843 build_zero_cst (tree type
)
1845 switch (TREE_CODE (type
))
1847 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1848 case POINTER_TYPE
: case REFERENCE_TYPE
:
1849 case OFFSET_TYPE
: case NULLPTR_TYPE
:
1850 return build_int_cst (type
, 0);
1853 return build_real (type
, dconst0
);
1855 case FIXED_POINT_TYPE
:
1856 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
1860 tree scalar
= build_zero_cst (TREE_TYPE (type
));
1862 return build_vector_from_val (type
, scalar
);
1867 tree zero
= build_zero_cst (TREE_TYPE (type
));
1869 return build_complex (type
, zero
, zero
);
1873 if (!AGGREGATE_TYPE_P (type
))
1874 return fold_convert (type
, integer_zero_node
);
1875 return build_constructor (type
, NULL
);
1880 /* Build a BINFO with LEN language slots. */
1883 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1886 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1887 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
1889 record_node_allocation_statistics (TREE_BINFO
, length
);
1891 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1893 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1895 TREE_SET_CODE (t
, TREE_BINFO
);
1897 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
1902 /* Create a CASE_LABEL_EXPR tree node and return it. */
1905 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
1907 tree t
= make_node (CASE_LABEL_EXPR
);
1909 TREE_TYPE (t
) = void_type_node
;
1910 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
1912 CASE_LOW (t
) = low_value
;
1913 CASE_HIGH (t
) = high_value
;
1914 CASE_LABEL (t
) = label_decl
;
1915 CASE_CHAIN (t
) = NULL_TREE
;
1920 /* Build a newly constructed TREE_VEC node of length LEN. */
1923 make_tree_vec_stat (int len MEM_STAT_DECL
)
1926 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1928 record_node_allocation_statistics (TREE_VEC
, length
);
1930 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1932 TREE_SET_CODE (t
, TREE_VEC
);
1933 TREE_VEC_LENGTH (t
) = len
;
1938 /* Return 1 if EXPR is the integer constant zero or a complex constant
1942 integer_zerop (const_tree expr
)
1946 switch (TREE_CODE (expr
))
1949 return (TREE_INT_CST_LOW (expr
) == 0
1950 && TREE_INT_CST_HIGH (expr
) == 0);
1952 return (integer_zerop (TREE_REALPART (expr
))
1953 && integer_zerop (TREE_IMAGPART (expr
)));
1957 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1958 if (!integer_zerop (VECTOR_CST_ELT (expr
, i
)))
1967 /* Return 1 if EXPR is the integer constant one or the corresponding
1968 complex constant. */
1971 integer_onep (const_tree expr
)
1975 switch (TREE_CODE (expr
))
1978 return (TREE_INT_CST_LOW (expr
) == 1
1979 && TREE_INT_CST_HIGH (expr
) == 0);
1981 return (integer_onep (TREE_REALPART (expr
))
1982 && integer_zerop (TREE_IMAGPART (expr
)));
1986 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1987 if (!integer_onep (VECTOR_CST_ELT (expr
, i
)))
1996 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1997 it contains, or a complex or vector whose subparts are such integers. */
2000 integer_all_onesp (const_tree expr
)
2007 if (TREE_CODE (expr
) == COMPLEX_CST
2008 && integer_all_onesp (TREE_REALPART (expr
))
2009 && integer_all_onesp (TREE_IMAGPART (expr
)))
2012 else if (TREE_CODE (expr
) == VECTOR_CST
)
2015 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2016 if (!integer_all_onesp (VECTOR_CST_ELT (expr
, i
)))
2021 else if (TREE_CODE (expr
) != INTEGER_CST
)
2024 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
2025 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
2026 && TREE_INT_CST_HIGH (expr
) == -1)
2031 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2032 if (prec
>= HOST_BITS_PER_WIDE_INT
)
2034 HOST_WIDE_INT high_value
;
2037 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
2039 /* Can not handle precisions greater than twice the host int size. */
2040 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
2041 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
2042 /* Shifting by the host word size is undefined according to the ANSI
2043 standard, so we must handle this as a special case. */
2046 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
2048 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
2049 && TREE_INT_CST_HIGH (expr
) == high_value
);
2052 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
2055 /* Return 1 if EXPR is the integer constant minus one. */
2058 integer_minus_onep (const_tree expr
)
2062 if (TREE_CODE (expr
) == COMPLEX_CST
)
2063 return (integer_all_onesp (TREE_REALPART (expr
))
2064 && integer_zerop (TREE_IMAGPART (expr
)));
2066 return integer_all_onesp (expr
);
2069 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2073 integer_pow2p (const_tree expr
)
2076 unsigned HOST_WIDE_INT high
, low
;
2080 if (TREE_CODE (expr
) == COMPLEX_CST
2081 && integer_pow2p (TREE_REALPART (expr
))
2082 && integer_zerop (TREE_IMAGPART (expr
)))
2085 if (TREE_CODE (expr
) != INTEGER_CST
)
2088 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2089 high
= TREE_INT_CST_HIGH (expr
);
2090 low
= TREE_INT_CST_LOW (expr
);
2092 /* First clear all bits that are beyond the type's precision in case
2093 we've been sign extended. */
2095 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
2097 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2098 high
&= ~(HOST_WIDE_INT_M1U
<< (prec
- HOST_BITS_PER_WIDE_INT
));
2102 if (prec
< HOST_BITS_PER_WIDE_INT
)
2103 low
&= ~(HOST_WIDE_INT_M1U
<< prec
);
2106 if (high
== 0 && low
== 0)
2109 return ((high
== 0 && (low
& (low
- 1)) == 0)
2110 || (low
== 0 && (high
& (high
- 1)) == 0));
2113 /* Return 1 if EXPR is an integer constant other than zero or a
2114 complex constant other than zero. */
2117 integer_nonzerop (const_tree expr
)
2121 return ((TREE_CODE (expr
) == INTEGER_CST
2122 && (TREE_INT_CST_LOW (expr
) != 0
2123 || TREE_INT_CST_HIGH (expr
) != 0))
2124 || (TREE_CODE (expr
) == COMPLEX_CST
2125 && (integer_nonzerop (TREE_REALPART (expr
))
2126 || integer_nonzerop (TREE_IMAGPART (expr
)))));
2129 /* Return 1 if EXPR is the fixed-point constant zero. */
2132 fixed_zerop (const_tree expr
)
2134 return (TREE_CODE (expr
) == FIXED_CST
2135 && TREE_FIXED_CST (expr
).data
.is_zero ());
2138 /* Return the power of two represented by a tree node known to be a
2142 tree_log2 (const_tree expr
)
2145 HOST_WIDE_INT high
, low
;
2149 if (TREE_CODE (expr
) == COMPLEX_CST
)
2150 return tree_log2 (TREE_REALPART (expr
));
2152 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2153 high
= TREE_INT_CST_HIGH (expr
);
2154 low
= TREE_INT_CST_LOW (expr
);
2156 /* First clear all bits that are beyond the type's precision in case
2157 we've been sign extended. */
2159 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
2161 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2162 high
&= ~(HOST_WIDE_INT_M1U
<< (prec
- HOST_BITS_PER_WIDE_INT
));
2166 if (prec
< HOST_BITS_PER_WIDE_INT
)
2167 low
&= ~(HOST_WIDE_INT_M1U
<< prec
);
2170 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
2171 : exact_log2 (low
));
2174 /* Similar, but return the largest integer Y such that 2 ** Y is less
2175 than or equal to EXPR. */
2178 tree_floor_log2 (const_tree expr
)
2181 HOST_WIDE_INT high
, low
;
2185 if (TREE_CODE (expr
) == COMPLEX_CST
)
2186 return tree_log2 (TREE_REALPART (expr
));
2188 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2189 high
= TREE_INT_CST_HIGH (expr
);
2190 low
= TREE_INT_CST_LOW (expr
);
2192 /* First clear all bits that are beyond the type's precision in case
2193 we've been sign extended. Ignore if type's precision hasn't been set
2194 since what we are doing is setting it. */
2196 if (prec
== HOST_BITS_PER_DOUBLE_INT
|| prec
== 0)
2198 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2199 high
&= ~(HOST_WIDE_INT_M1U
<< (prec
- HOST_BITS_PER_WIDE_INT
));
2203 if (prec
< HOST_BITS_PER_WIDE_INT
)
2204 low
&= ~(HOST_WIDE_INT_M1U
<< prec
);
2207 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
2208 : floor_log2 (low
));
2211 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2212 decimal float constants, so don't return 1 for them. */
2215 real_zerop (const_tree expr
)
2219 switch (TREE_CODE (expr
))
2222 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
2223 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2225 return real_zerop (TREE_REALPART (expr
))
2226 && real_zerop (TREE_IMAGPART (expr
));
2230 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2231 if (!real_zerop (VECTOR_CST_ELT (expr
, i
)))
2240 /* Return 1 if EXPR is the real constant one in real or complex form.
2241 Trailing zeroes matter for decimal float constants, so don't return
2245 real_onep (const_tree expr
)
2249 switch (TREE_CODE (expr
))
2252 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
2253 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2255 return real_onep (TREE_REALPART (expr
))
2256 && real_zerop (TREE_IMAGPART (expr
));
2260 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2261 if (!real_onep (VECTOR_CST_ELT (expr
, i
)))
2270 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
2271 for decimal float constants, so don't return 1 for them. */
2274 real_twop (const_tree expr
)
2278 switch (TREE_CODE (expr
))
2281 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
)
2282 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2284 return real_twop (TREE_REALPART (expr
))
2285 && real_zerop (TREE_IMAGPART (expr
));
2289 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2290 if (!real_twop (VECTOR_CST_ELT (expr
, i
)))
2299 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2300 matter for decimal float constants, so don't return 1 for them. */
2303 real_minus_onep (const_tree expr
)
2307 switch (TREE_CODE (expr
))
2310 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
2311 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2313 return real_minus_onep (TREE_REALPART (expr
))
2314 && real_zerop (TREE_IMAGPART (expr
));
2318 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2319 if (!real_minus_onep (VECTOR_CST_ELT (expr
, i
)))
2328 /* Nonzero if EXP is a constant or a cast of a constant. */
2331 really_constant_p (const_tree exp
)
2333 /* This is not quite the same as STRIP_NOPS. It does more. */
2334 while (CONVERT_EXPR_P (exp
)
2335 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2336 exp
= TREE_OPERAND (exp
, 0);
2337 return TREE_CONSTANT (exp
);
2340 /* Return first list element whose TREE_VALUE is ELEM.
2341 Return 0 if ELEM is not in LIST. */
2344 value_member (tree elem
, tree list
)
2348 if (elem
== TREE_VALUE (list
))
2350 list
= TREE_CHAIN (list
);
2355 /* Return first list element whose TREE_PURPOSE is ELEM.
2356 Return 0 if ELEM is not in LIST. */
2359 purpose_member (const_tree elem
, tree list
)
2363 if (elem
== TREE_PURPOSE (list
))
2365 list
= TREE_CHAIN (list
);
2370 /* Return true if ELEM is in V. */
2373 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
2377 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
2383 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2387 chain_index (int idx
, tree chain
)
2389 for (; chain
&& idx
> 0; --idx
)
2390 chain
= TREE_CHAIN (chain
);
2394 /* Return nonzero if ELEM is part of the chain CHAIN. */
2397 chain_member (const_tree elem
, const_tree chain
)
2403 chain
= DECL_CHAIN (chain
);
2409 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2410 We expect a null pointer to mark the end of the chain.
2411 This is the Lisp primitive `length'. */
2414 list_length (const_tree t
)
2417 #ifdef ENABLE_TREE_CHECKING
2425 #ifdef ENABLE_TREE_CHECKING
2428 gcc_assert (p
!= q
);
2436 /* Returns the number of FIELD_DECLs in TYPE. */
2439 fields_length (const_tree type
)
2441 tree t
= TYPE_FIELDS (type
);
2444 for (; t
; t
= DECL_CHAIN (t
))
2445 if (TREE_CODE (t
) == FIELD_DECL
)
2451 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2452 UNION_TYPE TYPE, or NULL_TREE if none. */
2455 first_field (const_tree type
)
2457 tree t
= TYPE_FIELDS (type
);
2458 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2463 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2464 by modifying the last node in chain 1 to point to chain 2.
2465 This is the Lisp primitive `nconc'. */
2468 chainon (tree op1
, tree op2
)
2477 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2479 TREE_CHAIN (t1
) = op2
;
2481 #ifdef ENABLE_TREE_CHECKING
2484 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2485 gcc_assert (t2
!= t1
);
2492 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2495 tree_last (tree chain
)
2499 while ((next
= TREE_CHAIN (chain
)))
2504 /* Reverse the order of elements in the chain T,
2505 and return the new head of the chain (old last element). */
2510 tree prev
= 0, decl
, next
;
2511 for (decl
= t
; decl
; decl
= next
)
2513 /* We shouldn't be using this function to reverse BLOCK chains; we
2514 have blocks_nreverse for that. */
2515 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2516 next
= TREE_CHAIN (decl
);
2517 TREE_CHAIN (decl
) = prev
;
2523 /* Return a newly created TREE_LIST node whose
2524 purpose and value fields are PARM and VALUE. */
2527 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2529 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2530 TREE_PURPOSE (t
) = parm
;
2531 TREE_VALUE (t
) = value
;
2535 /* Build a chain of TREE_LIST nodes from a vector. */
2538 build_tree_list_vec_stat (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
2540 tree ret
= NULL_TREE
;
2544 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
2546 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2547 pp
= &TREE_CHAIN (*pp
);
2552 /* Return a newly created TREE_LIST node whose
2553 purpose and value fields are PURPOSE and VALUE
2554 and whose TREE_CHAIN is CHAIN. */
2557 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2561 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
2562 memset (node
, 0, sizeof (struct tree_common
));
2564 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2566 TREE_SET_CODE (node
, TREE_LIST
);
2567 TREE_CHAIN (node
) = chain
;
2568 TREE_PURPOSE (node
) = purpose
;
2569 TREE_VALUE (node
) = value
;
2573 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2577 ctor_to_vec (tree ctor
)
2579 vec
<tree
, va_gc
> *vec
;
2580 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
2584 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2585 vec
->quick_push (val
);
2590 /* Return the size nominally occupied by an object of type TYPE
2591 when it resides in memory. The value is measured in units of bytes,
2592 and its data type is that normally used for type sizes
2593 (which is the first type created by make_signed_type or
2594 make_unsigned_type). */
2597 size_in_bytes (const_tree type
)
2601 if (type
== error_mark_node
)
2602 return integer_zero_node
;
2604 type
= TYPE_MAIN_VARIANT (type
);
2605 t
= TYPE_SIZE_UNIT (type
);
2609 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2610 return size_zero_node
;
2616 /* Return the size of TYPE (in bytes) as a wide integer
2617 or return -1 if the size can vary or is larger than an integer. */
2620 int_size_in_bytes (const_tree type
)
2624 if (type
== error_mark_node
)
2627 type
= TYPE_MAIN_VARIANT (type
);
2628 t
= TYPE_SIZE_UNIT (type
);
2630 || TREE_CODE (t
) != INTEGER_CST
2631 || TREE_INT_CST_HIGH (t
) != 0
2632 /* If the result would appear negative, it's too big to represent. */
2633 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
2636 return TREE_INT_CST_LOW (t
);
2639 /* Return the maximum size of TYPE (in bytes) as a wide integer
2640 or return -1 if the size can vary or is larger than an integer. */
2643 max_int_size_in_bytes (const_tree type
)
2645 HOST_WIDE_INT size
= -1;
2648 /* If this is an array type, check for a possible MAX_SIZE attached. */
2650 if (TREE_CODE (type
) == ARRAY_TYPE
)
2652 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2654 if (size_tree
&& host_integerp (size_tree
, 1))
2655 size
= tree_low_cst (size_tree
, 1);
2658 /* If we still haven't been able to get a size, see if the language
2659 can compute a maximum size. */
2663 size_tree
= lang_hooks
.types
.max_size (type
);
2665 if (size_tree
&& host_integerp (size_tree
, 1))
2666 size
= tree_low_cst (size_tree
, 1);
2672 /* Returns a tree for the size of EXP in bytes. */
2675 tree_expr_size (const_tree exp
)
2678 && DECL_SIZE_UNIT (exp
) != 0)
2679 return DECL_SIZE_UNIT (exp
);
2681 return size_in_bytes (TREE_TYPE (exp
));
2684 /* Return the bit position of FIELD, in bits from the start of the record.
2685 This is a tree of type bitsizetype. */
2688 bit_position (const_tree field
)
2690 return bit_from_pos (DECL_FIELD_OFFSET (field
),
2691 DECL_FIELD_BIT_OFFSET (field
));
2694 /* Likewise, but return as an integer. It must be representable in
2695 that way (since it could be a signed value, we don't have the
2696 option of returning -1 like int_size_in_byte can. */
2699 int_bit_position (const_tree field
)
2701 return tree_low_cst (bit_position (field
), 0);
2704 /* Return the byte position of FIELD, in bytes from the start of the record.
2705 This is a tree of type sizetype. */
2708 byte_position (const_tree field
)
2710 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2711 DECL_FIELD_BIT_OFFSET (field
));
2714 /* Likewise, but return as an integer. It must be representable in
2715 that way (since it could be a signed value, we don't have the
2716 option of returning -1 like int_size_in_byte can. */
2719 int_byte_position (const_tree field
)
2721 return tree_low_cst (byte_position (field
), 0);
2724 /* Return the strictest alignment, in bits, that T is known to have. */
2727 expr_align (const_tree t
)
2729 unsigned int align0
, align1
;
2731 switch (TREE_CODE (t
))
2733 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2734 /* If we have conversions, we know that the alignment of the
2735 object must meet each of the alignments of the types. */
2736 align0
= expr_align (TREE_OPERAND (t
, 0));
2737 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2738 return MAX (align0
, align1
);
2740 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2741 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2742 case CLEANUP_POINT_EXPR
:
2743 /* These don't change the alignment of an object. */
2744 return expr_align (TREE_OPERAND (t
, 0));
2747 /* The best we can do is say that the alignment is the least aligned
2749 align0
= expr_align (TREE_OPERAND (t
, 1));
2750 align1
= expr_align (TREE_OPERAND (t
, 2));
2751 return MIN (align0
, align1
);
2753 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2754 meaningfully, it's always 1. */
2755 case LABEL_DECL
: case CONST_DECL
:
2756 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2758 gcc_assert (DECL_ALIGN (t
) != 0);
2759 return DECL_ALIGN (t
);
2765 /* Otherwise take the alignment from that of the type. */
2766 return TYPE_ALIGN (TREE_TYPE (t
));
2769 /* Return, as a tree node, the number of elements for TYPE (which is an
2770 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2773 array_type_nelts (const_tree type
)
2775 tree index_type
, min
, max
;
2777 /* If they did it with unspecified bounds, then we should have already
2778 given an error about it before we got here. */
2779 if (! TYPE_DOMAIN (type
))
2780 return error_mark_node
;
2782 index_type
= TYPE_DOMAIN (type
);
2783 min
= TYPE_MIN_VALUE (index_type
);
2784 max
= TYPE_MAX_VALUE (index_type
);
2786 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
2788 return error_mark_node
;
2790 return (integer_zerop (min
)
2792 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2795 /* If arg is static -- a reference to an object in static storage -- then
2796 return the object. This is not the same as the C meaning of `static'.
2797 If arg isn't static, return NULL. */
2802 switch (TREE_CODE (arg
))
2805 /* Nested functions are static, even though taking their address will
2806 involve a trampoline as we unnest the nested function and create
2807 the trampoline on the tree level. */
2811 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2812 && ! DECL_THREAD_LOCAL_P (arg
)
2813 && ! DECL_DLLIMPORT_P (arg
)
2817 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2821 return TREE_STATIC (arg
) ? arg
: NULL
;
2828 /* If the thing being referenced is not a field, then it is
2829 something language specific. */
2830 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
2832 /* If we are referencing a bitfield, we can't evaluate an
2833 ADDR_EXPR at compile time and so it isn't a constant. */
2834 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2837 return staticp (TREE_OPERAND (arg
, 0));
2843 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2846 case ARRAY_RANGE_REF
:
2847 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2848 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2849 return staticp (TREE_OPERAND (arg
, 0));
2853 case COMPOUND_LITERAL_EXPR
:
2854 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
2864 /* Return whether OP is a DECL whose address is function-invariant. */
2867 decl_address_invariant_p (const_tree op
)
2869 /* The conditions below are slightly less strict than the one in
2872 switch (TREE_CODE (op
))
2881 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2882 || DECL_THREAD_LOCAL_P (op
)
2883 || DECL_CONTEXT (op
) == current_function_decl
2884 || decl_function_context (op
) == current_function_decl
)
2889 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2890 || decl_function_context (op
) == current_function_decl
)
2901 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2904 decl_address_ip_invariant_p (const_tree op
)
2906 /* The conditions below are slightly less strict than the one in
2909 switch (TREE_CODE (op
))
2917 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2918 && !DECL_DLLIMPORT_P (op
))
2919 || DECL_THREAD_LOCAL_P (op
))
2924 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2936 /* Return true if T is function-invariant (internal function, does
2937 not handle arithmetic; that's handled in skip_simple_arithmetic and
2938 tree_invariant_p). */
2940 static bool tree_invariant_p (tree t
);
2943 tree_invariant_p_1 (tree t
)
2947 if (TREE_CONSTANT (t
)
2948 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2951 switch (TREE_CODE (t
))
2957 op
= TREE_OPERAND (t
, 0);
2958 while (handled_component_p (op
))
2960 switch (TREE_CODE (op
))
2963 case ARRAY_RANGE_REF
:
2964 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2965 || TREE_OPERAND (op
, 2) != NULL_TREE
2966 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2971 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2977 op
= TREE_OPERAND (op
, 0);
2980 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2989 /* Return true if T is function-invariant. */
2992 tree_invariant_p (tree t
)
2994 tree inner
= skip_simple_arithmetic (t
);
2995 return tree_invariant_p_1 (inner
);
2998 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2999 Do this to any expression which may be used in more than one place,
3000 but must be evaluated only once.
3002 Normally, expand_expr would reevaluate the expression each time.
3003 Calling save_expr produces something that is evaluated and recorded
3004 the first time expand_expr is called on it. Subsequent calls to
3005 expand_expr just reuse the recorded value.
3007 The call to expand_expr that generates code that actually computes
3008 the value is the first call *at compile time*. Subsequent calls
3009 *at compile time* generate code to use the saved value.
3010 This produces correct result provided that *at run time* control
3011 always flows through the insns made by the first expand_expr
3012 before reaching the other places where the save_expr was evaluated.
3013 You, the caller of save_expr, must make sure this is so.
3015 Constants, and certain read-only nodes, are returned with no
3016 SAVE_EXPR because that is safe. Expressions containing placeholders
3017 are not touched; see tree.def for an explanation of what these
3021 save_expr (tree expr
)
3023 tree t
= fold (expr
);
3026 /* If the tree evaluates to a constant, then we don't want to hide that
3027 fact (i.e. this allows further folding, and direct checks for constants).
3028 However, a read-only object that has side effects cannot be bypassed.
3029 Since it is no problem to reevaluate literals, we just return the
3031 inner
= skip_simple_arithmetic (t
);
3032 if (TREE_CODE (inner
) == ERROR_MARK
)
3035 if (tree_invariant_p_1 (inner
))
3038 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
3039 it means that the size or offset of some field of an object depends on
3040 the value within another field.
3042 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
3043 and some variable since it would then need to be both evaluated once and
3044 evaluated more than once. Front-ends must assure this case cannot
3045 happen by surrounding any such subexpressions in their own SAVE_EXPR
3046 and forcing evaluation at the proper time. */
3047 if (contains_placeholder_p (inner
))
3050 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
3051 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
3053 /* This expression might be placed ahead of a jump to ensure that the
3054 value was computed on both sides of the jump. So make sure it isn't
3055 eliminated as dead. */
3056 TREE_SIDE_EFFECTS (t
) = 1;
3060 /* Look inside EXPR into any simple arithmetic operations. Return the
3061 outermost non-arithmetic or non-invariant node. */
3064 skip_simple_arithmetic (tree expr
)
3066 /* We don't care about whether this can be used as an lvalue in this
3068 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3069 expr
= TREE_OPERAND (expr
, 0);
3071 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3072 a constant, it will be more efficient to not make another SAVE_EXPR since
3073 it will allow better simplification and GCSE will be able to merge the
3074 computations if they actually occur. */
3077 if (UNARY_CLASS_P (expr
))
3078 expr
= TREE_OPERAND (expr
, 0);
3079 else if (BINARY_CLASS_P (expr
))
3081 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
3082 expr
= TREE_OPERAND (expr
, 0);
3083 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
3084 expr
= TREE_OPERAND (expr
, 1);
3095 /* Look inside EXPR into simple arithmetic operations involving constants.
3096 Return the outermost non-arithmetic or non-constant node. */
3099 skip_simple_constant_arithmetic (tree expr
)
3101 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
3102 expr
= TREE_OPERAND (expr
, 0);
3106 if (UNARY_CLASS_P (expr
))
3107 expr
= TREE_OPERAND (expr
, 0);
3108 else if (BINARY_CLASS_P (expr
))
3110 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
3111 expr
= TREE_OPERAND (expr
, 0);
3112 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3113 expr
= TREE_OPERAND (expr
, 1);
3124 /* Return which tree structure is used by T. */
3126 enum tree_node_structure_enum
3127 tree_node_structure (const_tree t
)
3129 const enum tree_code code
= TREE_CODE (t
);
3130 return tree_node_structure_for_code (code
);
3133 /* Set various status flags when building a CALL_EXPR object T. */
3136 process_call_operands (tree t
)
3138 bool side_effects
= TREE_SIDE_EFFECTS (t
);
3139 bool read_only
= false;
3140 int i
= call_expr_flags (t
);
3142 /* Calls have side-effects, except those to const or pure functions. */
3143 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
3144 side_effects
= true;
3145 /* Propagate TREE_READONLY of arguments for const functions. */
3149 if (!side_effects
|| read_only
)
3150 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3152 tree op
= TREE_OPERAND (t
, i
);
3153 if (op
&& TREE_SIDE_EFFECTS (op
))
3154 side_effects
= true;
3155 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3159 TREE_SIDE_EFFECTS (t
) = side_effects
;
3160 TREE_READONLY (t
) = read_only
;
3163 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3164 size or offset that depends on a field within a record. */
3167 contains_placeholder_p (const_tree exp
)
3169 enum tree_code code
;
3174 code
= TREE_CODE (exp
);
3175 if (code
== PLACEHOLDER_EXPR
)
3178 switch (TREE_CODE_CLASS (code
))
3181 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3182 position computations since they will be converted into a
3183 WITH_RECORD_EXPR involving the reference, which will assume
3184 here will be valid. */
3185 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3187 case tcc_exceptional
:
3188 if (code
== TREE_LIST
)
3189 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3190 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3195 case tcc_comparison
:
3196 case tcc_expression
:
3200 /* Ignoring the first operand isn't quite right, but works best. */
3201 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
3204 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3205 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
3206 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
3209 /* The save_expr function never wraps anything containing
3210 a PLACEHOLDER_EXPR. */
3217 switch (TREE_CODE_LENGTH (code
))
3220 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3222 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3223 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
3234 const_call_expr_arg_iterator iter
;
3235 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
3236 if (CONTAINS_PLACEHOLDER_P (arg
))
3250 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3251 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3255 type_contains_placeholder_1 (const_tree type
)
3257 /* If the size contains a placeholder or the parent type (component type in
3258 the case of arrays) type involves a placeholder, this type does. */
3259 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
3260 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
3261 || (!POINTER_TYPE_P (type
)
3263 && type_contains_placeholder_p (TREE_TYPE (type
))))
3266 /* Now do type-specific checks. Note that the last part of the check above
3267 greatly limits what we have to do below. */
3268 switch (TREE_CODE (type
))
3276 case REFERENCE_TYPE
:
3285 case FIXED_POINT_TYPE
:
3286 /* Here we just check the bounds. */
3287 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
3288 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
3291 /* We have already checked the component type above, so just check the
3293 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
3297 case QUAL_UNION_TYPE
:
3301 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
3302 if (TREE_CODE (field
) == FIELD_DECL
3303 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
3304 || (TREE_CODE (type
) == QUAL_UNION_TYPE
3305 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
3306 || type_contains_placeholder_p (TREE_TYPE (field
))))
3317 /* Wrapper around above function used to cache its result. */
3320 type_contains_placeholder_p (tree type
)
3324 /* If the contains_placeholder_bits field has been initialized,
3325 then we know the answer. */
3326 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
3327 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
3329 /* Indicate that we've seen this type node, and the answer is false.
3330 This is what we want to return if we run into recursion via fields. */
3331 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
3333 /* Compute the real value. */
3334 result
= type_contains_placeholder_1 (type
);
3336 /* Store the real value. */
3337 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
3342 /* Push tree EXP onto vector QUEUE if it is not already present. */
3345 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
3350 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
3351 if (simple_cst_equal (iter
, exp
) == 1)
3355 queue
->safe_push (exp
);
3358 /* Given a tree EXP, find all occurrences of references to fields
3359 in a PLACEHOLDER_EXPR and place them in vector REFS without
3360 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3361 we assume here that EXP contains only arithmetic expressions
3362 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3366 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
3368 enum tree_code code
= TREE_CODE (exp
);
3372 /* We handle TREE_LIST and COMPONENT_REF separately. */
3373 if (code
== TREE_LIST
)
3375 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3376 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3378 else if (code
== COMPONENT_REF
)
3380 for (inner
= TREE_OPERAND (exp
, 0);
3381 REFERENCE_CLASS_P (inner
);
3382 inner
= TREE_OPERAND (inner
, 0))
3385 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3386 push_without_duplicates (exp
, refs
);
3388 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3391 switch (TREE_CODE_CLASS (code
))
3396 case tcc_declaration
:
3397 /* Variables allocated to static storage can stay. */
3398 if (!TREE_STATIC (exp
))
3399 push_without_duplicates (exp
, refs
);
3402 case tcc_expression
:
3403 /* This is the pattern built in ada/make_aligning_type. */
3404 if (code
== ADDR_EXPR
3405 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3407 push_without_duplicates (exp
, refs
);
3411 /* Fall through... */
3413 case tcc_exceptional
:
3416 case tcc_comparison
:
3418 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3419 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3423 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3424 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3432 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3433 return a tree with all occurrences of references to F in a
3434 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3435 CONST_DECLs. Note that we assume here that EXP contains only
3436 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3437 occurring only in their argument list. */
3440 substitute_in_expr (tree exp
, tree f
, tree r
)
3442 enum tree_code code
= TREE_CODE (exp
);
3443 tree op0
, op1
, op2
, op3
;
3446 /* We handle TREE_LIST and COMPONENT_REF separately. */
3447 if (code
== TREE_LIST
)
3449 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3450 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3451 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3454 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3456 else if (code
== COMPONENT_REF
)
3460 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3461 and it is the right field, replace it with R. */
3462 for (inner
= TREE_OPERAND (exp
, 0);
3463 REFERENCE_CLASS_P (inner
);
3464 inner
= TREE_OPERAND (inner
, 0))
3468 op1
= TREE_OPERAND (exp
, 1);
3470 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3473 /* If this expression hasn't been completed let, leave it alone. */
3474 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3477 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3478 if (op0
== TREE_OPERAND (exp
, 0))
3482 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3485 switch (TREE_CODE_CLASS (code
))
3490 case tcc_declaration
:
3496 case tcc_expression
:
3500 /* Fall through... */
3502 case tcc_exceptional
:
3505 case tcc_comparison
:
3507 switch (TREE_CODE_LENGTH (code
))
3513 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3514 if (op0
== TREE_OPERAND (exp
, 0))
3517 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3521 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3522 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3524 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3527 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3531 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3532 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3533 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3535 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3536 && op2
== TREE_OPERAND (exp
, 2))
3539 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3543 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3544 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3545 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3546 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3548 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3549 && op2
== TREE_OPERAND (exp
, 2)
3550 && op3
== TREE_OPERAND (exp
, 3))
3554 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3566 new_tree
= NULL_TREE
;
3568 /* If we are trying to replace F with a constant, inline back
3569 functions which do nothing else than computing a value from
3570 the arguments they are passed. This makes it possible to
3571 fold partially or entirely the replacement expression. */
3572 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3574 tree t
= maybe_inline_call_in_expr (exp
);
3576 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3579 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3581 tree op
= TREE_OPERAND (exp
, i
);
3582 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3586 new_tree
= copy_node (exp
);
3587 TREE_OPERAND (new_tree
, i
) = new_op
;
3593 new_tree
= fold (new_tree
);
3594 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3595 process_call_operands (new_tree
);
3606 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3608 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3609 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3614 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3615 for it within OBJ, a tree that is an object or a chain of references. */
3618 substitute_placeholder_in_expr (tree exp
, tree obj
)
3620 enum tree_code code
= TREE_CODE (exp
);
3621 tree op0
, op1
, op2
, op3
;
3624 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3625 in the chain of OBJ. */
3626 if (code
== PLACEHOLDER_EXPR
)
3628 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3631 for (elt
= obj
; elt
!= 0;
3632 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3633 || TREE_CODE (elt
) == COND_EXPR
)
3634 ? TREE_OPERAND (elt
, 1)
3635 : (REFERENCE_CLASS_P (elt
)
3636 || UNARY_CLASS_P (elt
)
3637 || BINARY_CLASS_P (elt
)
3638 || VL_EXP_CLASS_P (elt
)
3639 || EXPRESSION_CLASS_P (elt
))
3640 ? TREE_OPERAND (elt
, 0) : 0))
3641 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3644 for (elt
= obj
; elt
!= 0;
3645 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3646 || TREE_CODE (elt
) == COND_EXPR
)
3647 ? TREE_OPERAND (elt
, 1)
3648 : (REFERENCE_CLASS_P (elt
)
3649 || UNARY_CLASS_P (elt
)
3650 || BINARY_CLASS_P (elt
)
3651 || VL_EXP_CLASS_P (elt
)
3652 || EXPRESSION_CLASS_P (elt
))
3653 ? TREE_OPERAND (elt
, 0) : 0))
3654 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3655 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3657 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3659 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3660 survives until RTL generation, there will be an error. */
3664 /* TREE_LIST is special because we need to look at TREE_VALUE
3665 and TREE_CHAIN, not TREE_OPERANDS. */
3666 else if (code
== TREE_LIST
)
3668 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3669 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3670 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3673 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3676 switch (TREE_CODE_CLASS (code
))
3679 case tcc_declaration
:
3682 case tcc_exceptional
:
3685 case tcc_comparison
:
3686 case tcc_expression
:
3689 switch (TREE_CODE_LENGTH (code
))
3695 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3696 if (op0
== TREE_OPERAND (exp
, 0))
3699 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3703 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3704 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3706 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3709 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3713 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3714 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3715 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3717 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3718 && op2
== TREE_OPERAND (exp
, 2))
3721 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3725 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3726 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3727 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3728 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3730 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3731 && op2
== TREE_OPERAND (exp
, 2)
3732 && op3
== TREE_OPERAND (exp
, 3))
3736 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3748 new_tree
= NULL_TREE
;
3750 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3752 tree op
= TREE_OPERAND (exp
, i
);
3753 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
3757 new_tree
= copy_node (exp
);
3758 TREE_OPERAND (new_tree
, i
) = new_op
;
3764 new_tree
= fold (new_tree
);
3765 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3766 process_call_operands (new_tree
);
3777 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3779 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3780 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3785 /* Stabilize a reference so that we can use it any number of times
3786 without causing its operands to be evaluated more than once.
3787 Returns the stabilized reference. This works by means of save_expr,
3788 so see the caveats in the comments about save_expr.
3790 Also allows conversion expressions whose operands are references.
3791 Any other kind of expression is returned unchanged. */
3794 stabilize_reference (tree ref
)
3797 enum tree_code code
= TREE_CODE (ref
);
3804 /* No action is needed in this case. */
3809 case FIX_TRUNC_EXPR
:
3810 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
3814 result
= build_nt (INDIRECT_REF
,
3815 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
3819 result
= build_nt (COMPONENT_REF
,
3820 stabilize_reference (TREE_OPERAND (ref
, 0)),
3821 TREE_OPERAND (ref
, 1), NULL_TREE
);
3825 result
= build_nt (BIT_FIELD_REF
,
3826 stabilize_reference (TREE_OPERAND (ref
, 0)),
3827 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
3831 result
= build_nt (ARRAY_REF
,
3832 stabilize_reference (TREE_OPERAND (ref
, 0)),
3833 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3834 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3837 case ARRAY_RANGE_REF
:
3838 result
= build_nt (ARRAY_RANGE_REF
,
3839 stabilize_reference (TREE_OPERAND (ref
, 0)),
3840 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3841 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3845 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3846 it wouldn't be ignored. This matters when dealing with
3848 return stabilize_reference_1 (ref
);
3850 /* If arg isn't a kind of lvalue we recognize, make no change.
3851 Caller should recognize the error for an invalid lvalue. */
3856 return error_mark_node
;
3859 TREE_TYPE (result
) = TREE_TYPE (ref
);
3860 TREE_READONLY (result
) = TREE_READONLY (ref
);
3861 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3862 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3867 /* Subroutine of stabilize_reference; this is called for subtrees of
3868 references. Any expression with side-effects must be put in a SAVE_EXPR
3869 to ensure that it is only evaluated once.
3871 We don't put SAVE_EXPR nodes around everything, because assigning very
3872 simple expressions to temporaries causes us to miss good opportunities
3873 for optimizations. Among other things, the opportunity to fold in the
3874 addition of a constant into an addressing mode often gets lost, e.g.
3875 "y[i+1] += x;". In general, we take the approach that we should not make
3876 an assignment unless we are forced into it - i.e., that any non-side effect
3877 operator should be allowed, and that cse should take care of coalescing
3878 multiple utterances of the same expression should that prove fruitful. */
3881 stabilize_reference_1 (tree e
)
3884 enum tree_code code
= TREE_CODE (e
);
3886 /* We cannot ignore const expressions because it might be a reference
3887 to a const array but whose index contains side-effects. But we can
3888 ignore things that are actual constant or that already have been
3889 handled by this function. */
3891 if (tree_invariant_p (e
))
3894 switch (TREE_CODE_CLASS (code
))
3896 case tcc_exceptional
:
3898 case tcc_declaration
:
3899 case tcc_comparison
:
3901 case tcc_expression
:
3904 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3905 so that it will only be evaluated once. */
3906 /* The reference (r) and comparison (<) classes could be handled as
3907 below, but it is generally faster to only evaluate them once. */
3908 if (TREE_SIDE_EFFECTS (e
))
3909 return save_expr (e
);
3913 /* Constants need no processing. In fact, we should never reach
3918 /* Division is slow and tends to be compiled with jumps,
3919 especially the division by powers of 2 that is often
3920 found inside of an array reference. So do it just once. */
3921 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3922 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3923 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3924 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3925 return save_expr (e
);
3926 /* Recursively stabilize each operand. */
3927 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3928 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3932 /* Recursively stabilize each operand. */
3933 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3940 TREE_TYPE (result
) = TREE_TYPE (e
);
3941 TREE_READONLY (result
) = TREE_READONLY (e
);
3942 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3943 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3948 /* Low-level constructors for expressions. */
3950 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3951 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3954 recompute_tree_invariant_for_addr_expr (tree t
)
3957 bool tc
= true, se
= false;
3959 /* We started out assuming this address is both invariant and constant, but
3960 does not have side effects. Now go down any handled components and see if
3961 any of them involve offsets that are either non-constant or non-invariant.
3962 Also check for side-effects.
3964 ??? Note that this code makes no attempt to deal with the case where
3965 taking the address of something causes a copy due to misalignment. */
3967 #define UPDATE_FLAGS(NODE) \
3968 do { tree _node = (NODE); \
3969 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3970 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3972 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3973 node
= TREE_OPERAND (node
, 0))
3975 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3976 array reference (probably made temporarily by the G++ front end),
3977 so ignore all the operands. */
3978 if ((TREE_CODE (node
) == ARRAY_REF
3979 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3980 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3982 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3983 if (TREE_OPERAND (node
, 2))
3984 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3985 if (TREE_OPERAND (node
, 3))
3986 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3988 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3989 FIELD_DECL, apparently. The G++ front end can put something else
3990 there, at least temporarily. */
3991 else if (TREE_CODE (node
) == COMPONENT_REF
3992 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3994 if (TREE_OPERAND (node
, 2))
3995 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3999 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
4001 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
4002 the address, since &(*a)->b is a form of addition. If it's a constant, the
4003 address is constant too. If it's a decl, its address is constant if the
4004 decl is static. Everything else is not constant and, furthermore,
4005 taking the address of a volatile variable is not volatile. */
4006 if (TREE_CODE (node
) == INDIRECT_REF
4007 || TREE_CODE (node
) == MEM_REF
)
4008 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
4009 else if (CONSTANT_CLASS_P (node
))
4011 else if (DECL_P (node
))
4012 tc
&= (staticp (node
) != NULL_TREE
);
4016 se
|= TREE_SIDE_EFFECTS (node
);
4020 TREE_CONSTANT (t
) = tc
;
4021 TREE_SIDE_EFFECTS (t
) = se
;
4025 /* Build an expression of code CODE, data type TYPE, and operands as
4026 specified. Expressions and reference nodes can be created this way.
4027 Constants, decls, types and misc nodes cannot be.
4029 We define 5 non-variadic functions, from 0 to 4 arguments. This is
4030 enough for all extant tree codes. */
4033 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
4037 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
4039 t
= make_node_stat (code PASS_MEM_STAT
);
4046 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
4048 int length
= sizeof (struct tree_exp
);
4051 record_node_allocation_statistics (code
, length
);
4053 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
4055 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
4057 memset (t
, 0, sizeof (struct tree_common
));
4059 TREE_SET_CODE (t
, code
);
4061 TREE_TYPE (t
) = type
;
4062 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
4063 TREE_OPERAND (t
, 0) = node
;
4064 if (node
&& !TYPE_P (node
))
4066 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
4067 TREE_READONLY (t
) = TREE_READONLY (node
);
4070 if (TREE_CODE_CLASS (code
) == tcc_statement
)
4071 TREE_SIDE_EFFECTS (t
) = 1;
4075 /* All of these have side-effects, no matter what their
4077 TREE_SIDE_EFFECTS (t
) = 1;
4078 TREE_READONLY (t
) = 0;
4082 /* Whether a dereference is readonly has nothing to do with whether
4083 its operand is readonly. */
4084 TREE_READONLY (t
) = 0;
4089 recompute_tree_invariant_for_addr_expr (t
);
4093 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
4094 && node
&& !TYPE_P (node
)
4095 && TREE_CONSTANT (node
))
4096 TREE_CONSTANT (t
) = 1;
4097 if (TREE_CODE_CLASS (code
) == tcc_reference
4098 && node
&& TREE_THIS_VOLATILE (node
))
4099 TREE_THIS_VOLATILE (t
) = 1;
4106 #define PROCESS_ARG(N) \
4108 TREE_OPERAND (t, N) = arg##N; \
4109 if (arg##N &&!TYPE_P (arg##N)) \
4111 if (TREE_SIDE_EFFECTS (arg##N)) \
4113 if (!TREE_READONLY (arg##N) \
4114 && !CONSTANT_CLASS_P (arg##N)) \
4115 (void) (read_only = 0); \
4116 if (!TREE_CONSTANT (arg##N)) \
4117 (void) (constant = 0); \
4122 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
4124 bool constant
, read_only
, side_effects
;
4127 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
4129 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
4130 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
4131 /* When sizetype precision doesn't match that of pointers
4132 we need to be able to build explicit extensions or truncations
4133 of the offset argument. */
4134 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
4135 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
4136 && TREE_CODE (arg1
) == INTEGER_CST
);
4138 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4139 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4140 && ptrofftype_p (TREE_TYPE (arg1
)));
4142 t
= make_node_stat (code PASS_MEM_STAT
);
4145 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4146 result based on those same flags for the arguments. But if the
4147 arguments aren't really even `tree' expressions, we shouldn't be trying
4150 /* Expressions without side effects may be constant if their
4151 arguments are as well. */
4152 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4153 || TREE_CODE_CLASS (code
) == tcc_binary
);
4155 side_effects
= TREE_SIDE_EFFECTS (t
);
4160 TREE_READONLY (t
) = read_only
;
4161 TREE_CONSTANT (t
) = constant
;
4162 TREE_SIDE_EFFECTS (t
) = side_effects
;
4163 TREE_THIS_VOLATILE (t
)
4164 = (TREE_CODE_CLASS (code
) == tcc_reference
4165 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4172 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4173 tree arg2 MEM_STAT_DECL
)
4175 bool constant
, read_only
, side_effects
;
4178 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
4179 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4181 t
= make_node_stat (code PASS_MEM_STAT
);
4186 /* As a special exception, if COND_EXPR has NULL branches, we
4187 assume that it is a gimple statement and always consider
4188 it to have side effects. */
4189 if (code
== COND_EXPR
4190 && tt
== void_type_node
4191 && arg1
== NULL_TREE
4192 && arg2
== NULL_TREE
)
4193 side_effects
= true;
4195 side_effects
= TREE_SIDE_EFFECTS (t
);
4201 if (code
== COND_EXPR
)
4202 TREE_READONLY (t
) = read_only
;
4204 TREE_SIDE_EFFECTS (t
) = side_effects
;
4205 TREE_THIS_VOLATILE (t
)
4206 = (TREE_CODE_CLASS (code
) == tcc_reference
4207 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4213 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4214 tree arg2
, tree arg3 MEM_STAT_DECL
)
4216 bool constant
, read_only
, side_effects
;
4219 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
4221 t
= make_node_stat (code PASS_MEM_STAT
);
4224 side_effects
= TREE_SIDE_EFFECTS (t
);
4231 TREE_SIDE_EFFECTS (t
) = side_effects
;
4232 TREE_THIS_VOLATILE (t
)
4233 = (TREE_CODE_CLASS (code
) == tcc_reference
4234 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4240 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4241 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
4243 bool constant
, read_only
, side_effects
;
4246 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
4248 t
= make_node_stat (code PASS_MEM_STAT
);
4251 side_effects
= TREE_SIDE_EFFECTS (t
);
4259 TREE_SIDE_EFFECTS (t
) = side_effects
;
4260 TREE_THIS_VOLATILE (t
)
4261 = (TREE_CODE_CLASS (code
) == tcc_reference
4262 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4267 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4268 on the pointer PTR. */
4271 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
4273 HOST_WIDE_INT offset
= 0;
4274 tree ptype
= TREE_TYPE (ptr
);
4276 /* For convenience allow addresses that collapse to a simple base
4278 if (TREE_CODE (ptr
) == ADDR_EXPR
4279 && (handled_component_p (TREE_OPERAND (ptr
, 0))
4280 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
4282 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
4284 ptr
= build_fold_addr_expr (ptr
);
4285 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
4287 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
4288 ptr
, build_int_cst (ptype
, offset
));
4289 SET_EXPR_LOCATION (tem
, loc
);
4293 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4296 mem_ref_offset (const_tree t
)
4298 tree toff
= TREE_OPERAND (t
, 1);
4299 return tree_to_double_int (toff
).sext (TYPE_PRECISION (TREE_TYPE (toff
)));
4302 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4303 offsetted by OFFSET units. */
4306 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4308 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4309 build_fold_addr_expr (base
),
4310 build_int_cst (ptr_type_node
, offset
));
4311 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4312 recompute_tree_invariant_for_addr_expr (addr
);
4316 /* Similar except don't specify the TREE_TYPE
4317 and leave the TREE_SIDE_EFFECTS as 0.
4318 It is permissible for arguments to be null,
4319 or even garbage if their values do not matter. */
4322 build_nt (enum tree_code code
, ...)
4329 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4333 t
= make_node (code
);
4334 length
= TREE_CODE_LENGTH (code
);
4336 for (i
= 0; i
< length
; i
++)
4337 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4343 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4347 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
4352 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
4353 CALL_EXPR_FN (ret
) = fn
;
4354 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4355 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
4356 CALL_EXPR_ARG (ret
, ix
) = t
;
4360 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4361 We do NOT enter this node in any sort of symbol table.
4363 LOC is the location of the decl.
4365 layout_decl is used to set up the decl's storage layout.
4366 Other slots are initialized to 0 or null pointers. */
4369 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4370 tree type MEM_STAT_DECL
)
4374 t
= make_node_stat (code PASS_MEM_STAT
);
4375 DECL_SOURCE_LOCATION (t
) = loc
;
4377 /* if (type == error_mark_node)
4378 type = integer_type_node; */
4379 /* That is not done, deliberately, so that having error_mark_node
4380 as the type can suppress useless errors in the use of this variable. */
4382 DECL_NAME (t
) = name
;
4383 TREE_TYPE (t
) = type
;
4385 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4391 /* Builds and returns function declaration with NAME and TYPE. */
4394 build_fn_decl (const char *name
, tree type
)
4396 tree id
= get_identifier (name
);
4397 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4399 DECL_EXTERNAL (decl
) = 1;
4400 TREE_PUBLIC (decl
) = 1;
4401 DECL_ARTIFICIAL (decl
) = 1;
4402 TREE_NOTHROW (decl
) = 1;
4407 vec
<tree
, va_gc
> *all_translation_units
;
4409 /* Builds a new translation-unit decl with name NAME, queues it in the
4410 global list of translation-unit decls and returns it. */
4413 build_translation_unit_decl (tree name
)
4415 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4417 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4418 vec_safe_push (all_translation_units
, tu
);
4423 /* BLOCK nodes are used to represent the structure of binding contours
4424 and declarations, once those contours have been exited and their contents
4425 compiled. This information is used for outputting debugging info. */
4428 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4430 tree block
= make_node (BLOCK
);
4432 BLOCK_VARS (block
) = vars
;
4433 BLOCK_SUBBLOCKS (block
) = subblocks
;
4434 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4435 BLOCK_CHAIN (block
) = chain
;
4440 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4442 LOC is the location to use in tree T. */
4445 protected_set_expr_location (tree t
, location_t loc
)
4447 if (t
&& CAN_HAVE_LOCATION_P (t
))
4448 SET_EXPR_LOCATION (t
, loc
);
4451 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4455 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4457 DECL_ATTRIBUTES (ddecl
) = attribute
;
4461 /* Borrowed from hashtab.c iterative_hash implementation. */
4462 #define mix(a,b,c) \
4464 a -= b; a -= c; a ^= (c>>13); \
4465 b -= c; b -= a; b ^= (a<< 8); \
4466 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4467 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4468 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4469 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4470 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4471 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4472 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4476 /* Produce good hash value combining VAL and VAL2. */
4478 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
4480 /* the golden ratio; an arbitrary value. */
4481 hashval_t a
= 0x9e3779b9;
4487 /* Produce good hash value combining VAL and VAL2. */
4489 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
4491 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
4492 return iterative_hash_hashval_t (val
, val2
);
4495 hashval_t a
= (hashval_t
) val
;
4496 /* Avoid warnings about shifting of more than the width of the type on
4497 hosts that won't execute this path. */
4499 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
4501 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
4503 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
4504 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
4511 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4512 is ATTRIBUTE and its qualifiers are QUALS.
4514 Record such modified types already made so we don't make duplicates. */
4517 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4519 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4521 hashval_t hashcode
= 0;
4523 enum tree_code code
= TREE_CODE (ttype
);
4525 /* Building a distinct copy of a tagged type is inappropriate; it
4526 causes breakage in code that expects there to be a one-to-one
4527 relationship between a struct and its fields.
4528 build_duplicate_type is another solution (as used in
4529 handle_transparent_union_attribute), but that doesn't play well
4530 with the stronger C++ type identity model. */
4531 if (TREE_CODE (ttype
) == RECORD_TYPE
4532 || TREE_CODE (ttype
) == UNION_TYPE
4533 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4534 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4536 warning (OPT_Wattributes
,
4537 "ignoring attributes applied to %qT after definition",
4538 TYPE_MAIN_VARIANT (ttype
));
4539 return build_qualified_type (ttype
, quals
);
4542 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4543 ntype
= build_distinct_type_copy (ttype
);
4545 TYPE_ATTRIBUTES (ntype
) = attribute
;
4547 hashcode
= iterative_hash_object (code
, hashcode
);
4548 if (TREE_TYPE (ntype
))
4549 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
4551 hashcode
= attribute_hash_list (attribute
, hashcode
);
4553 switch (TREE_CODE (ntype
))
4556 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
4559 if (TYPE_DOMAIN (ntype
))
4560 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
4564 hashcode
= iterative_hash_object
4565 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
4566 hashcode
= iterative_hash_object
4567 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
4570 case FIXED_POINT_TYPE
:
4572 unsigned int precision
= TYPE_PRECISION (ntype
);
4573 hashcode
= iterative_hash_object (precision
, hashcode
);
4580 ntype
= type_hash_canon (hashcode
, ntype
);
4582 /* If the target-dependent attributes make NTYPE different from
4583 its canonical type, we will need to use structural equality
4584 checks for this type. */
4585 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4586 || !comp_type_attributes (ntype
, ttype
))
4587 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4588 else if (TYPE_CANONICAL (ntype
) == ntype
)
4589 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4591 ttype
= build_qualified_type (ntype
, quals
);
4593 else if (TYPE_QUALS (ttype
) != quals
)
4594 ttype
= build_qualified_type (ttype
, quals
);
4599 /* Check if "omp declare simd" attribute arguments, CLAUSES1 and CLAUSES2, are
4603 omp_declare_simd_clauses_equal (tree clauses1
, tree clauses2
)
4606 for (cl1
= clauses1
, cl2
= clauses2
;
4608 cl1
= OMP_CLAUSE_CHAIN (cl1
), cl2
= OMP_CLAUSE_CHAIN (cl2
))
4610 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_CODE (cl2
))
4612 if (OMP_CLAUSE_CODE (cl1
) != OMP_CLAUSE_SIMDLEN
)
4614 if (simple_cst_equal (OMP_CLAUSE_DECL (cl1
),
4615 OMP_CLAUSE_DECL (cl2
)) != 1)
4618 switch (OMP_CLAUSE_CODE (cl1
))
4620 case OMP_CLAUSE_ALIGNED
:
4621 if (simple_cst_equal (OMP_CLAUSE_ALIGNED_ALIGNMENT (cl1
),
4622 OMP_CLAUSE_ALIGNED_ALIGNMENT (cl2
)) != 1)
4625 case OMP_CLAUSE_LINEAR
:
4626 if (simple_cst_equal (OMP_CLAUSE_LINEAR_STEP (cl1
),
4627 OMP_CLAUSE_LINEAR_STEP (cl2
)) != 1)
4630 case OMP_CLAUSE_SIMDLEN
:
4631 if (simple_cst_equal (OMP_CLAUSE_SIMDLEN_EXPR (cl1
),
4632 OMP_CLAUSE_SIMDLEN_EXPR (cl2
)) != 1)
4641 /* Remove duplicate "omp declare simd" attributes. */
4644 omp_remove_redundant_declare_simd_attrs (tree fndecl
)
4646 tree attr
, end_attr
= NULL_TREE
, last_attr
= NULL_TREE
;
4647 for (attr
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (fndecl
));
4649 attr
= lookup_attribute ("omp declare simd", TREE_CHAIN (attr
)))
4652 for (pc
= &TREE_CHAIN (attr
); *pc
&& *pc
!= end_attr
; )
4654 if (is_attribute_p ("omp declare simd", TREE_PURPOSE (*pc
)))
4656 last_attr
= TREE_CHAIN (*pc
);
4657 if (TREE_VALUE (attr
) == NULL_TREE
)
4659 if (TREE_VALUE (*pc
) == NULL_TREE
)
4661 *pc
= TREE_CHAIN (*pc
);
4665 else if (TREE_VALUE (*pc
) != NULL_TREE
4666 && omp_declare_simd_clauses_equal
4667 (TREE_VALUE (TREE_VALUE (*pc
)),
4668 TREE_VALUE (TREE_VALUE (attr
))))
4670 *pc
= TREE_CHAIN (*pc
);
4674 pc
= &TREE_CHAIN (*pc
);
4676 end_attr
= last_attr
;
4680 /* Compare two attributes for their value identity. Return true if the
4681 attribute values are known to be equal; otherwise return false.
4685 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4687 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4690 if (TREE_VALUE (attr1
) != NULL_TREE
4691 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4692 && TREE_VALUE (attr2
) != NULL
4693 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4694 return (simple_cst_list_equal (TREE_VALUE (attr1
),
4695 TREE_VALUE (attr2
)) == 1);
4698 && TREE_VALUE (attr1
) && TREE_VALUE (attr2
)
4699 && TREE_CODE (TREE_VALUE (attr1
)) == OMP_CLAUSE
4700 && TREE_CODE (TREE_VALUE (attr2
)) == OMP_CLAUSE
)
4701 return omp_declare_simd_clauses_equal (TREE_VALUE (attr1
),
4702 TREE_VALUE (attr2
));
4704 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
4707 /* Return 0 if the attributes for two types are incompatible, 1 if they
4708 are compatible, and 2 if they are nearly compatible (which causes a
4709 warning to be generated). */
4711 comp_type_attributes (const_tree type1
, const_tree type2
)
4713 const_tree a1
= TYPE_ATTRIBUTES (type1
);
4714 const_tree a2
= TYPE_ATTRIBUTES (type2
);
4719 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4721 const struct attribute_spec
*as
;
4724 as
= lookup_attribute_spec (get_attribute_name (a
));
4725 if (!as
|| as
->affects_type_identity
== false)
4728 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
4729 if (!attr
|| !attribute_value_equal (a
, attr
))
4734 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4736 const struct attribute_spec
*as
;
4738 as
= lookup_attribute_spec (get_attribute_name (a
));
4739 if (!as
|| as
->affects_type_identity
== false)
4742 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
4744 /* We don't need to compare trees again, as we did this
4745 already in first loop. */
4747 /* All types - affecting identity - are equal, so
4748 there is no need to call target hook for comparison. */
4752 /* As some type combinations - like default calling-convention - might
4753 be compatible, we have to call the target hook to get the final result. */
4754 return targetm
.comp_type_attributes (type1
, type2
);
4757 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4760 Record such modified types already made so we don't make duplicates. */
4763 build_type_attribute_variant (tree ttype
, tree attribute
)
4765 return build_type_attribute_qual_variant (ttype
, attribute
,
4766 TYPE_QUALS (ttype
));
4770 /* Reset the expression *EXPR_P, a size or position.
4772 ??? We could reset all non-constant sizes or positions. But it's cheap
4773 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4775 We need to reset self-referential sizes or positions because they cannot
4776 be gimplified and thus can contain a CALL_EXPR after the gimplification
4777 is finished, which will run afoul of LTO streaming. And they need to be
4778 reset to something essentially dummy but not constant, so as to preserve
4779 the properties of the object they are attached to. */
4782 free_lang_data_in_one_sizepos (tree
*expr_p
)
4784 tree expr
= *expr_p
;
4785 if (CONTAINS_PLACEHOLDER_P (expr
))
4786 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
4790 /* Reset all the fields in a binfo node BINFO. We only keep
4791 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
4794 free_lang_data_in_binfo (tree binfo
)
4799 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
4801 BINFO_VIRTUALS (binfo
) = NULL_TREE
;
4802 BINFO_BASE_ACCESSES (binfo
) = NULL
;
4803 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
4804 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
4806 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo
), i
, t
)
4807 free_lang_data_in_binfo (t
);
4811 /* Reset all language specific information still present in TYPE. */
4814 free_lang_data_in_type (tree type
)
4816 gcc_assert (TYPE_P (type
));
4818 /* Give the FE a chance to remove its own data first. */
4819 lang_hooks
.free_lang_data (type
);
4821 TREE_LANG_FLAG_0 (type
) = 0;
4822 TREE_LANG_FLAG_1 (type
) = 0;
4823 TREE_LANG_FLAG_2 (type
) = 0;
4824 TREE_LANG_FLAG_3 (type
) = 0;
4825 TREE_LANG_FLAG_4 (type
) = 0;
4826 TREE_LANG_FLAG_5 (type
) = 0;
4827 TREE_LANG_FLAG_6 (type
) = 0;
4829 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4831 /* Remove the const and volatile qualifiers from arguments. The
4832 C++ front end removes them, but the C front end does not,
4833 leading to false ODR violation errors when merging two
4834 instances of the same function signature compiled by
4835 different front ends. */
4838 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
4840 tree arg_type
= TREE_VALUE (p
);
4842 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
4844 int quals
= TYPE_QUALS (arg_type
)
4846 & ~TYPE_QUAL_VOLATILE
;
4847 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
4848 free_lang_data_in_type (TREE_VALUE (p
));
4853 /* Remove members that are not actually FIELD_DECLs from the field
4854 list of an aggregate. These occur in C++. */
4855 if (RECORD_OR_UNION_TYPE_P (type
))
4859 /* Note that TYPE_FIELDS can be shared across distinct
4860 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4861 to be removed, we cannot set its TREE_CHAIN to NULL.
4862 Otherwise, we would not be able to find all the other fields
4863 in the other instances of this TREE_TYPE.
4865 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4867 member
= TYPE_FIELDS (type
);
4870 if (TREE_CODE (member
) == FIELD_DECL
4871 || TREE_CODE (member
) == TYPE_DECL
)
4874 TREE_CHAIN (prev
) = member
;
4876 TYPE_FIELDS (type
) = member
;
4880 member
= TREE_CHAIN (member
);
4884 TREE_CHAIN (prev
) = NULL_TREE
;
4886 TYPE_FIELDS (type
) = NULL_TREE
;
4888 TYPE_METHODS (type
) = NULL_TREE
;
4889 if (TYPE_BINFO (type
))
4890 free_lang_data_in_binfo (TYPE_BINFO (type
));
4894 /* For non-aggregate types, clear out the language slot (which
4895 overloads TYPE_BINFO). */
4896 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
4898 if (INTEGRAL_TYPE_P (type
)
4899 || SCALAR_FLOAT_TYPE_P (type
)
4900 || FIXED_POINT_TYPE_P (type
))
4902 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
4903 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
4907 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
4908 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
4910 if (TYPE_CONTEXT (type
)
4911 && TREE_CODE (TYPE_CONTEXT (type
)) == BLOCK
)
4913 tree ctx
= TYPE_CONTEXT (type
);
4916 ctx
= BLOCK_SUPERCONTEXT (ctx
);
4918 while (ctx
&& TREE_CODE (ctx
) == BLOCK
);
4919 TYPE_CONTEXT (type
) = ctx
;
4924 /* Return true if DECL may need an assembler name to be set. */
4927 need_assembler_name_p (tree decl
)
4929 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4930 if (TREE_CODE (decl
) != FUNCTION_DECL
4931 && TREE_CODE (decl
) != VAR_DECL
)
4934 /* If DECL already has its assembler name set, it does not need a
4936 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
4937 || DECL_ASSEMBLER_NAME_SET_P (decl
))
4940 /* Abstract decls do not need an assembler name. */
4941 if (DECL_ABSTRACT (decl
))
4944 /* For VAR_DECLs, only static, public and external symbols need an
4946 if (TREE_CODE (decl
) == VAR_DECL
4947 && !TREE_STATIC (decl
)
4948 && !TREE_PUBLIC (decl
)
4949 && !DECL_EXTERNAL (decl
))
4952 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4954 /* Do not set assembler name on builtins. Allow RTL expansion to
4955 decide whether to expand inline or via a regular call. */
4956 if (DECL_BUILT_IN (decl
)
4957 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
4960 /* Functions represented in the callgraph need an assembler name. */
4961 if (cgraph_get_node (decl
) != NULL
)
4964 /* Unused and not public functions don't need an assembler name. */
4965 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
4973 /* Reset all language specific information still present in symbol
4977 free_lang_data_in_decl (tree decl
)
4979 gcc_assert (DECL_P (decl
));
4981 /* Give the FE a chance to remove its own data first. */
4982 lang_hooks
.free_lang_data (decl
);
4984 TREE_LANG_FLAG_0 (decl
) = 0;
4985 TREE_LANG_FLAG_1 (decl
) = 0;
4986 TREE_LANG_FLAG_2 (decl
) = 0;
4987 TREE_LANG_FLAG_3 (decl
) = 0;
4988 TREE_LANG_FLAG_4 (decl
) = 0;
4989 TREE_LANG_FLAG_5 (decl
) = 0;
4990 TREE_LANG_FLAG_6 (decl
) = 0;
4992 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
4993 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
4994 if (TREE_CODE (decl
) == FIELD_DECL
)
4996 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
4997 if (TREE_CODE (DECL_CONTEXT (decl
)) == QUAL_UNION_TYPE
)
4998 DECL_QUALIFIER (decl
) = NULL_TREE
;
5001 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5003 struct cgraph_node
*node
;
5004 if (!(node
= cgraph_get_node (decl
))
5005 || (!node
->symbol
.definition
&& !node
->clones
))
5008 cgraph_release_function_body (node
);
5011 release_function_body (decl
);
5012 DECL_ARGUMENTS (decl
) = NULL
;
5013 DECL_RESULT (decl
) = NULL
;
5014 DECL_INITIAL (decl
) = error_mark_node
;
5017 if (gimple_has_body_p (decl
))
5021 /* If DECL has a gimple body, then the context for its
5022 arguments must be DECL. Otherwise, it doesn't really
5023 matter, as we will not be emitting any code for DECL. In
5024 general, there may be other instances of DECL created by
5025 the front end and since PARM_DECLs are generally shared,
5026 their DECL_CONTEXT changes as the replicas of DECL are
5027 created. The only time where DECL_CONTEXT is important
5028 is for the FUNCTION_DECLs that have a gimple body (since
5029 the PARM_DECL will be used in the function's body). */
5030 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
5031 DECL_CONTEXT (t
) = decl
;
5034 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
5035 At this point, it is not needed anymore. */
5036 DECL_SAVED_TREE (decl
) = NULL_TREE
;
5038 /* Clear the abstract origin if it refers to a method. Otherwise
5039 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
5040 origin will not be output correctly. */
5041 if (DECL_ABSTRACT_ORIGIN (decl
)
5042 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
5043 && RECORD_OR_UNION_TYPE_P
5044 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
5045 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
5047 /* Sometimes the C++ frontend doesn't manage to transform a temporary
5048 DECL_VINDEX referring to itself into a vtable slot number as it
5049 should. Happens with functions that are copied and then forgotten
5050 about. Just clear it, it won't matter anymore. */
5051 if (DECL_VINDEX (decl
) && !host_integerp (DECL_VINDEX (decl
), 0))
5052 DECL_VINDEX (decl
) = NULL_TREE
;
5054 else if (TREE_CODE (decl
) == VAR_DECL
)
5056 if ((DECL_EXTERNAL (decl
)
5057 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
5058 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
5059 DECL_INITIAL (decl
) = NULL_TREE
;
5061 else if (TREE_CODE (decl
) == TYPE_DECL
5062 || TREE_CODE (decl
) == FIELD_DECL
)
5063 DECL_INITIAL (decl
) = NULL_TREE
;
5064 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
5065 && DECL_INITIAL (decl
)
5066 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
5068 /* Strip builtins from the translation-unit BLOCK. We still have targets
5069 without builtin_decl_explicit support and also builtins are shared
5070 nodes and thus we can't use TREE_CHAIN in multiple lists. */
5071 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
5075 if (TREE_CODE (var
) == FUNCTION_DECL
5076 && DECL_BUILT_IN (var
))
5077 *nextp
= TREE_CHAIN (var
);
5079 nextp
= &TREE_CHAIN (var
);
5085 /* Data used when collecting DECLs and TYPEs for language data removal. */
5087 struct free_lang_data_d
5089 /* Worklist to avoid excessive recursion. */
5092 /* Set of traversed objects. Used to avoid duplicate visits. */
5093 struct pointer_set_t
*pset
;
5095 /* Array of symbols to process with free_lang_data_in_decl. */
5098 /* Array of types to process with free_lang_data_in_type. */
5103 /* Save all language fields needed to generate proper debug information
5104 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
5107 save_debug_info_for_decl (tree t
)
5109 /*struct saved_debug_info_d *sdi;*/
5111 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
5113 /* FIXME. Partial implementation for saving debug info removed. */
5117 /* Save all language fields needed to generate proper debug information
5118 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5121 save_debug_info_for_type (tree t
)
5123 /*struct saved_debug_info_d *sdi;*/
5125 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
5127 /* FIXME. Partial implementation for saving debug info removed. */
5131 /* Add type or decl T to one of the list of tree nodes that need their
5132 language data removed. The lists are held inside FLD. */
5135 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
5139 fld
->decls
.safe_push (t
);
5140 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5141 save_debug_info_for_decl (t
);
5143 else if (TYPE_P (t
))
5145 fld
->types
.safe_push (t
);
5146 if (debug_info_level
> DINFO_LEVEL_TERSE
)
5147 save_debug_info_for_type (t
);
5153 /* Push tree node T into FLD->WORKLIST. */
5156 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
5158 if (t
&& !is_lang_specific (t
) && !pointer_set_contains (fld
->pset
, t
))
5159 fld
->worklist
.safe_push ((t
));
5163 /* Operand callback helper for free_lang_data_in_node. *TP is the
5164 subtree operand being considered. */
5167 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
5170 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
5172 if (TREE_CODE (t
) == TREE_LIST
)
5175 /* Language specific nodes will be removed, so there is no need
5176 to gather anything under them. */
5177 if (is_lang_specific (t
))
5185 /* Note that walk_tree does not traverse every possible field in
5186 decls, so we have to do our own traversals here. */
5187 add_tree_to_fld_list (t
, fld
);
5189 fld_worklist_push (DECL_NAME (t
), fld
);
5190 fld_worklist_push (DECL_CONTEXT (t
), fld
);
5191 fld_worklist_push (DECL_SIZE (t
), fld
);
5192 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
5194 /* We are going to remove everything under DECL_INITIAL for
5195 TYPE_DECLs. No point walking them. */
5196 if (TREE_CODE (t
) != TYPE_DECL
)
5197 fld_worklist_push (DECL_INITIAL (t
), fld
);
5199 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
5200 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
5202 if (TREE_CODE (t
) == FUNCTION_DECL
)
5204 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
5205 fld_worklist_push (DECL_RESULT (t
), fld
);
5207 else if (TREE_CODE (t
) == TYPE_DECL
)
5209 fld_worklist_push (DECL_ARGUMENT_FLD (t
), fld
);
5210 fld_worklist_push (DECL_VINDEX (t
), fld
);
5211 fld_worklist_push (DECL_ORIGINAL_TYPE (t
), fld
);
5213 else if (TREE_CODE (t
) == FIELD_DECL
)
5215 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
5216 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
5217 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
5218 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
5220 else if (TREE_CODE (t
) == VAR_DECL
)
5222 fld_worklist_push (DECL_SECTION_NAME (t
), fld
);
5223 fld_worklist_push (DECL_COMDAT_GROUP (t
), fld
);
5226 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
5227 && DECL_HAS_VALUE_EXPR_P (t
))
5228 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
5230 if (TREE_CODE (t
) != FIELD_DECL
5231 && TREE_CODE (t
) != TYPE_DECL
)
5232 fld_worklist_push (TREE_CHAIN (t
), fld
);
5235 else if (TYPE_P (t
))
5237 /* Note that walk_tree does not traverse every possible field in
5238 types, so we have to do our own traversals here. */
5239 add_tree_to_fld_list (t
, fld
);
5241 if (!RECORD_OR_UNION_TYPE_P (t
))
5242 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
5243 fld_worklist_push (TYPE_SIZE (t
), fld
);
5244 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
5245 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
5246 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
5247 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
5248 fld_worklist_push (TYPE_NAME (t
), fld
);
5249 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5250 them and thus do not and want not to reach unused pointer types
5252 if (!POINTER_TYPE_P (t
))
5253 fld_worklist_push (TYPE_MINVAL (t
), fld
);
5254 if (!RECORD_OR_UNION_TYPE_P (t
))
5255 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
5256 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
5257 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5258 do not and want not to reach unused variants this way. */
5259 if (TYPE_CONTEXT (t
))
5261 tree ctx
= TYPE_CONTEXT (t
);
5262 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5263 So push that instead. */
5264 while (ctx
&& TREE_CODE (ctx
) == BLOCK
)
5265 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5266 fld_worklist_push (ctx
, fld
);
5268 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5269 and want not to reach unused types this way. */
5271 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
5275 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t
)), i
, tem
)
5276 fld_worklist_push (TREE_TYPE (tem
), fld
);
5277 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
5279 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5280 && TREE_CODE (tem
) == TREE_LIST
)
5283 fld_worklist_push (TREE_VALUE (tem
), fld
);
5284 tem
= TREE_CHAIN (tem
);
5288 if (RECORD_OR_UNION_TYPE_P (t
))
5291 /* Push all TYPE_FIELDS - there can be interleaving interesting
5292 and non-interesting things. */
5293 tem
= TYPE_FIELDS (t
);
5296 if (TREE_CODE (tem
) == FIELD_DECL
5297 || TREE_CODE (tem
) == TYPE_DECL
)
5298 fld_worklist_push (tem
, fld
);
5299 tem
= TREE_CHAIN (tem
);
5303 fld_worklist_push (TYPE_STUB_DECL (t
), fld
);
5306 else if (TREE_CODE (t
) == BLOCK
)
5309 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
5310 fld_worklist_push (tem
, fld
);
5311 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
5312 fld_worklist_push (tem
, fld
);
5313 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
5316 if (TREE_CODE (t
) != IDENTIFIER_NODE
5317 && CODE_CONTAINS_STRUCT (TREE_CODE (t
), TS_TYPED
))
5318 fld_worklist_push (TREE_TYPE (t
), fld
);
5324 /* Find decls and types in T. */
5327 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
5331 if (!pointer_set_contains (fld
->pset
, t
))
5332 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
5333 if (fld
->worklist
.is_empty ())
5335 t
= fld
->worklist
.pop ();
5339 /* Translate all the types in LIST with the corresponding runtime
5343 get_eh_types_for_runtime (tree list
)
5347 if (list
== NULL_TREE
)
5350 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5352 list
= TREE_CHAIN (list
);
5355 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5356 TREE_CHAIN (prev
) = n
;
5357 prev
= TREE_CHAIN (prev
);
5358 list
= TREE_CHAIN (list
);
5365 /* Find decls and types referenced in EH region R and store them in
5366 FLD->DECLS and FLD->TYPES. */
5369 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
5380 /* The types referenced in each catch must first be changed to the
5381 EH types used at runtime. This removes references to FE types
5383 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
5385 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
5386 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
5391 case ERT_ALLOWED_EXCEPTIONS
:
5392 r
->u
.allowed
.type_list
5393 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
5394 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
5397 case ERT_MUST_NOT_THROW
:
5398 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
5399 find_decls_types_r
, fld
, fld
->pset
);
5405 /* Find decls and types referenced in cgraph node N and store them in
5406 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5407 look for *every* kind of DECL and TYPE node reachable from N,
5408 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5409 NAMESPACE_DECLs, etc). */
5412 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5415 struct function
*fn
;
5419 find_decls_types (n
->symbol
.decl
, fld
);
5421 if (!gimple_has_body_p (n
->symbol
.decl
))
5424 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5426 fn
= DECL_STRUCT_FUNCTION (n
->symbol
.decl
);
5428 /* Traverse locals. */
5429 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5430 find_decls_types (t
, fld
);
5432 /* Traverse EH regions in FN. */
5435 FOR_ALL_EH_REGION_FN (r
, fn
)
5436 find_decls_types_in_eh_region (r
, fld
);
5439 /* Traverse every statement in FN. */
5440 FOR_EACH_BB_FN (bb
, fn
)
5442 gimple_stmt_iterator si
;
5445 for (si
= gsi_start_phis (bb
); !gsi_end_p (si
); gsi_next (&si
))
5447 gimple phi
= gsi_stmt (si
);
5449 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5451 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5452 find_decls_types (*arg_p
, fld
);
5456 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5458 gimple stmt
= gsi_stmt (si
);
5460 if (is_gimple_call (stmt
))
5461 find_decls_types (gimple_call_fntype (stmt
), fld
);
5463 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5465 tree arg
= gimple_op (stmt
, i
);
5466 find_decls_types (arg
, fld
);
5473 /* Find decls and types referenced in varpool node N and store them in
5474 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5475 look for *every* kind of DECL and TYPE node reachable from N,
5476 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5477 NAMESPACE_DECLs, etc). */
5480 find_decls_types_in_var (struct varpool_node
*v
, struct free_lang_data_d
*fld
)
5482 find_decls_types (v
->symbol
.decl
, fld
);
5485 /* If T needs an assembler name, have one created for it. */
5488 assign_assembler_name_if_neeeded (tree t
)
5490 if (need_assembler_name_p (t
))
5492 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5493 diagnostics that use input_location to show locus
5494 information. The problem here is that, at this point,
5495 input_location is generally anchored to the end of the file
5496 (since the parser is long gone), so we don't have a good
5497 position to pin it to.
5499 To alleviate this problem, this uses the location of T's
5500 declaration. Examples of this are
5501 testsuite/g++.dg/template/cond2.C and
5502 testsuite/g++.dg/template/pr35240.C. */
5503 location_t saved_location
= input_location
;
5504 input_location
= DECL_SOURCE_LOCATION (t
);
5506 decl_assembler_name (t
);
5508 input_location
= saved_location
;
5513 /* Free language specific information for every operand and expression
5514 in every node of the call graph. This process operates in three stages:
5516 1- Every callgraph node and varpool node is traversed looking for
5517 decls and types embedded in them. This is a more exhaustive
5518 search than that done by find_referenced_vars, because it will
5519 also collect individual fields, decls embedded in types, etc.
5521 2- All the decls found are sent to free_lang_data_in_decl.
5523 3- All the types found are sent to free_lang_data_in_type.
5525 The ordering between decls and types is important because
5526 free_lang_data_in_decl sets assembler names, which includes
5527 mangling. So types cannot be freed up until assembler names have
5531 free_lang_data_in_cgraph (void)
5533 struct cgraph_node
*n
;
5534 struct varpool_node
*v
;
5535 struct free_lang_data_d fld
;
5540 /* Initialize sets and arrays to store referenced decls and types. */
5541 fld
.pset
= pointer_set_create ();
5542 fld
.worklist
.create (0);
5543 fld
.decls
.create (100);
5544 fld
.types
.create (100);
5546 /* Find decls and types in the body of every function in the callgraph. */
5547 FOR_EACH_FUNCTION (n
)
5548 find_decls_types_in_node (n
, &fld
);
5550 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
5551 find_decls_types (p
->decl
, &fld
);
5553 /* Find decls and types in every varpool symbol. */
5554 FOR_EACH_VARIABLE (v
)
5555 find_decls_types_in_var (v
, &fld
);
5557 /* Set the assembler name on every decl found. We need to do this
5558 now because free_lang_data_in_decl will invalidate data needed
5559 for mangling. This breaks mangling on interdependent decls. */
5560 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5561 assign_assembler_name_if_neeeded (t
);
5563 /* Traverse every decl found freeing its language data. */
5564 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5565 free_lang_data_in_decl (t
);
5567 /* Traverse every type found freeing its language data. */
5568 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5569 free_lang_data_in_type (t
);
5571 pointer_set_destroy (fld
.pset
);
5572 fld
.worklist
.release ();
5573 fld
.decls
.release ();
5574 fld
.types
.release ();
5578 /* Free resources that are used by FE but are not needed once they are done. */
5581 free_lang_data (void)
5585 /* If we are the LTO frontend we have freed lang-specific data already. */
5587 || !flag_generate_lto
)
5590 /* Allocate and assign alias sets to the standard integer types
5591 while the slots are still in the way the frontends generated them. */
5592 for (i
= 0; i
< itk_none
; ++i
)
5593 if (integer_types
[i
])
5594 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5596 /* Traverse the IL resetting language specific information for
5597 operands, expressions, etc. */
5598 free_lang_data_in_cgraph ();
5600 /* Create gimple variants for common types. */
5601 ptrdiff_type_node
= integer_type_node
;
5602 fileptr_type_node
= ptr_type_node
;
5604 /* Reset some langhooks. Do not reset types_compatible_p, it may
5605 still be used indirectly via the get_alias_set langhook. */
5606 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5607 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5608 /* We do not want the default decl_assembler_name implementation,
5609 rather if we have fixed everything we want a wrapper around it
5610 asserting that all non-local symbols already got their assembler
5611 name and only produce assembler names for local symbols. Or rather
5612 make sure we never call decl_assembler_name on local symbols and
5613 devise a separate, middle-end private scheme for it. */
5615 /* Reset diagnostic machinery. */
5616 tree_diagnostics_defaults (global_dc
);
5624 const pass_data pass_data_ipa_free_lang_data
=
5626 SIMPLE_IPA_PASS
, /* type */
5627 "*free_lang_data", /* name */
5628 OPTGROUP_NONE
, /* optinfo_flags */
5629 false, /* has_gate */
5630 true, /* has_execute */
5631 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5632 0, /* properties_required */
5633 0, /* properties_provided */
5634 0, /* properties_destroyed */
5635 0, /* todo_flags_start */
5636 0, /* todo_flags_finish */
5639 class pass_ipa_free_lang_data
: public simple_ipa_opt_pass
5642 pass_ipa_free_lang_data (gcc::context
*ctxt
)
5643 : simple_ipa_opt_pass (pass_data_ipa_free_lang_data
, ctxt
)
5646 /* opt_pass methods: */
5647 unsigned int execute () { return free_lang_data (); }
5649 }; // class pass_ipa_free_lang_data
5653 simple_ipa_opt_pass
*
5654 make_pass_ipa_free_lang_data (gcc::context
*ctxt
)
5656 return new pass_ipa_free_lang_data (ctxt
);
5659 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
5660 ATTR_NAME. Also used internally by remove_attribute(). */
5662 private_is_attribute_p (const char *attr_name
, size_t attr_len
, const_tree ident
)
5664 size_t ident_len
= IDENTIFIER_LENGTH (ident
);
5666 if (ident_len
== attr_len
)
5668 if (strcmp (attr_name
, IDENTIFIER_POINTER (ident
)) == 0)
5671 else if (ident_len
== attr_len
+ 4)
5673 /* There is the possibility that ATTR is 'text' and IDENT is
5675 const char *p
= IDENTIFIER_POINTER (ident
);
5676 if (p
[0] == '_' && p
[1] == '_'
5677 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5678 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5685 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
5686 of ATTR_NAME, and LIST is not NULL_TREE. */
5688 private_lookup_attribute (const char *attr_name
, size_t attr_len
, tree list
)
5692 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5694 if (ident_len
== attr_len
)
5696 if (!strcmp (attr_name
,
5697 IDENTIFIER_POINTER (get_attribute_name (list
))))
5700 /* TODO: If we made sure that attributes were stored in the
5701 canonical form without '__...__' (ie, as in 'text' as opposed
5702 to '__text__') then we could avoid the following case. */
5703 else if (ident_len
== attr_len
+ 4)
5705 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5706 if (p
[0] == '_' && p
[1] == '_'
5707 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5708 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5711 list
= TREE_CHAIN (list
);
5717 /* A variant of lookup_attribute() that can be used with an identifier
5718 as the first argument, and where the identifier can be either
5719 'text' or '__text__'.
5721 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
5722 return a pointer to the attribute's list element if the attribute
5723 is part of the list, or NULL_TREE if not found. If the attribute
5724 appears more than once, this only returns the first occurrence; the
5725 TREE_CHAIN of the return value should be passed back in if further
5726 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
5727 can be in the form 'text' or '__text__'. */
5729 lookup_ident_attribute (tree attr_identifier
, tree list
)
5731 gcc_checking_assert (TREE_CODE (attr_identifier
) == IDENTIFIER_NODE
);
5735 gcc_checking_assert (TREE_CODE (get_attribute_name (list
))
5736 == IDENTIFIER_NODE
);
5738 /* Identifiers can be compared directly for equality. */
5739 if (attr_identifier
== get_attribute_name (list
))
5742 /* If they are not equal, they may still be one in the form
5743 'text' while the other one is in the form '__text__'. TODO:
5744 If we were storing attributes in normalized 'text' form, then
5745 this could all go away and we could take full advantage of
5746 the fact that we're comparing identifiers. :-) */
5748 size_t attr_len
= IDENTIFIER_LENGTH (attr_identifier
);
5749 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5751 if (ident_len
== attr_len
+ 4)
5753 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5754 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5755 if (p
[0] == '_' && p
[1] == '_'
5756 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5757 && strncmp (q
, p
+ 2, attr_len
) == 0)
5760 else if (ident_len
+ 4 == attr_len
)
5762 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5763 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5764 if (q
[0] == '_' && q
[1] == '_'
5765 && q
[attr_len
- 2] == '_' && q
[attr_len
- 1] == '_'
5766 && strncmp (q
+ 2, p
, ident_len
) == 0)
5770 list
= TREE_CHAIN (list
);
5776 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5780 remove_attribute (const char *attr_name
, tree list
)
5783 size_t attr_len
= strlen (attr_name
);
5785 gcc_checking_assert (attr_name
[0] != '_');
5787 for (p
= &list
; *p
; )
5790 /* TODO: If we were storing attributes in normalized form, here
5791 we could use a simple strcmp(). */
5792 if (private_is_attribute_p (attr_name
, attr_len
, get_attribute_name (l
)))
5793 *p
= TREE_CHAIN (l
);
5795 p
= &TREE_CHAIN (l
);
5801 /* Return an attribute list that is the union of a1 and a2. */
5804 merge_attributes (tree a1
, tree a2
)
5808 /* Either one unset? Take the set one. */
5810 if ((attributes
= a1
) == 0)
5813 /* One that completely contains the other? Take it. */
5815 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
5817 if (attribute_list_contained (a2
, a1
))
5821 /* Pick the longest list, and hang on the other list. */
5823 if (list_length (a1
) < list_length (a2
))
5824 attributes
= a2
, a2
= a1
;
5826 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
5829 for (a
= lookup_ident_attribute (get_attribute_name (a2
),
5831 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
5832 a
= lookup_ident_attribute (get_attribute_name (a2
),
5837 a1
= copy_node (a2
);
5838 TREE_CHAIN (a1
) = attributes
;
5847 /* Given types T1 and T2, merge their attributes and return
5851 merge_type_attributes (tree t1
, tree t2
)
5853 return merge_attributes (TYPE_ATTRIBUTES (t1
),
5854 TYPE_ATTRIBUTES (t2
));
5857 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5861 merge_decl_attributes (tree olddecl
, tree newdecl
)
5863 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
5864 DECL_ATTRIBUTES (newdecl
));
5867 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5869 /* Specialization of merge_decl_attributes for various Windows targets.
5871 This handles the following situation:
5873 __declspec (dllimport) int foo;
5876 The second instance of `foo' nullifies the dllimport. */
5879 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
5882 int delete_dllimport_p
= 1;
5884 /* What we need to do here is remove from `old' dllimport if it doesn't
5885 appear in `new'. dllimport behaves like extern: if a declaration is
5886 marked dllimport and a definition appears later, then the object
5887 is not dllimport'd. We also remove a `new' dllimport if the old list
5888 contains dllexport: dllexport always overrides dllimport, regardless
5889 of the order of declaration. */
5890 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
5891 delete_dllimport_p
= 0;
5892 else if (DECL_DLLIMPORT_P (new_tree
)
5893 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
5895 DECL_DLLIMPORT_P (new_tree
) = 0;
5896 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
5897 "dllimport ignored", new_tree
);
5899 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
5901 /* Warn about overriding a symbol that has already been used, e.g.:
5902 extern int __attribute__ ((dllimport)) foo;
5903 int* bar () {return &foo;}
5906 if (TREE_USED (old
))
5908 warning (0, "%q+D redeclared without dllimport attribute "
5909 "after being referenced with dll linkage", new_tree
);
5910 /* If we have used a variable's address with dllimport linkage,
5911 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5912 decl may already have had TREE_CONSTANT computed.
5913 We still remove the attribute so that assembler code refers
5914 to '&foo rather than '_imp__foo'. */
5915 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
5916 DECL_DLLIMPORT_P (new_tree
) = 1;
5919 /* Let an inline definition silently override the external reference,
5920 but otherwise warn about attribute inconsistency. */
5921 else if (TREE_CODE (new_tree
) == VAR_DECL
5922 || !DECL_DECLARED_INLINE_P (new_tree
))
5923 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
5924 "previous dllimport ignored", new_tree
);
5927 delete_dllimport_p
= 0;
5929 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
5931 if (delete_dllimport_p
)
5932 a
= remove_attribute ("dllimport", a
);
5937 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5938 struct attribute_spec.handler. */
5941 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
5947 /* These attributes may apply to structure and union types being created,
5948 but otherwise should pass to the declaration involved. */
5951 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
5952 | (int) ATTR_FLAG_ARRAY_NEXT
))
5954 *no_add_attrs
= true;
5955 return tree_cons (name
, args
, NULL_TREE
);
5957 if (TREE_CODE (node
) == RECORD_TYPE
5958 || TREE_CODE (node
) == UNION_TYPE
)
5960 node
= TYPE_NAME (node
);
5966 warning (OPT_Wattributes
, "%qE attribute ignored",
5968 *no_add_attrs
= true;
5973 if (TREE_CODE (node
) != FUNCTION_DECL
5974 && TREE_CODE (node
) != VAR_DECL
5975 && TREE_CODE (node
) != TYPE_DECL
)
5977 *no_add_attrs
= true;
5978 warning (OPT_Wattributes
, "%qE attribute ignored",
5983 if (TREE_CODE (node
) == TYPE_DECL
5984 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
5985 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
5987 *no_add_attrs
= true;
5988 warning (OPT_Wattributes
, "%qE attribute ignored",
5993 is_dllimport
= is_attribute_p ("dllimport", name
);
5995 /* Report error on dllimport ambiguities seen now before they cause
5999 /* Honor any target-specific overrides. */
6000 if (!targetm
.valid_dllimport_attribute_p (node
))
6001 *no_add_attrs
= true;
6003 else if (TREE_CODE (node
) == FUNCTION_DECL
6004 && DECL_DECLARED_INLINE_P (node
))
6006 warning (OPT_Wattributes
, "inline function %q+D declared as "
6007 " dllimport: attribute ignored", node
);
6008 *no_add_attrs
= true;
6010 /* Like MS, treat definition of dllimported variables and
6011 non-inlined functions on declaration as syntax errors. */
6012 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
6014 error ("function %q+D definition is marked dllimport", node
);
6015 *no_add_attrs
= true;
6018 else if (TREE_CODE (node
) == VAR_DECL
)
6020 if (DECL_INITIAL (node
))
6022 error ("variable %q+D definition is marked dllimport",
6024 *no_add_attrs
= true;
6027 /* `extern' needn't be specified with dllimport.
6028 Specify `extern' now and hope for the best. Sigh. */
6029 DECL_EXTERNAL (node
) = 1;
6030 /* Also, implicitly give dllimport'd variables declared within
6031 a function global scope, unless declared static. */
6032 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
6033 TREE_PUBLIC (node
) = 1;
6036 if (*no_add_attrs
== false)
6037 DECL_DLLIMPORT_P (node
) = 1;
6039 else if (TREE_CODE (node
) == FUNCTION_DECL
6040 && DECL_DECLARED_INLINE_P (node
)
6041 && flag_keep_inline_dllexport
)
6042 /* An exported function, even if inline, must be emitted. */
6043 DECL_EXTERNAL (node
) = 0;
6045 /* Report error if symbol is not accessible at global scope. */
6046 if (!TREE_PUBLIC (node
)
6047 && (TREE_CODE (node
) == VAR_DECL
6048 || TREE_CODE (node
) == FUNCTION_DECL
))
6050 error ("external linkage required for symbol %q+D because of "
6051 "%qE attribute", node
, name
);
6052 *no_add_attrs
= true;
6055 /* A dllexport'd entity must have default visibility so that other
6056 program units (shared libraries or the main executable) can see
6057 it. A dllimport'd entity must have default visibility so that
6058 the linker knows that undefined references within this program
6059 unit can be resolved by the dynamic linker. */
6062 if (DECL_VISIBILITY_SPECIFIED (node
)
6063 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
6064 error ("%qE implies default visibility, but %qD has already "
6065 "been declared with a different visibility",
6067 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
6068 DECL_VISIBILITY_SPECIFIED (node
) = 1;
6074 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
6076 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
6077 of the various TYPE_QUAL values. */
6080 set_type_quals (tree type
, int type_quals
)
6082 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
6083 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
6084 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
6085 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
6088 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
6091 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
6093 return (TYPE_QUALS (cand
) == type_quals
6094 && TYPE_NAME (cand
) == TYPE_NAME (base
)
6095 /* Apparently this is needed for Objective-C. */
6096 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6097 /* Check alignment. */
6098 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
6099 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6100 TYPE_ATTRIBUTES (base
)));
6103 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
6106 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
6108 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
6109 && TYPE_NAME (cand
) == TYPE_NAME (base
)
6110 /* Apparently this is needed for Objective-C. */
6111 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
6112 /* Check alignment. */
6113 && TYPE_ALIGN (cand
) == align
6114 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
6115 TYPE_ATTRIBUTES (base
)));
6118 /* Return a version of the TYPE, qualified as indicated by the
6119 TYPE_QUALS, if one exists. If no qualified version exists yet,
6120 return NULL_TREE. */
6123 get_qualified_type (tree type
, int type_quals
)
6127 if (TYPE_QUALS (type
) == type_quals
)
6130 /* Search the chain of variants to see if there is already one there just
6131 like the one we need to have. If so, use that existing one. We must
6132 preserve the TYPE_NAME, since there is code that depends on this. */
6133 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6134 if (check_qualified_type (t
, type
, type_quals
))
6140 /* Like get_qualified_type, but creates the type if it does not
6141 exist. This function never returns NULL_TREE. */
6144 build_qualified_type (tree type
, int type_quals
)
6148 /* See if we already have the appropriate qualified variant. */
6149 t
= get_qualified_type (type
, type_quals
);
6151 /* If not, build it. */
6154 t
= build_variant_type_copy (type
);
6155 set_type_quals (t
, type_quals
);
6157 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6158 /* Propagate structural equality. */
6159 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6160 else if (TYPE_CANONICAL (type
) != type
)
6161 /* Build the underlying canonical type, since it is different
6163 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
6166 /* T is its own canonical type. */
6167 TYPE_CANONICAL (t
) = t
;
6174 /* Create a variant of type T with alignment ALIGN. */
6177 build_aligned_type (tree type
, unsigned int align
)
6181 if (TYPE_PACKED (type
)
6182 || TYPE_ALIGN (type
) == align
)
6185 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6186 if (check_aligned_type (t
, type
, align
))
6189 t
= build_variant_type_copy (type
);
6190 TYPE_ALIGN (t
) = align
;
6195 /* Create a new distinct copy of TYPE. The new type is made its own
6196 MAIN_VARIANT. If TYPE requires structural equality checks, the
6197 resulting type requires structural equality checks; otherwise, its
6198 TYPE_CANONICAL points to itself. */
6201 build_distinct_type_copy (tree type
)
6203 tree t
= copy_node (type
);
6205 TYPE_POINTER_TO (t
) = 0;
6206 TYPE_REFERENCE_TO (t
) = 0;
6208 /* Set the canonical type either to a new equivalence class, or
6209 propagate the need for structural equality checks. */
6210 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6211 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6213 TYPE_CANONICAL (t
) = t
;
6215 /* Make it its own variant. */
6216 TYPE_MAIN_VARIANT (t
) = t
;
6217 TYPE_NEXT_VARIANT (t
) = 0;
6219 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6220 whose TREE_TYPE is not t. This can also happen in the Ada
6221 frontend when using subtypes. */
6226 /* Create a new variant of TYPE, equivalent but distinct. This is so
6227 the caller can modify it. TYPE_CANONICAL for the return type will
6228 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6229 are considered equal by the language itself (or that both types
6230 require structural equality checks). */
6233 build_variant_type_copy (tree type
)
6235 tree t
, m
= TYPE_MAIN_VARIANT (type
);
6237 t
= build_distinct_type_copy (type
);
6239 /* Since we're building a variant, assume that it is a non-semantic
6240 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6241 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
6243 /* Add the new type to the chain of variants of TYPE. */
6244 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
6245 TYPE_NEXT_VARIANT (m
) = t
;
6246 TYPE_MAIN_VARIANT (t
) = m
;
6251 /* Return true if the from tree in both tree maps are equal. */
6254 tree_map_base_eq (const void *va
, const void *vb
)
6256 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
6257 *const b
= (const struct tree_map_base
*) vb
;
6258 return (a
->from
== b
->from
);
6261 /* Hash a from tree in a tree_base_map. */
6264 tree_map_base_hash (const void *item
)
6266 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
6269 /* Return true if this tree map structure is marked for garbage collection
6270 purposes. We simply return true if the from tree is marked, so that this
6271 structure goes away when the from tree goes away. */
6274 tree_map_base_marked_p (const void *p
)
6276 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
6279 /* Hash a from tree in a tree_map. */
6282 tree_map_hash (const void *item
)
6284 return (((const struct tree_map
*) item
)->hash
);
6287 /* Hash a from tree in a tree_decl_map. */
6290 tree_decl_map_hash (const void *item
)
6292 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
6295 /* Return the initialization priority for DECL. */
6298 decl_init_priority_lookup (tree decl
)
6300 struct tree_priority_map
*h
;
6301 struct tree_map_base in
;
6303 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6305 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6306 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
6309 /* Return the finalization priority for DECL. */
6312 decl_fini_priority_lookup (tree decl
)
6314 struct tree_priority_map
*h
;
6315 struct tree_map_base in
;
6317 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6319 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6320 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
6323 /* Return the initialization and finalization priority information for
6324 DECL. If there is no previous priority information, a freshly
6325 allocated structure is returned. */
6327 static struct tree_priority_map
*
6328 decl_priority_info (tree decl
)
6330 struct tree_priority_map in
;
6331 struct tree_priority_map
*h
;
6334 in
.base
.from
= decl
;
6335 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
6336 h
= (struct tree_priority_map
*) *loc
;
6339 h
= ggc_alloc_cleared_tree_priority_map ();
6341 h
->base
.from
= decl
;
6342 h
->init
= DEFAULT_INIT_PRIORITY
;
6343 h
->fini
= DEFAULT_INIT_PRIORITY
;
6349 /* Set the initialization priority for DECL to PRIORITY. */
6352 decl_init_priority_insert (tree decl
, priority_type priority
)
6354 struct tree_priority_map
*h
;
6356 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6357 if (priority
== DEFAULT_INIT_PRIORITY
)
6359 h
= decl_priority_info (decl
);
6363 /* Set the finalization priority for DECL to PRIORITY. */
6366 decl_fini_priority_insert (tree decl
, priority_type priority
)
6368 struct tree_priority_map
*h
;
6370 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6371 if (priority
== DEFAULT_INIT_PRIORITY
)
6373 h
= decl_priority_info (decl
);
6377 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6380 print_debug_expr_statistics (void)
6382 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6383 (long) htab_size (debug_expr_for_decl
),
6384 (long) htab_elements (debug_expr_for_decl
),
6385 htab_collisions (debug_expr_for_decl
));
6388 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6391 print_value_expr_statistics (void)
6393 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6394 (long) htab_size (value_expr_for_decl
),
6395 (long) htab_elements (value_expr_for_decl
),
6396 htab_collisions (value_expr_for_decl
));
6399 /* Lookup a debug expression for FROM, and return it if we find one. */
6402 decl_debug_expr_lookup (tree from
)
6404 struct tree_decl_map
*h
, in
;
6405 in
.base
.from
= from
;
6407 h
= (struct tree_decl_map
*)
6408 htab_find_with_hash (debug_expr_for_decl
, &in
, DECL_UID (from
));
6414 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6417 decl_debug_expr_insert (tree from
, tree to
)
6419 struct tree_decl_map
*h
;
6422 h
= ggc_alloc_tree_decl_map ();
6423 h
->base
.from
= from
;
6425 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, DECL_UID (from
),
6427 *(struct tree_decl_map
**) loc
= h
;
6430 /* Lookup a value expression for FROM, and return it if we find one. */
6433 decl_value_expr_lookup (tree from
)
6435 struct tree_decl_map
*h
, in
;
6436 in
.base
.from
= from
;
6438 h
= (struct tree_decl_map
*)
6439 htab_find_with_hash (value_expr_for_decl
, &in
, DECL_UID (from
));
6445 /* Insert a mapping FROM->TO in the value expression hashtable. */
6448 decl_value_expr_insert (tree from
, tree to
)
6450 struct tree_decl_map
*h
;
6453 h
= ggc_alloc_tree_decl_map ();
6454 h
->base
.from
= from
;
6456 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, DECL_UID (from
),
6458 *(struct tree_decl_map
**) loc
= h
;
6461 /* Lookup a vector of debug arguments for FROM, and return it if we
6465 decl_debug_args_lookup (tree from
)
6467 struct tree_vec_map
*h
, in
;
6469 if (!DECL_HAS_DEBUG_ARGS_P (from
))
6471 gcc_checking_assert (debug_args_for_decl
!= NULL
);
6472 in
.base
.from
= from
;
6473 h
= (struct tree_vec_map
*)
6474 htab_find_with_hash (debug_args_for_decl
, &in
, DECL_UID (from
));
6480 /* Insert a mapping FROM->empty vector of debug arguments in the value
6481 expression hashtable. */
6484 decl_debug_args_insert (tree from
)
6486 struct tree_vec_map
*h
;
6489 if (DECL_HAS_DEBUG_ARGS_P (from
))
6490 return decl_debug_args_lookup (from
);
6491 if (debug_args_for_decl
== NULL
)
6492 debug_args_for_decl
= htab_create_ggc (64, tree_vec_map_hash
,
6493 tree_vec_map_eq
, 0);
6494 h
= ggc_alloc_tree_vec_map ();
6495 h
->base
.from
= from
;
6497 loc
= htab_find_slot_with_hash (debug_args_for_decl
, h
, DECL_UID (from
),
6499 *(struct tree_vec_map
**) loc
= h
;
6500 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
6504 /* Hashing of types so that we don't make duplicates.
6505 The entry point is `type_hash_canon'. */
6507 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6508 with types in the TREE_VALUE slots), by adding the hash codes
6509 of the individual types. */
6512 type_hash_list (const_tree list
, hashval_t hashcode
)
6516 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6517 if (TREE_VALUE (tail
) != error_mark_node
)
6518 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
6524 /* These are the Hashtable callback functions. */
6526 /* Returns true iff the types are equivalent. */
6529 type_hash_eq (const void *va
, const void *vb
)
6531 const struct type_hash
*const a
= (const struct type_hash
*) va
,
6532 *const b
= (const struct type_hash
*) vb
;
6534 /* First test the things that are the same for all types. */
6535 if (a
->hash
!= b
->hash
6536 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6537 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6538 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6539 TYPE_ATTRIBUTES (b
->type
))
6540 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6541 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6544 /* Be careful about comparing arrays before and after the element type
6545 has been completed; don't compare TYPE_ALIGN unless both types are
6547 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6548 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6549 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6552 switch (TREE_CODE (a
->type
))
6557 case REFERENCE_TYPE
:
6562 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6565 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6566 && !(TYPE_VALUES (a
->type
)
6567 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6568 && TYPE_VALUES (b
->type
)
6569 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6570 && type_list_equal (TYPE_VALUES (a
->type
),
6571 TYPE_VALUES (b
->type
))))
6574 /* ... fall through ... */
6579 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6580 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6581 TYPE_MAX_VALUE (b
->type
)))
6582 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6583 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6584 TYPE_MIN_VALUE (b
->type
))));
6586 case FIXED_POINT_TYPE
:
6587 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6590 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6593 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6594 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6595 || (TYPE_ARG_TYPES (a
->type
)
6596 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6597 && TYPE_ARG_TYPES (b
->type
)
6598 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6599 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6600 TYPE_ARG_TYPES (b
->type
)))))
6604 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6608 case QUAL_UNION_TYPE
:
6609 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6610 || (TYPE_FIELDS (a
->type
)
6611 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6612 && TYPE_FIELDS (b
->type
)
6613 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6614 && type_list_equal (TYPE_FIELDS (a
->type
),
6615 TYPE_FIELDS (b
->type
))));
6618 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6619 || (TYPE_ARG_TYPES (a
->type
)
6620 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6621 && TYPE_ARG_TYPES (b
->type
)
6622 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6623 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6624 TYPE_ARG_TYPES (b
->type
))))
6632 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6633 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6638 /* Return the cached hash value. */
6641 type_hash_hash (const void *item
)
6643 return ((const struct type_hash
*) item
)->hash
;
6646 /* Look in the type hash table for a type isomorphic to TYPE.
6647 If one is found, return it. Otherwise return 0. */
6650 type_hash_lookup (hashval_t hashcode
, tree type
)
6652 struct type_hash
*h
, in
;
6654 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6655 must call that routine before comparing TYPE_ALIGNs. */
6661 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
6668 /* Add an entry to the type-hash-table
6669 for a type TYPE whose hash code is HASHCODE. */
6672 type_hash_add (hashval_t hashcode
, tree type
)
6674 struct type_hash
*h
;
6677 h
= ggc_alloc_type_hash ();
6680 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
6684 /* Given TYPE, and HASHCODE its hash code, return the canonical
6685 object for an identical type if one already exists.
6686 Otherwise, return TYPE, and record it as the canonical object.
6688 To use this function, first create a type of the sort you want.
6689 Then compute its hash code from the fields of the type that
6690 make it different from other similar types.
6691 Then call this function and use the value. */
6694 type_hash_canon (unsigned int hashcode
, tree type
)
6698 /* The hash table only contains main variants, so ensure that's what we're
6700 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6702 /* See if the type is in the hash table already. If so, return it.
6703 Otherwise, add the type. */
6704 t1
= type_hash_lookup (hashcode
, type
);
6707 if (GATHER_STATISTICS
)
6709 tree_code_counts
[(int) TREE_CODE (type
)]--;
6710 tree_node_counts
[(int) t_kind
]--;
6711 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type_non_common
);
6717 type_hash_add (hashcode
, type
);
6722 /* See if the data pointed to by the type hash table is marked. We consider
6723 it marked if the type is marked or if a debug type number or symbol
6724 table entry has been made for the type. */
6727 type_hash_marked_p (const void *p
)
6729 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
6731 return ggc_marked_p (type
);
6735 print_type_hash_statistics (void)
6737 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6738 (long) htab_size (type_hash_table
),
6739 (long) htab_elements (type_hash_table
),
6740 htab_collisions (type_hash_table
));
6743 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6744 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6745 by adding the hash codes of the individual attributes. */
6748 attribute_hash_list (const_tree list
, hashval_t hashcode
)
6752 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6753 /* ??? Do we want to add in TREE_VALUE too? */
6754 hashcode
= iterative_hash_object
6755 (IDENTIFIER_HASH_VALUE (get_attribute_name (tail
)), hashcode
);
6759 /* Given two lists of attributes, return true if list l2 is
6760 equivalent to l1. */
6763 attribute_list_equal (const_tree l1
, const_tree l2
)
6768 return attribute_list_contained (l1
, l2
)
6769 && attribute_list_contained (l2
, l1
);
6772 /* Given two lists of attributes, return true if list L2 is
6773 completely contained within L1. */
6774 /* ??? This would be faster if attribute names were stored in a canonicalized
6775 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6776 must be used to show these elements are equivalent (which they are). */
6777 /* ??? It's not clear that attributes with arguments will always be handled
6781 attribute_list_contained (const_tree l1
, const_tree l2
)
6785 /* First check the obvious, maybe the lists are identical. */
6789 /* Maybe the lists are similar. */
6790 for (t1
= l1
, t2
= l2
;
6792 && get_attribute_name (t1
) == get_attribute_name (t2
)
6793 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
6794 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6797 /* Maybe the lists are equal. */
6798 if (t1
== 0 && t2
== 0)
6801 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
6804 /* This CONST_CAST is okay because lookup_attribute does not
6805 modify its argument and the return value is assigned to a
6807 for (attr
= lookup_ident_attribute (get_attribute_name (t2
),
6808 CONST_CAST_TREE (l1
));
6809 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
6810 attr
= lookup_ident_attribute (get_attribute_name (t2
),
6814 if (attr
== NULL_TREE
)
6821 /* Given two lists of types
6822 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6823 return 1 if the lists contain the same types in the same order.
6824 Also, the TREE_PURPOSEs must match. */
6827 type_list_equal (const_tree l1
, const_tree l2
)
6831 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6832 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6833 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6834 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6835 && (TREE_TYPE (TREE_PURPOSE (t1
))
6836 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6842 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6843 given by TYPE. If the argument list accepts variable arguments,
6844 then this function counts only the ordinary arguments. */
6847 type_num_arguments (const_tree type
)
6852 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
6853 /* If the function does not take a variable number of arguments,
6854 the last element in the list will have type `void'. */
6855 if (VOID_TYPE_P (TREE_VALUE (t
)))
6863 /* Nonzero if integer constants T1 and T2
6864 represent the same constant value. */
6867 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6872 if (t1
== 0 || t2
== 0)
6875 if (TREE_CODE (t1
) == INTEGER_CST
6876 && TREE_CODE (t2
) == INTEGER_CST
6877 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6878 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
6884 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6885 The precise way of comparison depends on their data type. */
6888 tree_int_cst_lt (const_tree t1
, const_tree t2
)
6893 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
6895 int t1_sgn
= tree_int_cst_sgn (t1
);
6896 int t2_sgn
= tree_int_cst_sgn (t2
);
6898 if (t1_sgn
< t2_sgn
)
6900 else if (t1_sgn
> t2_sgn
)
6902 /* Otherwise, both are non-negative, so we compare them as
6903 unsigned just in case one of them would overflow a signed
6906 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
6907 return INT_CST_LT (t1
, t2
);
6909 return INT_CST_LT_UNSIGNED (t1
, t2
);
6912 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6915 tree_int_cst_compare (const_tree t1
, const_tree t2
)
6917 if (tree_int_cst_lt (t1
, t2
))
6919 else if (tree_int_cst_lt (t2
, t1
))
6925 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6926 the host. If POS is zero, the value can be represented in a single
6927 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6928 be represented in a single unsigned HOST_WIDE_INT. */
6931 host_integerp (const_tree t
, int pos
)
6936 return (TREE_CODE (t
) == INTEGER_CST
6937 && ((TREE_INT_CST_HIGH (t
) == 0
6938 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
6939 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
6940 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
6941 && !TYPE_UNSIGNED (TREE_TYPE (t
)))
6942 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
6945 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6946 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6947 be non-negative. We must be able to satisfy the above conditions. */
6950 tree_low_cst (const_tree t
, int pos
)
6952 gcc_assert (host_integerp (t
, pos
));
6953 return TREE_INT_CST_LOW (t
);
6956 /* Return the HOST_WIDE_INT least significant bits of T, a sizetype
6957 kind INTEGER_CST. This makes sure to properly sign-extend the
6961 size_low_cst (const_tree t
)
6963 double_int d
= tree_to_double_int (t
);
6964 return d
.sext (TYPE_PRECISION (TREE_TYPE (t
))).low
;
6967 /* Return the most significant (sign) bit of T. */
6970 tree_int_cst_sign_bit (const_tree t
)
6972 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
6973 unsigned HOST_WIDE_INT w
;
6975 if (bitno
< HOST_BITS_PER_WIDE_INT
)
6976 w
= TREE_INT_CST_LOW (t
);
6979 w
= TREE_INT_CST_HIGH (t
);
6980 bitno
-= HOST_BITS_PER_WIDE_INT
;
6983 return (w
>> bitno
) & 1;
6986 /* Return an indication of the sign of the integer constant T.
6987 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6988 Note that -1 will never be returned if T's type is unsigned. */
6991 tree_int_cst_sgn (const_tree t
)
6993 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
6995 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6997 else if (TREE_INT_CST_HIGH (t
) < 0)
7003 /* Return the minimum number of bits needed to represent VALUE in a
7004 signed or unsigned type, UNSIGNEDP says which. */
7007 tree_int_cst_min_precision (tree value
, bool unsignedp
)
7009 /* If the value is negative, compute its negative minus 1. The latter
7010 adjustment is because the absolute value of the largest negative value
7011 is one larger than the largest positive value. This is equivalent to
7012 a bit-wise negation, so use that operation instead. */
7014 if (tree_int_cst_sgn (value
) < 0)
7015 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
7017 /* Return the number of bits needed, taking into account the fact
7018 that we need one more bit for a signed than unsigned type.
7019 If value is 0 or -1, the minimum precision is 1 no matter
7020 whether unsignedp is true or false. */
7022 if (integer_zerop (value
))
7025 return tree_floor_log2 (value
) + 1 + !unsignedp
;
7028 /* Compare two constructor-element-type constants. Return 1 if the lists
7029 are known to be equal; otherwise return 0. */
7032 simple_cst_list_equal (const_tree l1
, const_tree l2
)
7034 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
7036 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
7039 l1
= TREE_CHAIN (l1
);
7040 l2
= TREE_CHAIN (l2
);
7046 /* Return truthvalue of whether T1 is the same tree structure as T2.
7047 Return 1 if they are the same.
7048 Return 0 if they are understandably different.
7049 Return -1 if either contains tree structure not understood by
7053 simple_cst_equal (const_tree t1
, const_tree t2
)
7055 enum tree_code code1
, code2
;
7061 if (t1
== 0 || t2
== 0)
7064 code1
= TREE_CODE (t1
);
7065 code2
= TREE_CODE (t2
);
7067 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
7069 if (CONVERT_EXPR_CODE_P (code2
)
7070 || code2
== NON_LVALUE_EXPR
)
7071 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7073 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
7076 else if (CONVERT_EXPR_CODE_P (code2
)
7077 || code2
== NON_LVALUE_EXPR
)
7078 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
7086 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
7087 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
7090 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
7093 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
7096 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
7097 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
7098 TREE_STRING_LENGTH (t1
)));
7102 unsigned HOST_WIDE_INT idx
;
7103 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
7104 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
7106 if (vec_safe_length (v1
) != vec_safe_length (v2
))
7109 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
7110 /* ??? Should we handle also fields here? */
7111 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
7117 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7120 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
7123 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
7126 const_tree arg1
, arg2
;
7127 const_call_expr_arg_iterator iter1
, iter2
;
7128 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
7129 arg2
= first_const_call_expr_arg (t2
, &iter2
);
7131 arg1
= next_const_call_expr_arg (&iter1
),
7132 arg2
= next_const_call_expr_arg (&iter2
))
7134 cmp
= simple_cst_equal (arg1
, arg2
);
7138 return arg1
== arg2
;
7142 /* Special case: if either target is an unallocated VAR_DECL,
7143 it means that it's going to be unified with whatever the
7144 TARGET_EXPR is really supposed to initialize, so treat it
7145 as being equivalent to anything. */
7146 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
7147 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
7148 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
7149 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
7150 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
7151 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
7154 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7159 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
7161 case WITH_CLEANUP_EXPR
:
7162 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7166 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
7169 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
7170 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7184 /* This general rule works for most tree codes. All exceptions should be
7185 handled above. If this is a language-specific tree code, we can't
7186 trust what might be in the operand, so say we don't know
7188 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
7191 switch (TREE_CODE_CLASS (code1
))
7195 case tcc_comparison
:
7196 case tcc_expression
:
7200 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
7202 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
7214 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7215 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7216 than U, respectively. */
7219 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
7221 if (tree_int_cst_sgn (t
) < 0)
7223 else if (TREE_INT_CST_HIGH (t
) != 0)
7225 else if (TREE_INT_CST_LOW (t
) == u
)
7227 else if (TREE_INT_CST_LOW (t
) < u
)
7233 /* Return true if SIZE represents a constant size that is in bounds of
7234 what the middle-end and the backend accepts (covering not more than
7235 half of the address-space). */
7238 valid_constant_size_p (const_tree size
)
7240 if (! host_integerp (size
, 1)
7241 || TREE_OVERFLOW (size
)
7242 || tree_int_cst_sign_bit (size
) != 0)
7247 /* Return the precision of the type, or for a complex or vector type the
7248 precision of the type of its elements. */
7251 element_precision (const_tree type
)
7253 enum tree_code code
= TREE_CODE (type
);
7254 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7255 type
= TREE_TYPE (type
);
7257 return TYPE_PRECISION (type
);
7260 /* Return true if CODE represents an associative tree code. Otherwise
7263 associative_tree_code (enum tree_code code
)
7282 /* Return true if CODE represents a commutative tree code. Otherwise
7285 commutative_tree_code (enum tree_code code
)
7291 case MULT_HIGHPART_EXPR
:
7299 case UNORDERED_EXPR
:
7303 case TRUTH_AND_EXPR
:
7304 case TRUTH_XOR_EXPR
:
7306 case WIDEN_MULT_EXPR
:
7307 case VEC_WIDEN_MULT_HI_EXPR
:
7308 case VEC_WIDEN_MULT_LO_EXPR
:
7309 case VEC_WIDEN_MULT_EVEN_EXPR
:
7310 case VEC_WIDEN_MULT_ODD_EXPR
:
7319 /* Return true if CODE represents a ternary tree code for which the
7320 first two operands are commutative. Otherwise return false. */
7322 commutative_ternary_tree_code (enum tree_code code
)
7326 case WIDEN_MULT_PLUS_EXPR
:
7327 case WIDEN_MULT_MINUS_EXPR
:
7336 /* Generate a hash value for an expression. This can be used iteratively
7337 by passing a previous result as the VAL argument.
7339 This function is intended to produce the same hash for expressions which
7340 would compare equal using operand_equal_p. */
7343 iterative_hash_expr (const_tree t
, hashval_t val
)
7346 enum tree_code code
;
7350 return iterative_hash_hashval_t (0, val
);
7352 code
= TREE_CODE (t
);
7356 /* Alas, constants aren't shared, so we can't rely on pointer
7359 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
7360 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
7363 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
7365 return iterative_hash_hashval_t (val2
, val
);
7369 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
7371 return iterative_hash_hashval_t (val2
, val
);
7374 return iterative_hash (TREE_STRING_POINTER (t
),
7375 TREE_STRING_LENGTH (t
), val
);
7377 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
7378 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
7382 for (i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
7383 val
= iterative_hash_expr (VECTOR_CST_ELT (t
, i
), val
);
7387 /* We can just compare by pointer. */
7388 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
7389 case PLACEHOLDER_EXPR
:
7390 /* The node itself doesn't matter. */
7393 /* A list of expressions, for a CALL_EXPR or as the elements of a
7395 for (; t
; t
= TREE_CHAIN (t
))
7396 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
7400 unsigned HOST_WIDE_INT idx
;
7402 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
7404 val
= iterative_hash_expr (field
, val
);
7405 val
= iterative_hash_expr (value
, val
);
7410 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7411 Otherwise nodes that compare equal according to operand_equal_p might
7412 get different hash codes. However, don't do this for machine specific
7413 or front end builtins, since the function code is overloaded in those
7415 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
7416 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t
)))
7418 t
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
7419 code
= TREE_CODE (t
);
7423 tclass
= TREE_CODE_CLASS (code
);
7425 if (tclass
== tcc_declaration
)
7427 /* DECL's have a unique ID */
7428 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
7432 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
7434 val
= iterative_hash_object (code
, val
);
7436 /* Don't hash the type, that can lead to having nodes which
7437 compare equal according to operand_equal_p, but which
7438 have different hash codes. */
7439 if (CONVERT_EXPR_CODE_P (code
)
7440 || code
== NON_LVALUE_EXPR
)
7442 /* Make sure to include signness in the hash computation. */
7443 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
7444 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
7447 else if (commutative_tree_code (code
))
7449 /* It's a commutative expression. We want to hash it the same
7450 however it appears. We do this by first hashing both operands
7451 and then rehashing based on the order of their independent
7453 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
7454 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
7458 t
= one
, one
= two
, two
= t
;
7460 val
= iterative_hash_hashval_t (one
, val
);
7461 val
= iterative_hash_hashval_t (two
, val
);
7464 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
7465 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
7471 /* Generate a hash value for a pair of expressions. This can be used
7472 iteratively by passing a previous result as the VAL argument.
7474 The same hash value is always returned for a given pair of expressions,
7475 regardless of the order in which they are presented. This is useful in
7476 hashing the operands of commutative functions. */
7479 iterative_hash_exprs_commutative (const_tree t1
,
7480 const_tree t2
, hashval_t val
)
7482 hashval_t one
= iterative_hash_expr (t1
, 0);
7483 hashval_t two
= iterative_hash_expr (t2
, 0);
7487 t
= one
, one
= two
, two
= t
;
7488 val
= iterative_hash_hashval_t (one
, val
);
7489 val
= iterative_hash_hashval_t (two
, val
);
7494 /* Constructors for pointer, array and function types.
7495 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7496 constructed by language-dependent code, not here.) */
7498 /* Construct, lay out and return the type of pointers to TO_TYPE with
7499 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7500 reference all of memory. If such a type has already been
7501 constructed, reuse it. */
7504 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
7509 if (to_type
== error_mark_node
)
7510 return error_mark_node
;
7512 /* If the pointed-to type has the may_alias attribute set, force
7513 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7514 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7515 can_alias_all
= true;
7517 /* In some cases, languages will have things that aren't a POINTER_TYPE
7518 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7519 In that case, return that type without regard to the rest of our
7522 ??? This is a kludge, but consistent with the way this function has
7523 always operated and there doesn't seem to be a good way to avoid this
7525 if (TYPE_POINTER_TO (to_type
) != 0
7526 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7527 return TYPE_POINTER_TO (to_type
);
7529 /* First, if we already have a type for pointers to TO_TYPE and it's
7530 the proper mode, use it. */
7531 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7532 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7535 t
= make_node (POINTER_TYPE
);
7537 TREE_TYPE (t
) = to_type
;
7538 SET_TYPE_MODE (t
, mode
);
7539 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7540 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7541 TYPE_POINTER_TO (to_type
) = t
;
7543 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7544 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7545 else if (TYPE_CANONICAL (to_type
) != to_type
)
7547 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7548 mode
, can_alias_all
);
7550 /* Lay out the type. This function has many callers that are concerned
7551 with expression-construction, and this simplifies them all. */
7557 /* By default build pointers in ptr_mode. */
7560 build_pointer_type (tree to_type
)
7562 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7563 : TYPE_ADDR_SPACE (to_type
);
7564 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7565 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7568 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7571 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
7576 if (to_type
== error_mark_node
)
7577 return error_mark_node
;
7579 /* If the pointed-to type has the may_alias attribute set, force
7580 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7581 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7582 can_alias_all
= true;
7584 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7585 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7586 In that case, return that type without regard to the rest of our
7589 ??? This is a kludge, but consistent with the way this function has
7590 always operated and there doesn't seem to be a good way to avoid this
7592 if (TYPE_REFERENCE_TO (to_type
) != 0
7593 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7594 return TYPE_REFERENCE_TO (to_type
);
7596 /* First, if we already have a type for pointers to TO_TYPE and it's
7597 the proper mode, use it. */
7598 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7599 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7602 t
= make_node (REFERENCE_TYPE
);
7604 TREE_TYPE (t
) = to_type
;
7605 SET_TYPE_MODE (t
, mode
);
7606 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7607 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7608 TYPE_REFERENCE_TO (to_type
) = t
;
7610 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7611 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7612 else if (TYPE_CANONICAL (to_type
) != to_type
)
7614 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7615 mode
, can_alias_all
);
7623 /* Build the node for the type of references-to-TO_TYPE by default
7627 build_reference_type (tree to_type
)
7629 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7630 : TYPE_ADDR_SPACE (to_type
);
7631 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7632 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7635 /* Build a type that is compatible with t but has no cv quals anywhere
7638 const char *const *const * -> char ***. */
7641 build_type_no_quals (tree t
)
7643 switch (TREE_CODE (t
))
7646 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7648 TYPE_REF_CAN_ALIAS_ALL (t
));
7649 case REFERENCE_TYPE
:
7651 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7653 TYPE_REF_CAN_ALIAS_ALL (t
));
7655 return TYPE_MAIN_VARIANT (t
);
7659 #define MAX_INT_CACHED_PREC \
7660 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7661 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7663 /* Builds a signed or unsigned integer type of precision PRECISION.
7664 Used for C bitfields whose precision does not match that of
7665 built-in target types. */
7667 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7673 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7675 if (precision
<= MAX_INT_CACHED_PREC
)
7677 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7682 itype
= make_node (INTEGER_TYPE
);
7683 TYPE_PRECISION (itype
) = precision
;
7686 fixup_unsigned_type (itype
);
7688 fixup_signed_type (itype
);
7691 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
7692 ret
= type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
7693 if (precision
<= MAX_INT_CACHED_PREC
)
7694 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7699 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7700 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7701 is true, reuse such a type that has already been constructed. */
7704 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7706 tree itype
= make_node (INTEGER_TYPE
);
7707 hashval_t hashcode
= 0;
7709 TREE_TYPE (itype
) = type
;
7711 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7712 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7714 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7715 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7716 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7717 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7718 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
7719 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7724 if ((TYPE_MIN_VALUE (itype
)
7725 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7726 || (TYPE_MAX_VALUE (itype
)
7727 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7729 /* Since we cannot reliably merge this type, we need to compare it using
7730 structural equality checks. */
7731 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7735 hashcode
= iterative_hash_expr (TYPE_MIN_VALUE (itype
), hashcode
);
7736 hashcode
= iterative_hash_expr (TYPE_MAX_VALUE (itype
), hashcode
);
7737 hashcode
= iterative_hash_hashval_t (TYPE_HASH (type
), hashcode
);
7738 itype
= type_hash_canon (hashcode
, itype
);
7743 /* Wrapper around build_range_type_1 with SHARED set to true. */
7746 build_range_type (tree type
, tree lowval
, tree highval
)
7748 return build_range_type_1 (type
, lowval
, highval
, true);
7751 /* Wrapper around build_range_type_1 with SHARED set to false. */
7754 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7756 return build_range_type_1 (type
, lowval
, highval
, false);
7759 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7760 MAXVAL should be the maximum value in the domain
7761 (one less than the length of the array).
7763 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7764 We don't enforce this limit, that is up to caller (e.g. language front end).
7765 The limit exists because the result is a signed type and we don't handle
7766 sizes that use more than one HOST_WIDE_INT. */
7769 build_index_type (tree maxval
)
7771 return build_range_type (sizetype
, size_zero_node
, maxval
);
7774 /* Return true if the debug information for TYPE, a subtype, should be emitted
7775 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7776 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7777 debug info and doesn't reflect the source code. */
7780 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7782 tree base_type
= TREE_TYPE (type
), low
, high
;
7784 /* Subrange types have a base type which is an integral type. */
7785 if (!INTEGRAL_TYPE_P (base_type
))
7788 /* Get the real bounds of the subtype. */
7789 if (lang_hooks
.types
.get_subrange_bounds
)
7790 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7793 low
= TYPE_MIN_VALUE (type
);
7794 high
= TYPE_MAX_VALUE (type
);
7797 /* If the type and its base type have the same representation and the same
7798 name, then the type is not a subrange but a copy of the base type. */
7799 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7800 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7801 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7802 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7803 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
7805 tree type_name
= TYPE_NAME (type
);
7806 tree base_type_name
= TYPE_NAME (base_type
);
7808 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
7809 type_name
= DECL_NAME (type_name
);
7811 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
7812 base_type_name
= DECL_NAME (base_type_name
);
7814 if (type_name
== base_type_name
)
7825 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7826 and number of elements specified by the range of values of INDEX_TYPE.
7827 If SHARED is true, reuse such a type that has already been constructed. */
7830 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
7834 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7836 error ("arrays of functions are not meaningful");
7837 elt_type
= integer_type_node
;
7840 t
= make_node (ARRAY_TYPE
);
7841 TREE_TYPE (t
) = elt_type
;
7842 TYPE_DOMAIN (t
) = index_type
;
7843 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7846 /* If the element type is incomplete at this point we get marked for
7847 structural equality. Do not record these types in the canonical
7849 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
7854 hashval_t hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), 0);
7856 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
7857 t
= type_hash_canon (hashcode
, t
);
7860 if (TYPE_CANONICAL (t
) == t
)
7862 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7863 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
7864 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7865 else if (TYPE_CANONICAL (elt_type
) != elt_type
7866 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7868 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7870 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7877 /* Wrapper around build_array_type_1 with SHARED set to true. */
7880 build_array_type (tree elt_type
, tree index_type
)
7882 return build_array_type_1 (elt_type
, index_type
, true);
7885 /* Wrapper around build_array_type_1 with SHARED set to false. */
7888 build_nonshared_array_type (tree elt_type
, tree index_type
)
7890 return build_array_type_1 (elt_type
, index_type
, false);
7893 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7897 build_array_type_nelts (tree elt_type
, unsigned HOST_WIDE_INT nelts
)
7899 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
7902 /* Recursively examines the array elements of TYPE, until a non-array
7903 element type is found. */
7906 strip_array_types (tree type
)
7908 while (TREE_CODE (type
) == ARRAY_TYPE
)
7909 type
= TREE_TYPE (type
);
7914 /* Computes the canonical argument types from the argument type list
7917 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7918 on entry to this function, or if any of the ARGTYPES are
7921 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7922 true on entry to this function, or if any of the ARGTYPES are
7925 Returns a canonical argument list, which may be ARGTYPES when the
7926 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7927 true) or would not differ from ARGTYPES. */
7930 maybe_canonicalize_argtypes (tree argtypes
,
7931 bool *any_structural_p
,
7932 bool *any_noncanonical_p
)
7935 bool any_noncanonical_argtypes_p
= false;
7937 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7939 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7940 /* Fail gracefully by stating that the type is structural. */
7941 *any_structural_p
= true;
7942 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7943 *any_structural_p
= true;
7944 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7945 || TREE_PURPOSE (arg
))
7946 /* If the argument has a default argument, we consider it
7947 non-canonical even though the type itself is canonical.
7948 That way, different variants of function and method types
7949 with default arguments will all point to the variant with
7950 no defaults as their canonical type. */
7951 any_noncanonical_argtypes_p
= true;
7954 if (*any_structural_p
)
7957 if (any_noncanonical_argtypes_p
)
7959 /* Build the canonical list of argument types. */
7960 tree canon_argtypes
= NULL_TREE
;
7961 bool is_void
= false;
7963 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7965 if (arg
== void_list_node
)
7968 canon_argtypes
= tree_cons (NULL_TREE
,
7969 TYPE_CANONICAL (TREE_VALUE (arg
)),
7973 canon_argtypes
= nreverse (canon_argtypes
);
7975 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7977 /* There is a non-canonical type. */
7978 *any_noncanonical_p
= true;
7979 return canon_argtypes
;
7982 /* The canonical argument types are the same as ARGTYPES. */
7986 /* Construct, lay out and return
7987 the type of functions returning type VALUE_TYPE
7988 given arguments of types ARG_TYPES.
7989 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7990 are data type nodes for the arguments of the function.
7991 If such a type has already been constructed, reuse it. */
7994 build_function_type (tree value_type
, tree arg_types
)
7997 hashval_t hashcode
= 0;
7998 bool any_structural_p
, any_noncanonical_p
;
7999 tree canon_argtypes
;
8001 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
8003 error ("function return type cannot be function");
8004 value_type
= integer_type_node
;
8007 /* Make a node of the sort we want. */
8008 t
= make_node (FUNCTION_TYPE
);
8009 TREE_TYPE (t
) = value_type
;
8010 TYPE_ARG_TYPES (t
) = arg_types
;
8012 /* If we already have such a type, use the old one. */
8013 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
8014 hashcode
= type_hash_list (arg_types
, hashcode
);
8015 t
= type_hash_canon (hashcode
, t
);
8017 /* Set up the canonical type. */
8018 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
8019 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
8020 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
8022 &any_noncanonical_p
);
8023 if (any_structural_p
)
8024 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8025 else if (any_noncanonical_p
)
8026 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
8029 if (!COMPLETE_TYPE_P (t
))
8034 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP and the
8035 return value if SKIP_RETURN is true. */
8038 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
,
8041 tree new_type
= NULL
;
8042 tree args
, new_args
= NULL
, t
;
8046 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
8047 args
= TREE_CHAIN (args
), i
++)
8048 if (!args_to_skip
|| !bitmap_bit_p (args_to_skip
, i
))
8049 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
8051 new_reversed
= nreverse (new_args
);
8055 TREE_CHAIN (new_args
) = void_list_node
;
8057 new_reversed
= void_list_node
;
8060 /* Use copy_node to preserve as much as possible from original type
8061 (debug info, attribute lists etc.)
8062 Exception is METHOD_TYPEs must have THIS argument.
8063 When we are asked to remove it, we need to build new FUNCTION_TYPE
8065 if (TREE_CODE (orig_type
) != METHOD_TYPE
8067 || !bitmap_bit_p (args_to_skip
, 0))
8069 new_type
= build_distinct_type_copy (orig_type
);
8070 TYPE_ARG_TYPES (new_type
) = new_reversed
;
8075 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
8077 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
8081 TREE_TYPE (new_type
) = void_type_node
;
8083 /* This is a new type, not a copy of an old type. Need to reassociate
8084 variants. We can handle everything except the main variant lazily. */
8085 t
= TYPE_MAIN_VARIANT (orig_type
);
8088 t
= build_function_type_skip_args (t
, args_to_skip
, skip_return
);
8089 TYPE_MAIN_VARIANT (new_type
) = t
;
8090 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
8091 TYPE_NEXT_VARIANT (t
) = new_type
;
8095 TYPE_MAIN_VARIANT (new_type
) = new_type
;
8096 TYPE_NEXT_VARIANT (new_type
) = NULL
;
8102 /* Build variant of function decl ORIG_DECL skipping ARGS_TO_SKIP and the
8103 return value if SKIP_RETURN is true.
8105 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
8106 linked by TREE_CHAIN directly. The caller is responsible for eliminating
8107 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
8110 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
,
8113 tree new_decl
= copy_node (orig_decl
);
8116 new_type
= TREE_TYPE (orig_decl
);
8117 if (prototype_p (new_type
)
8118 || (skip_return
&& !VOID_TYPE_P (TREE_TYPE (new_type
))))
8120 = build_function_type_skip_args (new_type
, args_to_skip
, skip_return
);
8121 TREE_TYPE (new_decl
) = new_type
;
8123 /* For declarations setting DECL_VINDEX (i.e. methods)
8124 we expect first argument to be THIS pointer. */
8125 if (args_to_skip
&& bitmap_bit_p (args_to_skip
, 0))
8126 DECL_VINDEX (new_decl
) = NULL_TREE
;
8128 /* When signature changes, we need to clear builtin info. */
8129 if (DECL_BUILT_IN (new_decl
)
8131 && !bitmap_empty_p (args_to_skip
))
8133 DECL_BUILT_IN_CLASS (new_decl
) = NOT_BUILT_IN
;
8134 DECL_FUNCTION_CODE (new_decl
) = (enum built_in_function
) 0;
8139 /* Build a function type. The RETURN_TYPE is the type returned by the
8140 function. If VAARGS is set, no void_type_node is appended to the
8141 the list. ARGP must be always be terminated be a NULL_TREE. */
8144 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
8148 t
= va_arg (argp
, tree
);
8149 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
8150 args
= tree_cons (NULL_TREE
, t
, args
);
8155 if (args
!= NULL_TREE
)
8156 args
= nreverse (args
);
8157 gcc_assert (last
!= void_list_node
);
8159 else if (args
== NULL_TREE
)
8160 args
= void_list_node
;
8164 args
= nreverse (args
);
8165 TREE_CHAIN (last
) = void_list_node
;
8167 args
= build_function_type (return_type
, args
);
8172 /* Build a function type. The RETURN_TYPE is the type returned by the
8173 function. If additional arguments are provided, they are
8174 additional argument types. The list of argument types must always
8175 be terminated by NULL_TREE. */
8178 build_function_type_list (tree return_type
, ...)
8183 va_start (p
, return_type
);
8184 args
= build_function_type_list_1 (false, return_type
, p
);
8189 /* Build a variable argument function type. The RETURN_TYPE is the
8190 type returned by the function. If additional arguments are provided,
8191 they are additional argument types. The list of argument types must
8192 always be terminated by NULL_TREE. */
8195 build_varargs_function_type_list (tree return_type
, ...)
8200 va_start (p
, return_type
);
8201 args
= build_function_type_list_1 (true, return_type
, p
);
8207 /* Build a function type. RETURN_TYPE is the type returned by the
8208 function; VAARGS indicates whether the function takes varargs. The
8209 function takes N named arguments, the types of which are provided in
8213 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
8217 tree t
= vaargs
? NULL_TREE
: void_list_node
;
8219 for (i
= n
- 1; i
>= 0; i
--)
8220 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
8222 return build_function_type (return_type
, t
);
8225 /* Build a function type. RETURN_TYPE is the type returned by the
8226 function. The function takes N named arguments, the types of which
8227 are provided in ARG_TYPES. */
8230 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8232 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
8235 /* Build a variable argument function type. RETURN_TYPE is the type
8236 returned by the function. The function takes N named arguments, the
8237 types of which are provided in ARG_TYPES. */
8240 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8242 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
8245 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8246 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8247 for the method. An implicit additional parameter (of type
8248 pointer-to-BASETYPE) is added to the ARGTYPES. */
8251 build_method_type_directly (tree basetype
,
8258 bool any_structural_p
, any_noncanonical_p
;
8259 tree canon_argtypes
;
8261 /* Make a node of the sort we want. */
8262 t
= make_node (METHOD_TYPE
);
8264 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8265 TREE_TYPE (t
) = rettype
;
8266 ptype
= build_pointer_type (basetype
);
8268 /* The actual arglist for this function includes a "hidden" argument
8269 which is "this". Put it into the list of argument types. */
8270 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
8271 TYPE_ARG_TYPES (t
) = argtypes
;
8273 /* If we already have such a type, use the old one. */
8274 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8275 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
8276 hashcode
= type_hash_list (argtypes
, hashcode
);
8277 t
= type_hash_canon (hashcode
, t
);
8279 /* Set up the canonical type. */
8281 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8282 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
8284 = (TYPE_CANONICAL (basetype
) != basetype
8285 || TYPE_CANONICAL (rettype
) != rettype
);
8286 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
8288 &any_noncanonical_p
);
8289 if (any_structural_p
)
8290 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8291 else if (any_noncanonical_p
)
8293 = build_method_type_directly (TYPE_CANONICAL (basetype
),
8294 TYPE_CANONICAL (rettype
),
8296 if (!COMPLETE_TYPE_P (t
))
8302 /* Construct, lay out and return the type of methods belonging to class
8303 BASETYPE and whose arguments and values are described by TYPE.
8304 If that type exists already, reuse it.
8305 TYPE must be a FUNCTION_TYPE node. */
8308 build_method_type (tree basetype
, tree type
)
8310 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
8312 return build_method_type_directly (basetype
,
8314 TYPE_ARG_TYPES (type
));
8317 /* Construct, lay out and return the type of offsets to a value
8318 of type TYPE, within an object of type BASETYPE.
8319 If a suitable offset type exists already, reuse it. */
8322 build_offset_type (tree basetype
, tree type
)
8325 hashval_t hashcode
= 0;
8327 /* Make a node of the sort we want. */
8328 t
= make_node (OFFSET_TYPE
);
8330 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8331 TREE_TYPE (t
) = type
;
8333 /* If we already have such a type, use the old one. */
8334 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8335 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
8336 t
= type_hash_canon (hashcode
, t
);
8338 if (!COMPLETE_TYPE_P (t
))
8341 if (TYPE_CANONICAL (t
) == t
)
8343 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8344 || TYPE_STRUCTURAL_EQUALITY_P (type
))
8345 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8346 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
8347 || TYPE_CANONICAL (type
) != type
)
8349 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
8350 TYPE_CANONICAL (type
));
8356 /* Create a complex type whose components are COMPONENT_TYPE. */
8359 build_complex_type (tree component_type
)
8364 gcc_assert (INTEGRAL_TYPE_P (component_type
)
8365 || SCALAR_FLOAT_TYPE_P (component_type
)
8366 || FIXED_POINT_TYPE_P (component_type
));
8368 /* Make a node of the sort we want. */
8369 t
= make_node (COMPLEX_TYPE
);
8371 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
8373 /* If we already have such a type, use the old one. */
8374 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
8375 t
= type_hash_canon (hashcode
, t
);
8377 if (!COMPLETE_TYPE_P (t
))
8380 if (TYPE_CANONICAL (t
) == t
)
8382 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
8383 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8384 else if (TYPE_CANONICAL (component_type
) != component_type
)
8386 = build_complex_type (TYPE_CANONICAL (component_type
));
8389 /* We need to create a name, since complex is a fundamental type. */
8390 if (! TYPE_NAME (t
))
8393 if (component_type
== char_type_node
)
8394 name
= "complex char";
8395 else if (component_type
== signed_char_type_node
)
8396 name
= "complex signed char";
8397 else if (component_type
== unsigned_char_type_node
)
8398 name
= "complex unsigned char";
8399 else if (component_type
== short_integer_type_node
)
8400 name
= "complex short int";
8401 else if (component_type
== short_unsigned_type_node
)
8402 name
= "complex short unsigned int";
8403 else if (component_type
== integer_type_node
)
8404 name
= "complex int";
8405 else if (component_type
== unsigned_type_node
)
8406 name
= "complex unsigned int";
8407 else if (component_type
== long_integer_type_node
)
8408 name
= "complex long int";
8409 else if (component_type
== long_unsigned_type_node
)
8410 name
= "complex long unsigned int";
8411 else if (component_type
== long_long_integer_type_node
)
8412 name
= "complex long long int";
8413 else if (component_type
== long_long_unsigned_type_node
)
8414 name
= "complex long long unsigned int";
8419 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
8420 get_identifier (name
), t
);
8423 return build_qualified_type (t
, TYPE_QUALS (component_type
));
8426 /* If TYPE is a real or complex floating-point type and the target
8427 does not directly support arithmetic on TYPE then return the wider
8428 type to be used for arithmetic on TYPE. Otherwise, return
8432 excess_precision_type (tree type
)
8434 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
8436 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
8437 switch (TREE_CODE (type
))
8440 switch (flt_eval_method
)
8443 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
8444 return double_type_node
;
8447 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
8448 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
8449 return long_double_type_node
;
8456 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
8458 switch (flt_eval_method
)
8461 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
8462 return complex_double_type_node
;
8465 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
8466 || (TYPE_MODE (TREE_TYPE (type
))
8467 == TYPE_MODE (double_type_node
)))
8468 return complex_long_double_type_node
;
8481 /* Return OP, stripped of any conversions to wider types as much as is safe.
8482 Converting the value back to OP's type makes a value equivalent to OP.
8484 If FOR_TYPE is nonzero, we return a value which, if converted to
8485 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8487 OP must have integer, real or enumeral type. Pointers are not allowed!
8489 There are some cases where the obvious value we could return
8490 would regenerate to OP if converted to OP's type,
8491 but would not extend like OP to wider types.
8492 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8493 For example, if OP is (unsigned short)(signed char)-1,
8494 we avoid returning (signed char)-1 if FOR_TYPE is int,
8495 even though extending that to an unsigned short would regenerate OP,
8496 since the result of extending (signed char)-1 to (int)
8497 is different from (int) OP. */
8500 get_unwidened (tree op
, tree for_type
)
8502 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8503 tree type
= TREE_TYPE (op
);
8505 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
8507 = (for_type
!= 0 && for_type
!= type
8508 && final_prec
> TYPE_PRECISION (type
)
8509 && TYPE_UNSIGNED (type
));
8512 while (CONVERT_EXPR_P (op
))
8516 /* TYPE_PRECISION on vector types has different meaning
8517 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8518 so avoid them here. */
8519 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
8522 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
8523 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
8525 /* Truncations are many-one so cannot be removed.
8526 Unless we are later going to truncate down even farther. */
8528 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
8531 /* See what's inside this conversion. If we decide to strip it,
8533 op
= TREE_OPERAND (op
, 0);
8535 /* If we have not stripped any zero-extensions (uns is 0),
8536 we can strip any kind of extension.
8537 If we have previously stripped a zero-extension,
8538 only zero-extensions can safely be stripped.
8539 Any extension can be stripped if the bits it would produce
8540 are all going to be discarded later by truncating to FOR_TYPE. */
8544 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
8546 /* TYPE_UNSIGNED says whether this is a zero-extension.
8547 Let's avoid computing it if it does not affect WIN
8548 and if UNS will not be needed again. */
8550 || CONVERT_EXPR_P (op
))
8551 && TYPE_UNSIGNED (TREE_TYPE (op
)))
8559 /* If we finally reach a constant see if it fits in for_type and
8560 in that case convert it. */
8562 && TREE_CODE (win
) == INTEGER_CST
8563 && TREE_TYPE (win
) != for_type
8564 && int_fits_type_p (win
, for_type
))
8565 win
= fold_convert (for_type
, win
);
8570 /* Return OP or a simpler expression for a narrower value
8571 which can be sign-extended or zero-extended to give back OP.
8572 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8573 or 0 if the value should be sign-extended. */
8576 get_narrower (tree op
, int *unsignedp_ptr
)
8581 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8583 while (TREE_CODE (op
) == NOP_EXPR
)
8586 = (TYPE_PRECISION (TREE_TYPE (op
))
8587 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8589 /* Truncations are many-one so cannot be removed. */
8593 /* See what's inside this conversion. If we decide to strip it,
8598 op
= TREE_OPERAND (op
, 0);
8599 /* An extension: the outermost one can be stripped,
8600 but remember whether it is zero or sign extension. */
8602 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8603 /* Otherwise, if a sign extension has been stripped,
8604 only sign extensions can now be stripped;
8605 if a zero extension has been stripped, only zero-extensions. */
8606 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8610 else /* bitschange == 0 */
8612 /* A change in nominal type can always be stripped, but we must
8613 preserve the unsignedness. */
8615 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8617 op
= TREE_OPERAND (op
, 0);
8618 /* Keep trying to narrow, but don't assign op to win if it
8619 would turn an integral type into something else. */
8620 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8627 if (TREE_CODE (op
) == COMPONENT_REF
8628 /* Since type_for_size always gives an integer type. */
8629 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8630 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8631 /* Ensure field is laid out already. */
8632 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8633 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
8635 unsigned HOST_WIDE_INT innerprec
8636 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
8637 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8638 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8639 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8641 /* We can get this structure field in a narrower type that fits it,
8642 but the resulting extension to its nominal type (a fullword type)
8643 must satisfy the same conditions as for other extensions.
8645 Do this only for fields that are aligned (not bit-fields),
8646 because when bit-field insns will be used there is no
8647 advantage in doing this. */
8649 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8650 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8651 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8655 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8656 win
= fold_convert (type
, op
);
8660 *unsignedp_ptr
= uns
;
8664 /* Returns true if integer constant C has a value that is permissible
8665 for type TYPE (an INTEGER_TYPE). */
8668 int_fits_type_p (const_tree c
, const_tree type
)
8670 tree type_low_bound
, type_high_bound
;
8671 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
8674 dc
= tree_to_double_int (c
);
8675 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
8678 type_low_bound
= TYPE_MIN_VALUE (type
);
8679 type_high_bound
= TYPE_MAX_VALUE (type
);
8681 /* If at least one bound of the type is a constant integer, we can check
8682 ourselves and maybe make a decision. If no such decision is possible, but
8683 this type is a subtype, try checking against that. Otherwise, use
8684 double_int_fits_to_tree_p, which checks against the precision.
8686 Compute the status for each possibly constant bound, and return if we see
8687 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8688 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8689 for "constant known to fit". */
8691 /* Check if c >= type_low_bound. */
8692 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8694 dd
= tree_to_double_int (type_low_bound
);
8695 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
8697 int c_neg
= (!unsc
&& dc
.is_negative ());
8698 int t_neg
= (unsc
&& dd
.is_negative ());
8700 if (c_neg
&& !t_neg
)
8702 if ((c_neg
|| !t_neg
) && dc
.ult (dd
))
8705 else if (dc
.cmp (dd
, unsc
) < 0)
8707 ok_for_low_bound
= true;
8710 ok_for_low_bound
= false;
8712 /* Check if c <= type_high_bound. */
8713 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8715 dd
= tree_to_double_int (type_high_bound
);
8716 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
8718 int c_neg
= (!unsc
&& dc
.is_negative ());
8719 int t_neg
= (unsc
&& dd
.is_negative ());
8721 if (t_neg
&& !c_neg
)
8723 if ((t_neg
|| !c_neg
) && dc
.ugt (dd
))
8726 else if (dc
.cmp (dd
, unsc
) > 0)
8728 ok_for_high_bound
= true;
8731 ok_for_high_bound
= false;
8733 /* If the constant fits both bounds, the result is known. */
8734 if (ok_for_low_bound
&& ok_for_high_bound
)
8737 /* Perform some generic filtering which may allow making a decision
8738 even if the bounds are not constant. First, negative integers
8739 never fit in unsigned types, */
8740 if (TYPE_UNSIGNED (type
) && !unsc
&& dc
.is_negative ())
8743 /* Second, narrower types always fit in wider ones. */
8744 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8747 /* Third, unsigned integers with top bit set never fit signed types. */
8748 if (! TYPE_UNSIGNED (type
) && unsc
)
8750 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
8751 if (prec
< HOST_BITS_PER_WIDE_INT
)
8753 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
8756 else if (((((unsigned HOST_WIDE_INT
) 1)
8757 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
8761 /* If we haven't been able to decide at this point, there nothing more we
8762 can check ourselves here. Look at the base type if we have one and it
8763 has the same precision. */
8764 if (TREE_CODE (type
) == INTEGER_TYPE
8765 && TREE_TYPE (type
) != 0
8766 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8768 type
= TREE_TYPE (type
);
8772 /* Or to double_int_fits_to_tree_p, if nothing else. */
8773 return double_int_fits_to_tree_p (type
, dc
);
8776 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8777 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8778 represented (assuming two's-complement arithmetic) within the bit
8779 precision of the type are returned instead. */
8782 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8784 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8785 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8786 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
8787 TYPE_UNSIGNED (type
));
8790 if (TYPE_UNSIGNED (type
))
8791 mpz_set_ui (min
, 0);
8795 mn
= double_int::mask (TYPE_PRECISION (type
) - 1);
8796 mn
= (mn
+ double_int_one
).sext (TYPE_PRECISION (type
));
8797 mpz_set_double_int (min
, mn
, false);
8801 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8802 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8803 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
8804 TYPE_UNSIGNED (type
));
8807 if (TYPE_UNSIGNED (type
))
8808 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
)),
8811 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
) - 1),
8816 /* Return true if VAR is an automatic variable defined in function FN. */
8819 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8821 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8822 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8823 || TREE_CODE (var
) == PARM_DECL
)
8824 && ! TREE_STATIC (var
))
8825 || TREE_CODE (var
) == LABEL_DECL
8826 || TREE_CODE (var
) == RESULT_DECL
));
8829 /* Subprogram of following function. Called by walk_tree.
8831 Return *TP if it is an automatic variable or parameter of the
8832 function passed in as DATA. */
8835 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8837 tree fn
= (tree
) data
;
8842 else if (DECL_P (*tp
)
8843 && auto_var_in_fn_p (*tp
, fn
))
8849 /* Returns true if T is, contains, or refers to a type with variable
8850 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8851 arguments, but not the return type. If FN is nonzero, only return
8852 true if a modifier of the type or position of FN is a variable or
8853 parameter inside FN.
8855 This concept is more general than that of C99 'variably modified types':
8856 in C99, a struct type is never variably modified because a VLA may not
8857 appear as a structure member. However, in GNU C code like:
8859 struct S { int i[f()]; };
8861 is valid, and other languages may define similar constructs. */
8864 variably_modified_type_p (tree type
, tree fn
)
8868 /* Test if T is either variable (if FN is zero) or an expression containing
8869 a variable in FN. If TYPE isn't gimplified, return true also if
8870 gimplify_one_sizepos would gimplify the expression into a local
8872 #define RETURN_TRUE_IF_VAR(T) \
8873 do { tree _t = (T); \
8874 if (_t != NULL_TREE \
8875 && _t != error_mark_node \
8876 && TREE_CODE (_t) != INTEGER_CST \
8877 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8879 || (!TYPE_SIZES_GIMPLIFIED (type) \
8880 && !is_gimple_sizepos (_t)) \
8881 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8882 return true; } while (0)
8884 if (type
== error_mark_node
)
8887 /* If TYPE itself has variable size, it is variably modified. */
8888 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8889 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8891 switch (TREE_CODE (type
))
8894 case REFERENCE_TYPE
:
8896 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8902 /* If TYPE is a function type, it is variably modified if the
8903 return type is variably modified. */
8904 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8910 case FIXED_POINT_TYPE
:
8913 /* Scalar types are variably modified if their end points
8915 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8916 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8921 case QUAL_UNION_TYPE
:
8922 /* We can't see if any of the fields are variably-modified by the
8923 definition we normally use, since that would produce infinite
8924 recursion via pointers. */
8925 /* This is variably modified if some field's type is. */
8926 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8927 if (TREE_CODE (t
) == FIELD_DECL
)
8929 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8930 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8931 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8933 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8934 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8939 /* Do not call ourselves to avoid infinite recursion. This is
8940 variably modified if the element type is. */
8941 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8942 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8949 /* The current language may have other cases to check, but in general,
8950 all other types are not variably modified. */
8951 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8953 #undef RETURN_TRUE_IF_VAR
8956 /* Given a DECL or TYPE, return the scope in which it was declared, or
8957 NULL_TREE if there is no containing scope. */
8960 get_containing_scope (const_tree t
)
8962 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8965 /* Return the innermost context enclosing DECL that is
8966 a FUNCTION_DECL, or zero if none. */
8969 decl_function_context (const_tree decl
)
8973 if (TREE_CODE (decl
) == ERROR_MARK
)
8976 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8977 where we look up the function at runtime. Such functions always take
8978 a first argument of type 'pointer to real context'.
8980 C++ should really be fixed to use DECL_CONTEXT for the real context,
8981 and use something else for the "virtual context". */
8982 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
8985 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8987 context
= DECL_CONTEXT (decl
);
8989 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8991 if (TREE_CODE (context
) == BLOCK
)
8992 context
= BLOCK_SUPERCONTEXT (context
);
8994 context
= get_containing_scope (context
);
9000 /* Return the innermost context enclosing DECL that is
9001 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
9002 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
9005 decl_type_context (const_tree decl
)
9007 tree context
= DECL_CONTEXT (decl
);
9010 switch (TREE_CODE (context
))
9012 case NAMESPACE_DECL
:
9013 case TRANSLATION_UNIT_DECL
:
9018 case QUAL_UNION_TYPE
:
9023 context
= DECL_CONTEXT (context
);
9027 context
= BLOCK_SUPERCONTEXT (context
);
9037 /* CALL is a CALL_EXPR. Return the declaration for the function
9038 called, or NULL_TREE if the called function cannot be
9042 get_callee_fndecl (const_tree call
)
9046 if (call
== error_mark_node
)
9047 return error_mark_node
;
9049 /* It's invalid to call this function with anything but a
9051 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
9053 /* The first operand to the CALL is the address of the function
9055 addr
= CALL_EXPR_FN (call
);
9059 /* If this is a readonly function pointer, extract its initial value. */
9060 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
9061 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
9062 && DECL_INITIAL (addr
))
9063 addr
= DECL_INITIAL (addr
);
9065 /* If the address is just `&f' for some function `f', then we know
9066 that `f' is being called. */
9067 if (TREE_CODE (addr
) == ADDR_EXPR
9068 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
9069 return TREE_OPERAND (addr
, 0);
9071 /* We couldn't figure out what was being called. */
9075 /* Print debugging information about tree nodes generated during the compile,
9076 and any language-specific information. */
9079 dump_tree_statistics (void)
9081 if (GATHER_STATISTICS
)
9084 int total_nodes
, total_bytes
;
9085 fprintf (stderr
, "Kind Nodes Bytes\n");
9086 fprintf (stderr
, "---------------------------------------\n");
9087 total_nodes
= total_bytes
= 0;
9088 for (i
= 0; i
< (int) all_kinds
; i
++)
9090 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
9091 tree_node_counts
[i
], tree_node_sizes
[i
]);
9092 total_nodes
+= tree_node_counts
[i
];
9093 total_bytes
+= tree_node_sizes
[i
];
9095 fprintf (stderr
, "---------------------------------------\n");
9096 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
9097 fprintf (stderr
, "---------------------------------------\n");
9098 fprintf (stderr
, "Code Nodes\n");
9099 fprintf (stderr
, "----------------------------\n");
9100 for (i
= 0; i
< (int) MAX_TREE_CODES
; i
++)
9101 fprintf (stderr
, "%-20s %7d\n", get_tree_code_name ((enum tree_code
) i
),
9102 tree_code_counts
[i
]);
9103 fprintf (stderr
, "----------------------------\n");
9104 ssanames_print_statistics ();
9105 phinodes_print_statistics ();
9108 fprintf (stderr
, "(No per-node statistics)\n");
9110 print_type_hash_statistics ();
9111 print_debug_expr_statistics ();
9112 print_value_expr_statistics ();
9113 lang_hooks
.print_statistics ();
9116 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9118 /* Generate a crc32 of a byte. */
9121 crc32_unsigned_bits (unsigned chksum
, unsigned value
, unsigned bits
)
9125 for (ix
= bits
; ix
--; value
<<= 1)
9129 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
9136 /* Generate a crc32 of a 32-bit unsigned. */
9139 crc32_unsigned (unsigned chksum
, unsigned value
)
9141 return crc32_unsigned_bits (chksum
, value
, 32);
9144 /* Generate a crc32 of a byte. */
9147 crc32_byte (unsigned chksum
, char byte
)
9149 return crc32_unsigned_bits (chksum
, (unsigned) byte
<< 24, 8);
9152 /* Generate a crc32 of a string. */
9155 crc32_string (unsigned chksum
, const char *string
)
9159 chksum
= crc32_byte (chksum
, *string
);
9165 /* P is a string that will be used in a symbol. Mask out any characters
9166 that are not valid in that context. */
9169 clean_symbol_name (char *p
)
9173 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9176 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9183 /* Generate a name for a special-purpose function.
9184 The generated name may need to be unique across the whole link.
9185 Changes to this function may also require corresponding changes to
9186 xstrdup_mask_random.
9187 TYPE is some string to identify the purpose of this function to the
9188 linker or collect2; it must start with an uppercase letter,
9190 I - for constructors
9192 N - for C++ anonymous namespaces
9193 F - for DWARF unwind frame information. */
9196 get_file_function_name (const char *type
)
9202 /* If we already have a name we know to be unique, just use that. */
9203 if (first_global_object_name
)
9204 p
= q
= ASTRDUP (first_global_object_name
);
9205 /* If the target is handling the constructors/destructors, they
9206 will be local to this file and the name is only necessary for
9208 We also assign sub_I and sub_D sufixes to constructors called from
9209 the global static constructors. These are always local. */
9210 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
9211 || (strncmp (type
, "sub_", 4) == 0
9212 && (type
[4] == 'I' || type
[4] == 'D')))
9214 const char *file
= main_input_filename
;
9216 file
= input_filename
;
9217 /* Just use the file's basename, because the full pathname
9218 might be quite long. */
9219 p
= q
= ASTRDUP (lbasename (file
));
9223 /* Otherwise, the name must be unique across the entire link.
9224 We don't have anything that we know to be unique to this translation
9225 unit, so use what we do have and throw in some randomness. */
9227 const char *name
= weak_global_object_name
;
9228 const char *file
= main_input_filename
;
9233 file
= input_filename
;
9235 len
= strlen (file
);
9236 q
= (char *) alloca (9 + 17 + len
+ 1);
9237 memcpy (q
, file
, len
+ 1);
9239 snprintf (q
+ len
, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
9240 crc32_string (0, name
), get_random_seed (false));
9245 clean_symbol_name (q
);
9246 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
9249 /* Set up the name of the file-level functions we may need.
9250 Use a global object (which is already required to be unique over
9251 the program) rather than the file name (which imposes extra
9253 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
9255 return get_identifier (buf
);
9258 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9260 /* Complain that the tree code of NODE does not match the expected 0
9261 terminated list of trailing codes. The trailing code list can be
9262 empty, for a more vague error message. FILE, LINE, and FUNCTION
9263 are of the caller. */
9266 tree_check_failed (const_tree node
, const char *file
,
9267 int line
, const char *function
, ...)
9271 unsigned length
= 0;
9272 enum tree_code code
;
9274 va_start (args
, function
);
9275 while ((code
= (enum tree_code
) va_arg (args
, int)))
9276 length
+= 4 + strlen (get_tree_code_name (code
));
9281 va_start (args
, function
);
9282 length
+= strlen ("expected ");
9283 buffer
= tmp
= (char *) alloca (length
);
9285 while ((code
= (enum tree_code
) va_arg (args
, int)))
9287 const char *prefix
= length
? " or " : "expected ";
9289 strcpy (tmp
+ length
, prefix
);
9290 length
+= strlen (prefix
);
9291 strcpy (tmp
+ length
, get_tree_code_name (code
));
9292 length
+= strlen (get_tree_code_name (code
));
9297 buffer
= "unexpected node";
9299 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9300 buffer
, get_tree_code_name (TREE_CODE (node
)),
9301 function
, trim_filename (file
), line
);
9304 /* Complain that the tree code of NODE does match the expected 0
9305 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9309 tree_not_check_failed (const_tree node
, const char *file
,
9310 int line
, const char *function
, ...)
9314 unsigned length
= 0;
9315 enum tree_code code
;
9317 va_start (args
, function
);
9318 while ((code
= (enum tree_code
) va_arg (args
, int)))
9319 length
+= 4 + strlen (get_tree_code_name (code
));
9321 va_start (args
, function
);
9322 buffer
= (char *) alloca (length
);
9324 while ((code
= (enum tree_code
) va_arg (args
, int)))
9328 strcpy (buffer
+ length
, " or ");
9331 strcpy (buffer
+ length
, get_tree_code_name (code
));
9332 length
+= strlen (get_tree_code_name (code
));
9336 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9337 buffer
, get_tree_code_name (TREE_CODE (node
)),
9338 function
, trim_filename (file
), line
);
9341 /* Similar to tree_check_failed, except that we check for a class of tree
9342 code, given in CL. */
9345 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9346 const char *file
, int line
, const char *function
)
9349 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9350 TREE_CODE_CLASS_STRING (cl
),
9351 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9352 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9355 /* Similar to tree_check_failed, except that instead of specifying a
9356 dozen codes, use the knowledge that they're all sequential. */
9359 tree_range_check_failed (const_tree node
, const char *file
, int line
,
9360 const char *function
, enum tree_code c1
,
9364 unsigned length
= 0;
9367 for (c
= c1
; c
<= c2
; ++c
)
9368 length
+= 4 + strlen (get_tree_code_name ((enum tree_code
) c
));
9370 length
+= strlen ("expected ");
9371 buffer
= (char *) alloca (length
);
9374 for (c
= c1
; c
<= c2
; ++c
)
9376 const char *prefix
= length
? " or " : "expected ";
9378 strcpy (buffer
+ length
, prefix
);
9379 length
+= strlen (prefix
);
9380 strcpy (buffer
+ length
, get_tree_code_name ((enum tree_code
) c
));
9381 length
+= strlen (get_tree_code_name ((enum tree_code
) c
));
9384 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9385 buffer
, get_tree_code_name (TREE_CODE (node
)),
9386 function
, trim_filename (file
), line
);
9390 /* Similar to tree_check_failed, except that we check that a tree does
9391 not have the specified code, given in CL. */
9394 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9395 const char *file
, int line
, const char *function
)
9398 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9399 TREE_CODE_CLASS_STRING (cl
),
9400 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9401 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9405 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9408 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
9409 const char *function
, enum omp_clause_code code
)
9411 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9412 omp_clause_code_name
[code
], get_tree_code_name (TREE_CODE (node
)),
9413 function
, trim_filename (file
), line
);
9417 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9420 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
9421 const char *function
, enum omp_clause_code c1
,
9422 enum omp_clause_code c2
)
9425 unsigned length
= 0;
9428 for (c
= c1
; c
<= c2
; ++c
)
9429 length
+= 4 + strlen (omp_clause_code_name
[c
]);
9431 length
+= strlen ("expected ");
9432 buffer
= (char *) alloca (length
);
9435 for (c
= c1
; c
<= c2
; ++c
)
9437 const char *prefix
= length
? " or " : "expected ";
9439 strcpy (buffer
+ length
, prefix
);
9440 length
+= strlen (prefix
);
9441 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
9442 length
+= strlen (omp_clause_code_name
[c
]);
9445 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9446 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
9447 function
, trim_filename (file
), line
);
9451 #undef DEFTREESTRUCT
9452 #define DEFTREESTRUCT(VAL, NAME) NAME,
9454 static const char *ts_enum_names
[] = {
9455 #include "treestruct.def"
9457 #undef DEFTREESTRUCT
9459 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9461 /* Similar to tree_class_check_failed, except that we check for
9462 whether CODE contains the tree structure identified by EN. */
9465 tree_contains_struct_check_failed (const_tree node
,
9466 const enum tree_node_structure_enum en
,
9467 const char *file
, int line
,
9468 const char *function
)
9471 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9473 get_tree_code_name (TREE_CODE (node
)), function
, trim_filename (file
), line
);
9477 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9478 (dynamically sized) vector. */
9481 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9482 const char *function
)
9485 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9486 idx
+ 1, len
, function
, trim_filename (file
), line
);
9489 /* Similar to above, except that the check is for the bounds of the operand
9490 vector of an expression node EXP. */
9493 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
9494 int line
, const char *function
)
9496 enum tree_code code
= TREE_CODE (exp
);
9498 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9499 idx
+ 1, get_tree_code_name (code
), TREE_OPERAND_LENGTH (exp
),
9500 function
, trim_filename (file
), line
);
9503 /* Similar to above, except that the check is for the number of
9504 operands of an OMP_CLAUSE node. */
9507 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
9508 int line
, const char *function
)
9511 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9512 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
9513 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
9514 trim_filename (file
), line
);
9516 #endif /* ENABLE_TREE_CHECKING */
9518 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9519 and mapped to the machine mode MODE. Initialize its fields and build
9520 the information necessary for debugging output. */
9523 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
9526 hashval_t hashcode
= 0;
9528 t
= make_node (VECTOR_TYPE
);
9529 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
9530 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
9531 SET_TYPE_MODE (t
, mode
);
9533 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
9534 SET_TYPE_STRUCTURAL_EQUALITY (t
);
9535 else if (TYPE_CANONICAL (innertype
) != innertype
9536 || mode
!= VOIDmode
)
9538 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
9542 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
9543 hashcode
= iterative_hash_host_wide_int (nunits
, hashcode
);
9544 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
9545 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (t
)), hashcode
);
9546 t
= type_hash_canon (hashcode
, t
);
9548 /* We have built a main variant, based on the main variant of the
9549 inner type. Use it to build the variant we return. */
9550 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
9551 && TREE_TYPE (t
) != innertype
)
9552 return build_type_attribute_qual_variant (t
,
9553 TYPE_ATTRIBUTES (innertype
),
9554 TYPE_QUALS (innertype
));
9560 make_or_reuse_type (unsigned size
, int unsignedp
)
9562 if (size
== INT_TYPE_SIZE
)
9563 return unsignedp
? unsigned_type_node
: integer_type_node
;
9564 if (size
== CHAR_TYPE_SIZE
)
9565 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
9566 if (size
== SHORT_TYPE_SIZE
)
9567 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
9568 if (size
== LONG_TYPE_SIZE
)
9569 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
9570 if (size
== LONG_LONG_TYPE_SIZE
)
9571 return (unsignedp
? long_long_unsigned_type_node
9572 : long_long_integer_type_node
);
9573 if (size
== 128 && int128_integer_type_node
)
9574 return (unsignedp
? int128_unsigned_type_node
9575 : int128_integer_type_node
);
9578 return make_unsigned_type (size
);
9580 return make_signed_type (size
);
9583 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9586 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
9590 if (size
== SHORT_FRACT_TYPE_SIZE
)
9591 return unsignedp
? sat_unsigned_short_fract_type_node
9592 : sat_short_fract_type_node
;
9593 if (size
== FRACT_TYPE_SIZE
)
9594 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9595 if (size
== LONG_FRACT_TYPE_SIZE
)
9596 return unsignedp
? sat_unsigned_long_fract_type_node
9597 : sat_long_fract_type_node
;
9598 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9599 return unsignedp
? sat_unsigned_long_long_fract_type_node
9600 : sat_long_long_fract_type_node
;
9604 if (size
== SHORT_FRACT_TYPE_SIZE
)
9605 return unsignedp
? unsigned_short_fract_type_node
9606 : short_fract_type_node
;
9607 if (size
== FRACT_TYPE_SIZE
)
9608 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9609 if (size
== LONG_FRACT_TYPE_SIZE
)
9610 return unsignedp
? unsigned_long_fract_type_node
9611 : long_fract_type_node
;
9612 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9613 return unsignedp
? unsigned_long_long_fract_type_node
9614 : long_long_fract_type_node
;
9617 return make_fract_type (size
, unsignedp
, satp
);
9620 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9623 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9627 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9628 return unsignedp
? sat_unsigned_short_accum_type_node
9629 : sat_short_accum_type_node
;
9630 if (size
== ACCUM_TYPE_SIZE
)
9631 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9632 if (size
== LONG_ACCUM_TYPE_SIZE
)
9633 return unsignedp
? sat_unsigned_long_accum_type_node
9634 : sat_long_accum_type_node
;
9635 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9636 return unsignedp
? sat_unsigned_long_long_accum_type_node
9637 : sat_long_long_accum_type_node
;
9641 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9642 return unsignedp
? unsigned_short_accum_type_node
9643 : short_accum_type_node
;
9644 if (size
== ACCUM_TYPE_SIZE
)
9645 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9646 if (size
== LONG_ACCUM_TYPE_SIZE
)
9647 return unsignedp
? unsigned_long_accum_type_node
9648 : long_accum_type_node
;
9649 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9650 return unsignedp
? unsigned_long_long_accum_type_node
9651 : long_long_accum_type_node
;
9654 return make_accum_type (size
, unsignedp
, satp
);
9657 /* Create nodes for all integer types (and error_mark_node) using the sizes
9658 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9659 SHORT_DOUBLE specifies whether double should be of the same precision
9663 build_common_tree_nodes (bool signed_char
, bool short_double
)
9665 error_mark_node
= make_node (ERROR_MARK
);
9666 TREE_TYPE (error_mark_node
) = error_mark_node
;
9668 initialize_sizetypes ();
9670 /* Define both `signed char' and `unsigned char'. */
9671 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9672 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9673 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9674 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9676 /* Define `char', which is like either `signed char' or `unsigned char'
9677 but not the same as either. */
9680 ? make_signed_type (CHAR_TYPE_SIZE
)
9681 : make_unsigned_type (CHAR_TYPE_SIZE
));
9682 TYPE_STRING_FLAG (char_type_node
) = 1;
9684 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9685 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9686 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9687 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9688 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9689 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9690 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9691 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9692 #if HOST_BITS_PER_WIDE_INT >= 64
9693 /* TODO: This isn't correct, but as logic depends at the moment on
9694 host's instead of target's wide-integer.
9695 If there is a target not supporting TImode, but has an 128-bit
9696 integer-scalar register, this target check needs to be adjusted. */
9697 if (targetm
.scalar_mode_supported_p (TImode
))
9699 int128_integer_type_node
= make_signed_type (128);
9700 int128_unsigned_type_node
= make_unsigned_type (128);
9704 /* Define a boolean type. This type only represents boolean values but
9705 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9706 Front ends which want to override this size (i.e. Java) can redefine
9707 boolean_type_node before calling build_common_tree_nodes_2. */
9708 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9709 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9710 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9711 TYPE_PRECISION (boolean_type_node
) = 1;
9713 /* Define what type to use for size_t. */
9714 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
9715 size_type_node
= unsigned_type_node
;
9716 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
9717 size_type_node
= long_unsigned_type_node
;
9718 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
9719 size_type_node
= long_long_unsigned_type_node
;
9720 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
9721 size_type_node
= short_unsigned_type_node
;
9725 /* Fill in the rest of the sized types. Reuse existing type nodes
9727 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9728 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9729 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9730 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9731 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9733 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9734 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9735 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9736 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9737 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9739 access_public_node
= get_identifier ("public");
9740 access_protected_node
= get_identifier ("protected");
9741 access_private_node
= get_identifier ("private");
9743 /* Define these next since types below may used them. */
9744 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9745 integer_one_node
= build_int_cst (integer_type_node
, 1);
9746 integer_three_node
= build_int_cst (integer_type_node
, 3);
9747 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9749 size_zero_node
= size_int (0);
9750 size_one_node
= size_int (1);
9751 bitsize_zero_node
= bitsize_int (0);
9752 bitsize_one_node
= bitsize_int (1);
9753 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9755 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9756 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9758 void_type_node
= make_node (VOID_TYPE
);
9759 layout_type (void_type_node
);
9761 /* We are not going to have real types in C with less than byte alignment,
9762 so we might as well not have any types that claim to have it. */
9763 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
9764 TYPE_USER_ALIGN (void_type_node
) = 0;
9766 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9767 layout_type (TREE_TYPE (null_pointer_node
));
9769 ptr_type_node
= build_pointer_type (void_type_node
);
9771 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9772 fileptr_type_node
= ptr_type_node
;
9774 pointer_sized_int_node
= build_nonstandard_integer_type (POINTER_SIZE
, 1);
9776 float_type_node
= make_node (REAL_TYPE
);
9777 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9778 layout_type (float_type_node
);
9780 double_type_node
= make_node (REAL_TYPE
);
9782 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
9784 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9785 layout_type (double_type_node
);
9787 long_double_type_node
= make_node (REAL_TYPE
);
9788 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9789 layout_type (long_double_type_node
);
9791 float_ptr_type_node
= build_pointer_type (float_type_node
);
9792 double_ptr_type_node
= build_pointer_type (double_type_node
);
9793 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9794 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9796 /* Fixed size integer types. */
9797 uint16_type_node
= build_nonstandard_integer_type (16, true);
9798 uint32_type_node
= build_nonstandard_integer_type (32, true);
9799 uint64_type_node
= build_nonstandard_integer_type (64, true);
9801 /* Decimal float types. */
9802 dfloat32_type_node
= make_node (REAL_TYPE
);
9803 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9804 layout_type (dfloat32_type_node
);
9805 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9806 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
9808 dfloat64_type_node
= make_node (REAL_TYPE
);
9809 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9810 layout_type (dfloat64_type_node
);
9811 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9812 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
9814 dfloat128_type_node
= make_node (REAL_TYPE
);
9815 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9816 layout_type (dfloat128_type_node
);
9817 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9818 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
9820 complex_integer_type_node
= build_complex_type (integer_type_node
);
9821 complex_float_type_node
= build_complex_type (float_type_node
);
9822 complex_double_type_node
= build_complex_type (double_type_node
);
9823 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
9825 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9826 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9827 sat_ ## KIND ## _type_node = \
9828 make_sat_signed_ ## KIND ## _type (SIZE); \
9829 sat_unsigned_ ## KIND ## _type_node = \
9830 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9831 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9832 unsigned_ ## KIND ## _type_node = \
9833 make_unsigned_ ## KIND ## _type (SIZE);
9835 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9836 sat_ ## WIDTH ## KIND ## _type_node = \
9837 make_sat_signed_ ## KIND ## _type (SIZE); \
9838 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9839 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9840 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9841 unsigned_ ## WIDTH ## KIND ## _type_node = \
9842 make_unsigned_ ## KIND ## _type (SIZE);
9844 /* Make fixed-point type nodes based on four different widths. */
9845 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9846 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9847 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9848 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9849 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9851 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9852 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9853 NAME ## _type_node = \
9854 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9855 u ## NAME ## _type_node = \
9856 make_or_reuse_unsigned_ ## KIND ## _type \
9857 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9858 sat_ ## NAME ## _type_node = \
9859 make_or_reuse_sat_signed_ ## KIND ## _type \
9860 (GET_MODE_BITSIZE (MODE ## mode)); \
9861 sat_u ## NAME ## _type_node = \
9862 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9863 (GET_MODE_BITSIZE (U ## MODE ## mode));
9865 /* Fixed-point type and mode nodes. */
9866 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9867 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9868 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9869 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9870 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9871 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9872 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9873 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9874 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9875 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9876 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9879 tree t
= targetm
.build_builtin_va_list ();
9881 /* Many back-ends define record types without setting TYPE_NAME.
9882 If we copied the record type here, we'd keep the original
9883 record type without a name. This breaks name mangling. So,
9884 don't copy record types and let c_common_nodes_and_builtins()
9885 declare the type to be __builtin_va_list. */
9886 if (TREE_CODE (t
) != RECORD_TYPE
)
9887 t
= build_variant_type_copy (t
);
9889 va_list_type_node
= t
;
9893 /* Modify DECL for given flags.
9894 TM_PURE attribute is set only on types, so the function will modify
9895 DECL's type when ECF_TM_PURE is used. */
9898 set_call_expr_flags (tree decl
, int flags
)
9900 if (flags
& ECF_NOTHROW
)
9901 TREE_NOTHROW (decl
) = 1;
9902 if (flags
& ECF_CONST
)
9903 TREE_READONLY (decl
) = 1;
9904 if (flags
& ECF_PURE
)
9905 DECL_PURE_P (decl
) = 1;
9906 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
9907 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9908 if (flags
& ECF_NOVOPS
)
9909 DECL_IS_NOVOPS (decl
) = 1;
9910 if (flags
& ECF_NORETURN
)
9911 TREE_THIS_VOLATILE (decl
) = 1;
9912 if (flags
& ECF_MALLOC
)
9913 DECL_IS_MALLOC (decl
) = 1;
9914 if (flags
& ECF_RETURNS_TWICE
)
9915 DECL_IS_RETURNS_TWICE (decl
) = 1;
9916 if (flags
& ECF_LEAF
)
9917 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9918 NULL
, DECL_ATTRIBUTES (decl
));
9919 if ((flags
& ECF_TM_PURE
) && flag_tm
)
9920 apply_tm_attr (decl
, get_identifier ("transaction_pure"));
9921 /* Looping const or pure is implied by noreturn.
9922 There is currently no way to declare looping const or looping pure alone. */
9923 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
9924 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
9928 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9931 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9932 const char *library_name
, int ecf_flags
)
9936 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9937 library_name
, NULL_TREE
);
9938 set_call_expr_flags (decl
, ecf_flags
);
9940 set_builtin_decl (code
, decl
, true);
9943 /* Call this function after instantiating all builtins that the language
9944 front end cares about. This will build the rest of the builtins that
9945 are relied upon by the tree optimizers and the middle-end. */
9948 build_common_builtin_nodes (void)
9953 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
9955 ftype
= build_function_type (void_type_node
, void_list_node
);
9956 local_define_builtin ("__builtin_unreachable", ftype
, BUILT_IN_UNREACHABLE
,
9957 "__builtin_unreachable",
9958 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
9959 | ECF_CONST
| ECF_LEAF
);
9962 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
9963 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9965 ftype
= build_function_type_list (ptr_type_node
,
9966 ptr_type_node
, const_ptr_type_node
,
9967 size_type_node
, NULL_TREE
);
9969 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
9970 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9971 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9972 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9973 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9974 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9977 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
9979 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9980 const_ptr_type_node
, size_type_node
,
9982 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9983 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9986 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
9988 ftype
= build_function_type_list (ptr_type_node
,
9989 ptr_type_node
, integer_type_node
,
9990 size_type_node
, NULL_TREE
);
9991 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9992 "memset", ECF_NOTHROW
| ECF_LEAF
);
9995 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
9997 ftype
= build_function_type_list (ptr_type_node
,
9998 size_type_node
, NULL_TREE
);
9999 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
10000 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10003 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
10004 size_type_node
, NULL_TREE
);
10005 local_define_builtin ("__builtin_alloca_with_align", ftype
,
10006 BUILT_IN_ALLOCA_WITH_ALIGN
, "alloca",
10007 ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
10009 /* If we're checking the stack, `alloca' can throw. */
10010 if (flag_stack_check
)
10012 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA
)) = 0;
10013 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
)) = 0;
10016 ftype
= build_function_type_list (void_type_node
,
10017 ptr_type_node
, ptr_type_node
,
10018 ptr_type_node
, NULL_TREE
);
10019 local_define_builtin ("__builtin_init_trampoline", ftype
,
10020 BUILT_IN_INIT_TRAMPOLINE
,
10021 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
10022 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
10023 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
10024 "__builtin_init_heap_trampoline",
10025 ECF_NOTHROW
| ECF_LEAF
);
10027 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
10028 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
10029 BUILT_IN_ADJUST_TRAMPOLINE
,
10030 "__builtin_adjust_trampoline",
10031 ECF_CONST
| ECF_NOTHROW
);
10033 ftype
= build_function_type_list (void_type_node
,
10034 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10035 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
10036 BUILT_IN_NONLOCAL_GOTO
,
10037 "__builtin_nonlocal_goto",
10038 ECF_NORETURN
| ECF_NOTHROW
);
10040 ftype
= build_function_type_list (void_type_node
,
10041 ptr_type_node
, ptr_type_node
, NULL_TREE
);
10042 local_define_builtin ("__builtin_setjmp_setup", ftype
,
10043 BUILT_IN_SETJMP_SETUP
,
10044 "__builtin_setjmp_setup", ECF_NOTHROW
);
10046 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
10047 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
10048 BUILT_IN_SETJMP_DISPATCHER
,
10049 "__builtin_setjmp_dispatcher",
10050 ECF_PURE
| ECF_NOTHROW
);
10052 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10053 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
10054 BUILT_IN_SETJMP_RECEIVER
,
10055 "__builtin_setjmp_receiver", ECF_NOTHROW
);
10057 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
10058 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
10059 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
10061 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10062 local_define_builtin ("__builtin_stack_restore", ftype
,
10063 BUILT_IN_STACK_RESTORE
,
10064 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
10066 /* If there's a possibility that we might use the ARM EABI, build the
10067 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
10068 if (targetm
.arm_eabi_unwinder
)
10070 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
10071 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
10072 BUILT_IN_CXA_END_CLEANUP
,
10073 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
10076 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
10077 local_define_builtin ("__builtin_unwind_resume", ftype
,
10078 BUILT_IN_UNWIND_RESUME
,
10079 ((targetm_common
.except_unwind_info (&global_options
)
10081 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10084 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
10086 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
10088 local_define_builtin ("__builtin_return_address", ftype
,
10089 BUILT_IN_RETURN_ADDRESS
,
10090 "__builtin_return_address",
10094 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
10095 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10097 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
10098 ptr_type_node
, NULL_TREE
);
10099 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
10100 local_define_builtin ("__cyg_profile_func_enter", ftype
,
10101 BUILT_IN_PROFILE_FUNC_ENTER
,
10102 "__cyg_profile_func_enter", 0);
10103 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
10104 local_define_builtin ("__cyg_profile_func_exit", ftype
,
10105 BUILT_IN_PROFILE_FUNC_EXIT
,
10106 "__cyg_profile_func_exit", 0);
10109 /* The exception object and filter values from the runtime. The argument
10110 must be zero before exception lowering, i.e. from the front end. After
10111 exception lowering, it will be the region number for the exception
10112 landing pad. These functions are PURE instead of CONST to prevent
10113 them from being hoisted past the exception edge that will initialize
10114 its value in the landing pad. */
10115 ftype
= build_function_type_list (ptr_type_node
,
10116 integer_type_node
, NULL_TREE
);
10117 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
10118 /* Only use TM_PURE if we we have TM language support. */
10119 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
10120 ecf_flags
|= ECF_TM_PURE
;
10121 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
10122 "__builtin_eh_pointer", ecf_flags
);
10124 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
10125 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
10126 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
10127 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
10129 ftype
= build_function_type_list (void_type_node
,
10130 integer_type_node
, integer_type_node
,
10132 local_define_builtin ("__builtin_eh_copy_values", ftype
,
10133 BUILT_IN_EH_COPY_VALUES
,
10134 "__builtin_eh_copy_values", ECF_NOTHROW
);
10136 /* Complex multiplication and division. These are handled as builtins
10137 rather than optabs because emit_library_call_value doesn't support
10138 complex. Further, we can do slightly better with folding these
10139 beasties if the real and complex parts of the arguments are separate. */
10143 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
10145 char mode_name_buf
[4], *q
;
10147 enum built_in_function mcode
, dcode
;
10148 tree type
, inner_type
;
10149 const char *prefix
= "__";
10151 if (targetm
.libfunc_gnu_prefix
)
10154 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
10157 inner_type
= TREE_TYPE (type
);
10159 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
10160 inner_type
, inner_type
, NULL_TREE
);
10162 mcode
= ((enum built_in_function
)
10163 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10164 dcode
= ((enum built_in_function
)
10165 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10167 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
10171 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
10173 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
10174 built_in_names
[mcode
],
10175 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10177 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
10179 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
10180 built_in_names
[dcode
],
10181 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10186 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10189 If we requested a pointer to a vector, build up the pointers that
10190 we stripped off while looking for the inner type. Similarly for
10191 return values from functions.
10193 The argument TYPE is the top of the chain, and BOTTOM is the
10194 new type which we will point to. */
10197 reconstruct_complex_type (tree type
, tree bottom
)
10201 if (TREE_CODE (type
) == POINTER_TYPE
)
10203 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10204 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
10205 TYPE_REF_CAN_ALIAS_ALL (type
));
10207 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
10209 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10210 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
10211 TYPE_REF_CAN_ALIAS_ALL (type
));
10213 else if (TREE_CODE (type
) == ARRAY_TYPE
)
10215 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10216 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
10218 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
10220 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10221 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
10223 else if (TREE_CODE (type
) == METHOD_TYPE
)
10225 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10226 /* The build_method_type_directly() routine prepends 'this' to argument list,
10227 so we must compensate by getting rid of it. */
10229 = build_method_type_directly
10230 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
10232 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
10234 else if (TREE_CODE (type
) == OFFSET_TYPE
)
10236 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10237 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
10242 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
10243 TYPE_QUALS (type
));
10246 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10249 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
10253 switch (GET_MODE_CLASS (mode
))
10255 case MODE_VECTOR_INT
:
10256 case MODE_VECTOR_FLOAT
:
10257 case MODE_VECTOR_FRACT
:
10258 case MODE_VECTOR_UFRACT
:
10259 case MODE_VECTOR_ACCUM
:
10260 case MODE_VECTOR_UACCUM
:
10261 nunits
= GET_MODE_NUNITS (mode
);
10265 /* Check that there are no leftover bits. */
10266 gcc_assert (GET_MODE_BITSIZE (mode
)
10267 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
10269 nunits
= GET_MODE_BITSIZE (mode
)
10270 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
10274 gcc_unreachable ();
10277 return make_vector_type (innertype
, nunits
, mode
);
10280 /* Similarly, but takes the inner type and number of units, which must be
10284 build_vector_type (tree innertype
, int nunits
)
10286 return make_vector_type (innertype
, nunits
, VOIDmode
);
10289 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10292 build_opaque_vector_type (tree innertype
, int nunits
)
10294 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
10296 /* We always build the non-opaque variant before the opaque one,
10297 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10298 cand
= TYPE_NEXT_VARIANT (t
);
10300 && TYPE_VECTOR_OPAQUE (cand
)
10301 && check_qualified_type (cand
, t
, TYPE_QUALS (t
)))
10303 /* Othewise build a variant type and make sure to queue it after
10304 the non-opaque type. */
10305 cand
= build_distinct_type_copy (t
);
10306 TYPE_VECTOR_OPAQUE (cand
) = true;
10307 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
10308 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
10309 TYPE_NEXT_VARIANT (t
) = cand
;
10310 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
10315 /* Given an initializer INIT, return TRUE if INIT is zero or some
10316 aggregate of zeros. Otherwise return FALSE. */
10318 initializer_zerop (const_tree init
)
10324 switch (TREE_CODE (init
))
10327 return integer_zerop (init
);
10330 /* ??? Note that this is not correct for C4X float formats. There,
10331 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10332 negative exponent. */
10333 return real_zerop (init
)
10334 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
10337 return fixed_zerop (init
);
10340 return integer_zerop (init
)
10341 || (real_zerop (init
)
10342 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10343 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
10348 for (i
= 0; i
< VECTOR_CST_NELTS (init
); ++i
)
10349 if (!initializer_zerop (VECTOR_CST_ELT (init
, i
)))
10356 unsigned HOST_WIDE_INT idx
;
10358 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10359 if (!initializer_zerop (elt
))
10368 /* We need to loop through all elements to handle cases like
10369 "\0" and "\0foobar". */
10370 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
10371 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10382 /* Check if vector VEC consists of all the equal elements and
10383 that the number of elements corresponds to the type of VEC.
10384 The function returns first element of the vector
10385 or NULL_TREE if the vector is not uniform. */
10387 uniform_vector_p (const_tree vec
)
10392 if (vec
== NULL_TREE
)
10395 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10397 if (TREE_CODE (vec
) == VECTOR_CST
)
10399 first
= VECTOR_CST_ELT (vec
, 0);
10400 for (i
= 1; i
< VECTOR_CST_NELTS (vec
); ++i
)
10401 if (!operand_equal_p (first
, VECTOR_CST_ELT (vec
, i
), 0))
10407 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
10409 first
= error_mark_node
;
10411 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10418 if (!operand_equal_p (first
, t
, 0))
10421 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
10430 /* Build an empty statement at location LOC. */
10433 build_empty_stmt (location_t loc
)
10435 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10436 SET_EXPR_LOCATION (t
, loc
);
10441 /* Build an OpenMP clause with code CODE. LOC is the location of the
10445 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10450 length
= omp_clause_num_ops
[code
];
10451 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10453 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10455 t
= ggc_alloc_tree_node (size
);
10456 memset (t
, 0, size
);
10457 TREE_SET_CODE (t
, OMP_CLAUSE
);
10458 OMP_CLAUSE_SET_CODE (t
, code
);
10459 OMP_CLAUSE_LOCATION (t
) = loc
;
10464 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10465 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10466 Except for the CODE and operand count field, other storage for the
10467 object is initialized to zeros. */
10470 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
10473 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10475 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10476 gcc_assert (len
>= 1);
10478 record_node_allocation_statistics (code
, length
);
10480 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10482 TREE_SET_CODE (t
, code
);
10484 /* Can't use TREE_OPERAND to store the length because if checking is
10485 enabled, it will try to check the length before we store it. :-P */
10486 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10491 /* Helper function for build_call_* functions; build a CALL_EXPR with
10492 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10493 the argument slots. */
10496 build_call_1 (tree return_type
, tree fn
, int nargs
)
10500 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10501 TREE_TYPE (t
) = return_type
;
10502 CALL_EXPR_FN (t
) = fn
;
10503 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10508 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10509 FN and a null static chain slot. NARGS is the number of call arguments
10510 which are specified as "..." arguments. */
10513 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10517 va_start (args
, nargs
);
10518 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10523 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10524 FN and a null static chain slot. NARGS is the number of call arguments
10525 which are specified as a va_list ARGS. */
10528 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10533 t
= build_call_1 (return_type
, fn
, nargs
);
10534 for (i
= 0; i
< nargs
; i
++)
10535 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10536 process_call_operands (t
);
10540 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10541 FN and a null static chain slot. NARGS is the number of call arguments
10542 which are specified as a tree array ARGS. */
10545 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10546 int nargs
, const tree
*args
)
10551 t
= build_call_1 (return_type
, fn
, nargs
);
10552 for (i
= 0; i
< nargs
; i
++)
10553 CALL_EXPR_ARG (t
, i
) = args
[i
];
10554 process_call_operands (t
);
10555 SET_EXPR_LOCATION (t
, loc
);
10559 /* Like build_call_array, but takes a vec. */
10562 build_call_vec (tree return_type
, tree fn
, vec
<tree
, va_gc
> *args
)
10567 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10568 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10569 CALL_EXPR_ARG (ret
, ix
) = t
;
10570 process_call_operands (ret
);
10575 /* Returns true if it is possible to prove that the index of
10576 an array access REF (an ARRAY_REF expression) falls into the
10580 in_array_bounds_p (tree ref
)
10582 tree idx
= TREE_OPERAND (ref
, 1);
10585 if (TREE_CODE (idx
) != INTEGER_CST
)
10588 min
= array_ref_low_bound (ref
);
10589 max
= array_ref_up_bound (ref
);
10592 || TREE_CODE (min
) != INTEGER_CST
10593 || TREE_CODE (max
) != INTEGER_CST
)
10596 if (tree_int_cst_lt (idx
, min
)
10597 || tree_int_cst_lt (max
, idx
))
10603 /* Returns true if it is possible to prove that the range of
10604 an array access REF (an ARRAY_RANGE_REF expression) falls
10605 into the array bounds. */
10608 range_in_array_bounds_p (tree ref
)
10610 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
10611 tree range_min
, range_max
, min
, max
;
10613 range_min
= TYPE_MIN_VALUE (domain_type
);
10614 range_max
= TYPE_MAX_VALUE (domain_type
);
10617 || TREE_CODE (range_min
) != INTEGER_CST
10618 || TREE_CODE (range_max
) != INTEGER_CST
)
10621 min
= array_ref_low_bound (ref
);
10622 max
= array_ref_up_bound (ref
);
10625 || TREE_CODE (min
) != INTEGER_CST
10626 || TREE_CODE (max
) != INTEGER_CST
)
10629 if (tree_int_cst_lt (range_min
, min
)
10630 || tree_int_cst_lt (max
, range_max
))
10636 /* Return true if T (assumed to be a DECL) must be assigned a memory
10640 needs_to_live_in_memory (const_tree t
)
10642 return (TREE_ADDRESSABLE (t
)
10643 || is_global_var (t
)
10644 || (TREE_CODE (t
) == RESULT_DECL
10645 && !DECL_BY_REFERENCE (t
)
10646 && aggregate_value_p (t
, current_function_decl
)));
10649 /* Return value of a constant X and sign-extend it. */
10652 int_cst_value (const_tree x
)
10654 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10655 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
10657 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10658 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10659 || TREE_INT_CST_HIGH (x
) == -1);
10661 if (bits
< HOST_BITS_PER_WIDE_INT
)
10663 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10665 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
10667 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
10673 /* Return value of a constant X and sign-extend it. */
10676 widest_int_cst_value (const_tree x
)
10678 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10679 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
10681 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
10682 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= HOST_BITS_PER_DOUBLE_INT
);
10683 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
10684 << HOST_BITS_PER_WIDE_INT
);
10686 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10687 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10688 || TREE_INT_CST_HIGH (x
) == -1);
10691 if (bits
< HOST_BITS_PER_WIDEST_INT
)
10693 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10695 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
10697 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
10703 /* If TYPE is an integral or pointer type, return an integer type with
10704 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10705 if TYPE is already an integer type of signedness UNSIGNEDP. */
10708 signed_or_unsigned_type_for (int unsignedp
, tree type
)
10710 if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
) == unsignedp
)
10713 if (TREE_CODE (type
) == VECTOR_TYPE
)
10715 tree inner
= TREE_TYPE (type
);
10716 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
10719 if (inner
== inner2
)
10721 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
10724 if (!INTEGRAL_TYPE_P (type
)
10725 && !POINTER_TYPE_P (type
))
10728 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
10731 /* If TYPE is an integral or pointer type, return an integer type with
10732 the same precision which is unsigned, or itself if TYPE is already an
10733 unsigned integer type. */
10736 unsigned_type_for (tree type
)
10738 return signed_or_unsigned_type_for (1, type
);
10741 /* If TYPE is an integral or pointer type, return an integer type with
10742 the same precision which is signed, or itself if TYPE is already a
10743 signed integer type. */
10746 signed_type_for (tree type
)
10748 return signed_or_unsigned_type_for (0, type
);
10751 /* If TYPE is a vector type, return a signed integer vector type with the
10752 same width and number of subparts. Otherwise return boolean_type_node. */
10755 truth_type_for (tree type
)
10757 if (TREE_CODE (type
) == VECTOR_TYPE
)
10759 tree elem
= lang_hooks
.types
.type_for_size
10760 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type
))), 0);
10761 return build_opaque_vector_type (elem
, TYPE_VECTOR_SUBPARTS (type
));
10764 return boolean_type_node
;
10767 /* Returns the largest value obtainable by casting something in INNER type to
10771 upper_bound_in_type (tree outer
, tree inner
)
10774 unsigned int det
= 0;
10775 unsigned oprec
= TYPE_PRECISION (outer
);
10776 unsigned iprec
= TYPE_PRECISION (inner
);
10779 /* Compute a unique number for every combination. */
10780 det
|= (oprec
> iprec
) ? 4 : 0;
10781 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10782 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10784 /* Determine the exponent to use. */
10789 /* oprec <= iprec, outer: signed, inner: don't care. */
10794 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10798 /* oprec > iprec, outer: signed, inner: signed. */
10802 /* oprec > iprec, outer: signed, inner: unsigned. */
10806 /* oprec > iprec, outer: unsigned, inner: signed. */
10810 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10814 gcc_unreachable ();
10817 /* Compute 2^^prec - 1. */
10818 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10821 high
.low
= ((~(unsigned HOST_WIDE_INT
) 0)
10822 >> (HOST_BITS_PER_WIDE_INT
- prec
));
10826 high
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10827 >> (HOST_BITS_PER_DOUBLE_INT
- prec
));
10828 high
.low
= ~(unsigned HOST_WIDE_INT
) 0;
10831 return double_int_to_tree (outer
, high
);
10834 /* Returns the smallest value obtainable by casting something in INNER type to
10838 lower_bound_in_type (tree outer
, tree inner
)
10841 unsigned oprec
= TYPE_PRECISION (outer
);
10842 unsigned iprec
= TYPE_PRECISION (inner
);
10844 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10846 if (TYPE_UNSIGNED (outer
)
10847 /* If we are widening something of an unsigned type, OUTER type
10848 contains all values of INNER type. In particular, both INNER
10849 and OUTER types have zero in common. */
10850 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10851 low
.low
= low
.high
= 0;
10854 /* If we are widening a signed type to another signed type, we
10855 want to obtain -2^^(iprec-1). If we are keeping the
10856 precision or narrowing to a signed type, we want to obtain
10858 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10860 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10862 low
.high
= ~(unsigned HOST_WIDE_INT
) 0;
10863 low
.low
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
10867 low
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10868 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
10873 return double_int_to_tree (outer
, low
);
10876 /* Return nonzero if two operands that are suitable for PHI nodes are
10877 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10878 SSA_NAME or invariant. Note that this is strictly an optimization.
10879 That is, callers of this function can directly call operand_equal_p
10880 and get the same result, only slower. */
10883 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10887 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10889 return operand_equal_p (arg0
, arg1
, 0);
10892 /* Returns number of zeros at the end of binary representation of X.
10894 ??? Use ffs if available? */
10897 num_ending_zeros (const_tree x
)
10899 unsigned HOST_WIDE_INT fr
, nfr
;
10900 unsigned num
, abits
;
10901 tree type
= TREE_TYPE (x
);
10903 if (TREE_INT_CST_LOW (x
) == 0)
10905 num
= HOST_BITS_PER_WIDE_INT
;
10906 fr
= TREE_INT_CST_HIGH (x
);
10911 fr
= TREE_INT_CST_LOW (x
);
10914 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
10917 if (nfr
<< abits
== fr
)
10924 if (num
> TYPE_PRECISION (type
))
10925 num
= TYPE_PRECISION (type
);
10927 return build_int_cst_type (type
, num
);
10931 #define WALK_SUBTREE(NODE) \
10934 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10940 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10941 be walked whenever a type is seen in the tree. Rest of operands and return
10942 value are as for walk_tree. */
10945 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10946 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10948 tree result
= NULL_TREE
;
10950 switch (TREE_CODE (type
))
10953 case REFERENCE_TYPE
:
10954 /* We have to worry about mutually recursive pointers. These can't
10955 be written in C. They can in Ada. It's pathological, but
10956 there's an ACATS test (c38102a) that checks it. Deal with this
10957 by checking if we're pointing to another pointer, that one
10958 points to another pointer, that one does too, and we have no htab.
10959 If so, get a hash table. We check three levels deep to avoid
10960 the cost of the hash table if we don't need one. */
10961 if (POINTER_TYPE_P (TREE_TYPE (type
))
10962 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10963 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10966 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10974 /* ... fall through ... */
10977 WALK_SUBTREE (TREE_TYPE (type
));
10981 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10983 /* Fall through. */
10985 case FUNCTION_TYPE
:
10986 WALK_SUBTREE (TREE_TYPE (type
));
10990 /* We never want to walk into default arguments. */
10991 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
10992 WALK_SUBTREE (TREE_VALUE (arg
));
10997 /* Don't follow this nodes's type if a pointer for fear that
10998 we'll have infinite recursion. If we have a PSET, then we
11001 || (!POINTER_TYPE_P (TREE_TYPE (type
))
11002 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
11003 WALK_SUBTREE (TREE_TYPE (type
));
11004 WALK_SUBTREE (TYPE_DOMAIN (type
));
11008 WALK_SUBTREE (TREE_TYPE (type
));
11009 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
11019 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11020 called with the DATA and the address of each sub-tree. If FUNC returns a
11021 non-NULL value, the traversal is stopped, and the value returned by FUNC
11022 is returned. If PSET is non-NULL it is used to record the nodes visited,
11023 and to avoid visiting a node more than once. */
11026 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11027 struct pointer_set_t
*pset
, walk_tree_lh lh
)
11029 enum tree_code code
;
11033 #define WALK_SUBTREE_TAIL(NODE) \
11037 goto tail_recurse; \
11042 /* Skip empty subtrees. */
11046 /* Don't walk the same tree twice, if the user has requested
11047 that we avoid doing so. */
11048 if (pset
&& pointer_set_insert (pset
, *tp
))
11051 /* Call the function. */
11053 result
= (*func
) (tp
, &walk_subtrees
, data
);
11055 /* If we found something, return it. */
11059 code
= TREE_CODE (*tp
);
11061 /* Even if we didn't, FUNC may have decided that there was nothing
11062 interesting below this point in the tree. */
11063 if (!walk_subtrees
)
11065 /* But we still need to check our siblings. */
11066 if (code
== TREE_LIST
)
11067 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11068 else if (code
== OMP_CLAUSE
)
11069 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11076 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
11077 if (result
|| !walk_subtrees
)
11084 case IDENTIFIER_NODE
:
11091 case PLACEHOLDER_EXPR
:
11095 /* None of these have subtrees other than those already walked
11100 WALK_SUBTREE (TREE_VALUE (*tp
));
11101 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
11106 int len
= TREE_VEC_LENGTH (*tp
);
11111 /* Walk all elements but the first. */
11113 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
11115 /* Now walk the first one as a tail call. */
11116 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
11120 WALK_SUBTREE (TREE_REALPART (*tp
));
11121 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
11125 unsigned HOST_WIDE_INT idx
;
11126 constructor_elt
*ce
;
11128 for (idx
= 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*tp
), idx
, &ce
);
11130 WALK_SUBTREE (ce
->value
);
11135 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
11140 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
11142 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11143 into declarations that are just mentioned, rather than
11144 declared; they don't really belong to this part of the tree.
11145 And, we can see cycles: the initializer for a declaration
11146 can refer to the declaration itself. */
11147 WALK_SUBTREE (DECL_INITIAL (decl
));
11148 WALK_SUBTREE (DECL_SIZE (decl
));
11149 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
11151 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
11154 case STATEMENT_LIST
:
11156 tree_stmt_iterator i
;
11157 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
11158 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11163 switch (OMP_CLAUSE_CODE (*tp
))
11165 case OMP_CLAUSE_PRIVATE
:
11166 case OMP_CLAUSE_SHARED
:
11167 case OMP_CLAUSE_FIRSTPRIVATE
:
11168 case OMP_CLAUSE_COPYIN
:
11169 case OMP_CLAUSE_COPYPRIVATE
:
11170 case OMP_CLAUSE_FINAL
:
11171 case OMP_CLAUSE_IF
:
11172 case OMP_CLAUSE_NUM_THREADS
:
11173 case OMP_CLAUSE_SCHEDULE
:
11174 case OMP_CLAUSE_UNIFORM
:
11175 case OMP_CLAUSE_DEPEND
:
11176 case OMP_CLAUSE_NUM_TEAMS
:
11177 case OMP_CLAUSE_THREAD_LIMIT
:
11178 case OMP_CLAUSE_DEVICE
:
11179 case OMP_CLAUSE_DIST_SCHEDULE
:
11180 case OMP_CLAUSE_SAFELEN
:
11181 case OMP_CLAUSE_SIMDLEN
:
11182 case OMP_CLAUSE__LOOPTEMP_
:
11183 case OMP_CLAUSE__SIMDUID_
:
11184 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
11187 case OMP_CLAUSE_NOWAIT
:
11188 case OMP_CLAUSE_ORDERED
:
11189 case OMP_CLAUSE_DEFAULT
:
11190 case OMP_CLAUSE_UNTIED
:
11191 case OMP_CLAUSE_MERGEABLE
:
11192 case OMP_CLAUSE_PROC_BIND
:
11193 case OMP_CLAUSE_INBRANCH
:
11194 case OMP_CLAUSE_NOTINBRANCH
:
11195 case OMP_CLAUSE_FOR
:
11196 case OMP_CLAUSE_PARALLEL
:
11197 case OMP_CLAUSE_SECTIONS
:
11198 case OMP_CLAUSE_TASKGROUP
:
11199 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11201 case OMP_CLAUSE_LASTPRIVATE
:
11202 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11203 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
11204 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11206 case OMP_CLAUSE_COLLAPSE
:
11209 for (i
= 0; i
< 3; i
++)
11210 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11211 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11214 case OMP_CLAUSE_ALIGNED
:
11215 case OMP_CLAUSE_LINEAR
:
11216 case OMP_CLAUSE_FROM
:
11217 case OMP_CLAUSE_TO
:
11218 case OMP_CLAUSE_MAP
:
11219 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11220 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 1));
11221 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11223 case OMP_CLAUSE_REDUCTION
:
11226 for (i
= 0; i
< 4; i
++)
11227 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11228 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11232 gcc_unreachable ();
11240 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11241 But, we only want to walk once. */
11242 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11243 for (i
= 0; i
< len
; ++i
)
11244 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11245 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11249 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11250 defining. We only want to walk into these fields of a type in this
11251 case and not in the general case of a mere reference to the type.
11253 The criterion is as follows: if the field can be an expression, it
11254 must be walked only here. This should be in keeping with the fields
11255 that are directly gimplified in gimplify_type_sizes in order for the
11256 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11257 variable-sized types.
11259 Note that DECLs get walked as part of processing the BIND_EXPR. */
11260 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11262 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11263 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11266 /* Call the function for the type. See if it returns anything or
11267 doesn't want us to continue. If we are to continue, walk both
11268 the normal fields and those for the declaration case. */
11269 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11270 if (result
|| !walk_subtrees
)
11273 /* But do not walk a pointed-to type since it may itself need to
11274 be walked in the declaration case if it isn't anonymous. */
11275 if (!POINTER_TYPE_P (*type_p
))
11277 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11282 /* If this is a record type, also walk the fields. */
11283 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11287 for (field
= TYPE_FIELDS (*type_p
); field
;
11288 field
= DECL_CHAIN (field
))
11290 /* We'd like to look at the type of the field, but we can
11291 easily get infinite recursion. So assume it's pointed
11292 to elsewhere in the tree. Also, ignore things that
11294 if (TREE_CODE (field
) != FIELD_DECL
)
11297 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11298 WALK_SUBTREE (DECL_SIZE (field
));
11299 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11300 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11301 WALK_SUBTREE (DECL_QUALIFIER (field
));
11305 /* Same for scalar types. */
11306 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11307 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11308 || TREE_CODE (*type_p
) == INTEGER_TYPE
11309 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11310 || TREE_CODE (*type_p
) == REAL_TYPE
)
11312 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11313 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11316 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11317 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11322 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11326 /* Walk over all the sub-trees of this operand. */
11327 len
= TREE_OPERAND_LENGTH (*tp
);
11329 /* Go through the subtrees. We need to do this in forward order so
11330 that the scope of a FOR_EXPR is handled properly. */
11333 for (i
= 0; i
< len
- 1; ++i
)
11334 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11335 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11338 /* If this is a type, walk the needed fields in the type. */
11339 else if (TYPE_P (*tp
))
11340 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11344 /* We didn't find what we were looking for. */
11347 #undef WALK_SUBTREE_TAIL
11349 #undef WALK_SUBTREE
11351 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11354 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11358 struct pointer_set_t
*pset
;
11360 pset
= pointer_set_create ();
11361 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
11362 pointer_set_destroy (pset
);
11368 tree_block (tree t
)
11370 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11372 if (IS_EXPR_CODE_CLASS (c
))
11373 return LOCATION_BLOCK (t
->exp
.locus
);
11374 gcc_unreachable ();
11379 tree_set_block (tree t
, tree b
)
11381 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11383 if (IS_EXPR_CODE_CLASS (c
))
11386 t
->exp
.locus
= COMBINE_LOCATION_DATA (line_table
, t
->exp
.locus
, b
);
11388 t
->exp
.locus
= LOCATION_LOCUS (t
->exp
.locus
);
11391 gcc_unreachable ();
11394 /* Create a nameless artificial label and put it in the current
11395 function context. The label has a location of LOC. Returns the
11396 newly created label. */
11399 create_artificial_label (location_t loc
)
11401 tree lab
= build_decl (loc
,
11402 LABEL_DECL
, NULL_TREE
, void_type_node
);
11404 DECL_ARTIFICIAL (lab
) = 1;
11405 DECL_IGNORED_P (lab
) = 1;
11406 DECL_CONTEXT (lab
) = current_function_decl
;
11410 /* Given a tree, try to return a useful variable name that we can use
11411 to prefix a temporary that is being assigned the value of the tree.
11412 I.E. given <temp> = &A, return A. */
11417 tree stripped_decl
;
11420 STRIP_NOPS (stripped_decl
);
11421 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11422 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11423 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11425 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11428 return IDENTIFIER_POINTER (name
);
11432 switch (TREE_CODE (stripped_decl
))
11435 return get_name (TREE_OPERAND (stripped_decl
, 0));
11442 /* Return true if TYPE has a variable argument list. */
11445 stdarg_p (const_tree fntype
)
11447 function_args_iterator args_iter
;
11448 tree n
= NULL_TREE
, t
;
11453 FOREACH_FUNCTION_ARGS (fntype
, t
, args_iter
)
11458 return n
!= NULL_TREE
&& n
!= void_type_node
;
11461 /* Return true if TYPE has a prototype. */
11464 prototype_p (tree fntype
)
11468 gcc_assert (fntype
!= NULL_TREE
);
11470 t
= TYPE_ARG_TYPES (fntype
);
11471 return (t
!= NULL_TREE
);
11474 /* If BLOCK is inlined from an __attribute__((__artificial__))
11475 routine, return pointer to location from where it has been
11478 block_nonartificial_location (tree block
)
11480 location_t
*ret
= NULL
;
11482 while (block
&& TREE_CODE (block
) == BLOCK
11483 && BLOCK_ABSTRACT_ORIGIN (block
))
11485 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11487 while (TREE_CODE (ao
) == BLOCK
11488 && BLOCK_ABSTRACT_ORIGIN (ao
)
11489 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
11490 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
11492 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11494 /* If AO is an artificial inline, point RET to the
11495 call site locus at which it has been inlined and continue
11496 the loop, in case AO's caller is also an artificial
11498 if (DECL_DECLARED_INLINE_P (ao
)
11499 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11500 ret
= &BLOCK_SOURCE_LOCATION (block
);
11504 else if (TREE_CODE (ao
) != BLOCK
)
11507 block
= BLOCK_SUPERCONTEXT (block
);
11513 /* If EXP is inlined from an __attribute__((__artificial__))
11514 function, return the location of the original call expression. */
11517 tree_nonartificial_location (tree exp
)
11519 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11524 return EXPR_LOCATION (exp
);
11528 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11531 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11534 cl_option_hash_hash (const void *x
)
11536 const_tree
const t
= (const_tree
) x
;
11540 hashval_t hash
= 0;
11542 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11544 p
= (const char *)TREE_OPTIMIZATION (t
);
11545 len
= sizeof (struct cl_optimization
);
11548 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11550 p
= (const char *)TREE_TARGET_OPTION (t
);
11551 len
= sizeof (struct cl_target_option
);
11555 gcc_unreachable ();
11557 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11559 for (i
= 0; i
< len
; i
++)
11561 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
11566 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11567 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11571 cl_option_hash_eq (const void *x
, const void *y
)
11573 const_tree
const xt
= (const_tree
) x
;
11574 const_tree
const yt
= (const_tree
) y
;
11579 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11582 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11584 xp
= (const char *)TREE_OPTIMIZATION (xt
);
11585 yp
= (const char *)TREE_OPTIMIZATION (yt
);
11586 len
= sizeof (struct cl_optimization
);
11589 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11591 xp
= (const char *)TREE_TARGET_OPTION (xt
);
11592 yp
= (const char *)TREE_TARGET_OPTION (yt
);
11593 len
= sizeof (struct cl_target_option
);
11597 gcc_unreachable ();
11599 return (memcmp (xp
, yp
, len
) == 0);
11602 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */
11605 build_optimization_node (struct gcc_options
*opts
)
11610 /* Use the cache of optimization nodes. */
11612 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
11615 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
11619 /* Insert this one into the hash table. */
11620 t
= cl_optimization_node
;
11623 /* Make a new node for next time round. */
11624 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
11630 /* Build a TARGET_OPTION_NODE based on the options in OPTS. */
11633 build_target_option_node (struct gcc_options
*opts
)
11638 /* Use the cache of optimization nodes. */
11640 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
11643 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
11647 /* Insert this one into the hash table. */
11648 t
= cl_target_option_node
;
11651 /* Make a new node for next time round. */
11652 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
11658 /* Determine the "ultimate origin" of a block. The block may be an inlined
11659 instance of an inlined instance of a block which is local to an inline
11660 function, so we have to trace all of the way back through the origin chain
11661 to find out what sort of node actually served as the original seed for the
11665 block_ultimate_origin (const_tree block
)
11667 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
11669 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
11670 nodes in the function to point to themselves; ignore that if
11671 we're trying to output the abstract instance of this function. */
11672 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
11675 if (immediate_origin
== NULL_TREE
)
11680 tree lookahead
= immediate_origin
;
11684 ret_val
= lookahead
;
11685 lookahead
= (TREE_CODE (ret_val
) == BLOCK
11686 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
11688 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
11690 /* The block's abstract origin chain may not be the *ultimate* origin of
11691 the block. It could lead to a DECL that has an abstract origin set.
11692 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11693 will give us if it has one). Note that DECL's abstract origins are
11694 supposed to be the most distant ancestor (or so decl_ultimate_origin
11695 claims), so we don't need to loop following the DECL origins. */
11696 if (DECL_P (ret_val
))
11697 return DECL_ORIGIN (ret_val
);
11703 /* Return true if T1 and T2 are equivalent lists. */
11706 list_equal_p (const_tree t1
, const_tree t2
)
11708 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
11709 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
11714 /* Return true iff conversion in EXP generates no instruction. Mark
11715 it inline so that we fully inline into the stripping functions even
11716 though we have two uses of this function. */
11719 tree_nop_conversion (const_tree exp
)
11721 tree outer_type
, inner_type
;
11723 if (!CONVERT_EXPR_P (exp
)
11724 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
11726 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
11729 outer_type
= TREE_TYPE (exp
);
11730 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11735 /* Use precision rather then machine mode when we can, which gives
11736 the correct answer even for submode (bit-field) types. */
11737 if ((INTEGRAL_TYPE_P (outer_type
)
11738 || POINTER_TYPE_P (outer_type
)
11739 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
11740 && (INTEGRAL_TYPE_P (inner_type
)
11741 || POINTER_TYPE_P (inner_type
)
11742 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
11743 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
11745 /* Otherwise fall back on comparing machine modes (e.g. for
11746 aggregate types, floats). */
11747 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
11750 /* Return true iff conversion in EXP generates no instruction. Don't
11751 consider conversions changing the signedness. */
11754 tree_sign_nop_conversion (const_tree exp
)
11756 tree outer_type
, inner_type
;
11758 if (!tree_nop_conversion (exp
))
11761 outer_type
= TREE_TYPE (exp
);
11762 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11764 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
11765 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
11768 /* Strip conversions from EXP according to tree_nop_conversion and
11769 return the resulting expression. */
11772 tree_strip_nop_conversions (tree exp
)
11774 while (tree_nop_conversion (exp
))
11775 exp
= TREE_OPERAND (exp
, 0);
11779 /* Strip conversions from EXP according to tree_sign_nop_conversion
11780 and return the resulting expression. */
11783 tree_strip_sign_nop_conversions (tree exp
)
11785 while (tree_sign_nop_conversion (exp
))
11786 exp
= TREE_OPERAND (exp
, 0);
11790 /* Avoid any floating point extensions from EXP. */
11792 strip_float_extensions (tree exp
)
11794 tree sub
, expt
, subt
;
11796 /* For floating point constant look up the narrowest type that can hold
11797 it properly and handle it like (type)(narrowest_type)constant.
11798 This way we can optimize for instance a=a*2.0 where "a" is float
11799 but 2.0 is double constant. */
11800 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
11802 REAL_VALUE_TYPE orig
;
11805 orig
= TREE_REAL_CST (exp
);
11806 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
11807 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
11808 type
= float_type_node
;
11809 else if (TYPE_PRECISION (TREE_TYPE (exp
))
11810 > TYPE_PRECISION (double_type_node
)
11811 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
11812 type
= double_type_node
;
11814 return build_real (type
, real_value_truncate (TYPE_MODE (type
), orig
));
11817 if (!CONVERT_EXPR_P (exp
))
11820 sub
= TREE_OPERAND (exp
, 0);
11821 subt
= TREE_TYPE (sub
);
11822 expt
= TREE_TYPE (exp
);
11824 if (!FLOAT_TYPE_P (subt
))
11827 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
11830 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
11833 return strip_float_extensions (sub
);
11836 /* Strip out all handled components that produce invariant
11840 strip_invariant_refs (const_tree op
)
11842 while (handled_component_p (op
))
11844 switch (TREE_CODE (op
))
11847 case ARRAY_RANGE_REF
:
11848 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
11849 || TREE_OPERAND (op
, 2) != NULL_TREE
11850 || TREE_OPERAND (op
, 3) != NULL_TREE
)
11854 case COMPONENT_REF
:
11855 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
11861 op
= TREE_OPERAND (op
, 0);
11867 static GTY(()) tree gcc_eh_personality_decl
;
11869 /* Return the GCC personality function decl. */
11872 lhd_gcc_personality (void)
11874 if (!gcc_eh_personality_decl
)
11875 gcc_eh_personality_decl
= build_personality_function ("gcc");
11876 return gcc_eh_personality_decl
;
11879 /* For languages with One Definition Rule, work out if
11880 trees are actually the same even if the tree representation
11881 differs. This handles only decls appearing in TYPE_NAME
11882 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11883 RECORD_TYPE and IDENTIFIER_NODE. */
11886 same_for_odr (tree t1
, tree t2
)
11892 /* C and C++ FEs differ by using IDENTIFIER_NODE and TYPE_DECL. */
11893 if (TREE_CODE (t1
) == IDENTIFIER_NODE
11894 && TREE_CODE (t2
) == TYPE_DECL
11895 && DECL_FILE_SCOPE_P (t1
))
11897 t2
= DECL_NAME (t2
);
11898 gcc_assert (TREE_CODE (t2
) == IDENTIFIER_NODE
);
11900 if (TREE_CODE (t2
) == IDENTIFIER_NODE
11901 && TREE_CODE (t1
) == TYPE_DECL
11902 && DECL_FILE_SCOPE_P (t2
))
11904 t1
= DECL_NAME (t1
);
11905 gcc_assert (TREE_CODE (t1
) == IDENTIFIER_NODE
);
11907 if (TREE_CODE (t1
) != TREE_CODE (t2
))
11910 return types_same_for_odr (t1
, t2
);
11912 return decls_same_for_odr (t1
, t2
);
11916 /* For languages with One Definition Rule, work out if
11917 decls are actually the same even if the tree representation
11918 differs. This handles only decls appearing in TYPE_NAME
11919 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11920 RECORD_TYPE and IDENTIFIER_NODE. */
11923 decls_same_for_odr (tree decl1
, tree decl2
)
11925 if (decl1
&& TREE_CODE (decl1
) == TYPE_DECL
11926 && DECL_ORIGINAL_TYPE (decl1
))
11927 decl1
= DECL_ORIGINAL_TYPE (decl1
);
11928 if (decl2
&& TREE_CODE (decl2
) == TYPE_DECL
11929 && DECL_ORIGINAL_TYPE (decl2
))
11930 decl2
= DECL_ORIGINAL_TYPE (decl2
);
11931 if (decl1
== decl2
)
11933 if (!decl1
|| !decl2
)
11935 gcc_checking_assert (DECL_P (decl1
) && DECL_P (decl2
));
11936 if (TREE_CODE (decl1
) != TREE_CODE (decl2
))
11938 if (TREE_CODE (decl1
) == TRANSLATION_UNIT_DECL
)
11940 if (TREE_CODE (decl1
) != NAMESPACE_DECL
11941 && TREE_CODE (decl1
) != TYPE_DECL
)
11943 if (!DECL_NAME (decl1
))
11945 gcc_checking_assert (TREE_CODE (DECL_NAME (decl1
)) == IDENTIFIER_NODE
);
11946 gcc_checking_assert (!DECL_NAME (decl2
)
11947 || TREE_CODE (DECL_NAME (decl2
)) == IDENTIFIER_NODE
);
11948 if (DECL_NAME (decl1
) != DECL_NAME (decl2
))
11950 return same_for_odr (DECL_CONTEXT (decl1
),
11951 DECL_CONTEXT (decl2
));
11954 /* For languages with One Definition Rule, work out if
11955 types are same even if the tree representation differs.
11956 This is non-trivial for LTO where minnor differences in
11957 the type representation may have prevented type merging
11958 to merge two copies of otherwise equivalent type. */
11961 types_same_for_odr (tree type1
, tree type2
)
11963 gcc_checking_assert (TYPE_P (type1
) && TYPE_P (type2
));
11964 type1
= TYPE_MAIN_VARIANT (type1
);
11965 type2
= TYPE_MAIN_VARIANT (type2
);
11966 if (type1
== type2
)
11969 #ifndef ENABLE_CHECKING
11974 /* Check for anonymous namespaces. Those have !TREE_PUBLIC
11975 on the corresponding TYPE_STUB_DECL. */
11976 if (type_in_anonymous_namespace_p (type1
)
11977 || type_in_anonymous_namespace_p (type2
))
11979 /* When assembler name of virtual table is available, it is
11980 easy to compare types for equivalence. */
11981 if (TYPE_BINFO (type1
) && TYPE_BINFO (type2
)
11982 && BINFO_VTABLE (TYPE_BINFO (type1
))
11983 && BINFO_VTABLE (TYPE_BINFO (type2
)))
11985 tree v1
= BINFO_VTABLE (TYPE_BINFO (type1
));
11986 tree v2
= BINFO_VTABLE (TYPE_BINFO (type2
));
11988 if (TREE_CODE (v1
) == POINTER_PLUS_EXPR
)
11990 if (TREE_CODE (v2
) != POINTER_PLUS_EXPR
11991 || !operand_equal_p (TREE_OPERAND (v1
, 1),
11992 TREE_OPERAND (v2
, 1), 0))
11994 v1
= TREE_OPERAND (TREE_OPERAND (v1
, 0), 0);
11995 v2
= TREE_OPERAND (TREE_OPERAND (v2
, 0), 0);
11997 v1
= DECL_ASSEMBLER_NAME (v1
);
11998 v2
= DECL_ASSEMBLER_NAME (v2
);
12002 /* FIXME: the code comparing type names consider all instantiations of the
12003 same template to have same name. This is because we have no access
12004 to template parameters. For types with no virtual method tables
12005 we thus can return false positives. At the moment we do not need
12006 to compare types in other scenarios than devirtualization. */
12008 /* If types are not structuraly same, do not bother to contnue.
12009 Match in the remainder of code would mean ODR violation. */
12010 if (!types_compatible_p (type1
, type2
))
12012 if (!TYPE_NAME (type1
))
12014 if (!decls_same_for_odr (TYPE_NAME (type1
), TYPE_NAME (type2
)))
12016 if (!same_for_odr (TYPE_CONTEXT (type1
), TYPE_CONTEXT (type2
)))
12018 /* When not in LTO the MAIN_VARIANT check should be the same. */
12019 gcc_assert (in_lto_p
);
12024 /* TARGET is a call target of GIMPLE call statement
12025 (obtained by gimple_call_fn). Return true if it is
12026 OBJ_TYPE_REF representing an virtual call of C++ method.
12027 (As opposed to OBJ_TYPE_REF representing objc calls
12028 through a cast where middle-end devirtualization machinery
12032 virtual_method_call_p (tree target
)
12034 if (TREE_CODE (target
) != OBJ_TYPE_REF
)
12036 target
= TREE_TYPE (target
);
12037 gcc_checking_assert (TREE_CODE (target
) == POINTER_TYPE
);
12038 target
= TREE_TYPE (target
);
12039 if (TREE_CODE (target
) == FUNCTION_TYPE
)
12041 gcc_checking_assert (TREE_CODE (target
) == METHOD_TYPE
);
12045 /* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */
12048 obj_type_ref_class (tree ref
)
12050 gcc_checking_assert (TREE_CODE (ref
) == OBJ_TYPE_REF
);
12051 ref
= TREE_TYPE (ref
);
12052 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12053 ref
= TREE_TYPE (ref
);
12054 /* We look for type THIS points to. ObjC also builds
12055 OBJ_TYPE_REF with non-method calls, Their first parameter
12056 ID however also corresponds to class type. */
12057 gcc_checking_assert (TREE_CODE (ref
) == METHOD_TYPE
12058 || TREE_CODE (ref
) == FUNCTION_TYPE
);
12059 ref
= TREE_VALUE (TYPE_ARG_TYPES (ref
));
12060 gcc_checking_assert (TREE_CODE (ref
) == POINTER_TYPE
);
12061 return TREE_TYPE (ref
);
12064 /* Return true if T is in anonymous namespace. */
12067 type_in_anonymous_namespace_p (tree t
)
12069 return (TYPE_STUB_DECL (t
) && !TREE_PUBLIC (TYPE_STUB_DECL (t
)));
12072 /* Try to find a base info of BINFO that would have its field decl at offset
12073 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12074 found, return, otherwise return NULL_TREE. */
12077 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
12079 tree type
= BINFO_TYPE (binfo
);
12083 HOST_WIDE_INT pos
, size
;
12087 if (types_same_for_odr (type
, expected_type
))
12092 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
12094 if (TREE_CODE (fld
) != FIELD_DECL
)
12097 pos
= int_bit_position (fld
);
12098 size
= tree_low_cst (DECL_SIZE (fld
), 1);
12099 if (pos
<= offset
&& (pos
+ size
) > offset
)
12102 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
12105 if (!DECL_ARTIFICIAL (fld
))
12107 binfo
= TYPE_BINFO (TREE_TYPE (fld
));
12111 /* Offset 0 indicates the primary base, whose vtable contents are
12112 represented in the binfo for the derived class. */
12113 else if (offset
!= 0)
12115 tree base_binfo
, found_binfo
= NULL_TREE
;
12116 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
12117 if (types_same_for_odr (TREE_TYPE (base_binfo
), TREE_TYPE (fld
)))
12119 found_binfo
= base_binfo
;
12124 binfo
= found_binfo
;
12127 type
= TREE_TYPE (fld
);
12132 /* Returns true if X is a typedef decl. */
12135 is_typedef_decl (tree x
)
12137 return (x
&& TREE_CODE (x
) == TYPE_DECL
12138 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
12141 /* Returns true iff TYPE is a type variant created for a typedef. */
12144 typedef_variant_p (tree type
)
12146 return is_typedef_decl (TYPE_NAME (type
));
12149 /* Warn about a use of an identifier which was marked deprecated. */
12151 warn_deprecated_use (tree node
, tree attr
)
12155 if (node
== 0 || !warn_deprecated_decl
)
12161 attr
= DECL_ATTRIBUTES (node
);
12162 else if (TYPE_P (node
))
12164 tree decl
= TYPE_STUB_DECL (node
);
12166 attr
= lookup_attribute ("deprecated",
12167 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
12172 attr
= lookup_attribute ("deprecated", attr
);
12175 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
12181 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
12183 warning (OPT_Wdeprecated_declarations
,
12184 "%qD is deprecated (declared at %r%s:%d%R): %s",
12185 node
, "locus", xloc
.file
, xloc
.line
, msg
);
12187 warning (OPT_Wdeprecated_declarations
,
12188 "%qD is deprecated (declared at %r%s:%d%R)",
12189 node
, "locus", xloc
.file
, xloc
.line
);
12191 else if (TYPE_P (node
))
12193 tree what
= NULL_TREE
;
12194 tree decl
= TYPE_STUB_DECL (node
);
12196 if (TYPE_NAME (node
))
12198 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
12199 what
= TYPE_NAME (node
);
12200 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
12201 && DECL_NAME (TYPE_NAME (node
)))
12202 what
= DECL_NAME (TYPE_NAME (node
));
12207 expanded_location xloc
12208 = expand_location (DECL_SOURCE_LOCATION (decl
));
12212 warning (OPT_Wdeprecated_declarations
,
12213 "%qE is deprecated (declared at %r%s:%d%R): %s",
12214 what
, "locus", xloc
.file
, xloc
.line
, msg
);
12216 warning (OPT_Wdeprecated_declarations
,
12217 "%qE is deprecated (declared at %r%s:%d%R)",
12218 what
, "locus", xloc
.file
, xloc
.line
);
12223 warning (OPT_Wdeprecated_declarations
,
12224 "type is deprecated (declared at %r%s:%d%R): %s",
12225 "locus", xloc
.file
, xloc
.line
, msg
);
12227 warning (OPT_Wdeprecated_declarations
,
12228 "type is deprecated (declared at %r%s:%d%R)",
12229 "locus", xloc
.file
, xloc
.line
);
12237 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
12240 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
12245 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
12248 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
12254 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12255 somewhere in it. */
12258 contains_bitfld_component_ref_p (const_tree ref
)
12260 while (handled_component_p (ref
))
12262 if (TREE_CODE (ref
) == COMPONENT_REF
12263 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
12265 ref
= TREE_OPERAND (ref
, 0);
12271 /* Try to determine whether a TRY_CATCH expression can fall through.
12272 This is a subroutine of block_may_fallthru. */
12275 try_catch_may_fallthru (const_tree stmt
)
12277 tree_stmt_iterator i
;
12279 /* If the TRY block can fall through, the whole TRY_CATCH can
12281 if (block_may_fallthru (TREE_OPERAND (stmt
, 0)))
12284 i
= tsi_start (TREE_OPERAND (stmt
, 1));
12285 switch (TREE_CODE (tsi_stmt (i
)))
12288 /* We expect to see a sequence of CATCH_EXPR trees, each with a
12289 catch expression and a body. The whole TRY_CATCH may fall
12290 through iff any of the catch bodies falls through. */
12291 for (; !tsi_end_p (i
); tsi_next (&i
))
12293 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i
))))
12298 case EH_FILTER_EXPR
:
12299 /* The exception filter expression only matters if there is an
12300 exception. If the exception does not match EH_FILTER_TYPES,
12301 we will execute EH_FILTER_FAILURE, and we will fall through
12302 if that falls through. If the exception does match
12303 EH_FILTER_TYPES, the stack unwinder will continue up the
12304 stack, so we will not fall through. We don't know whether we
12305 will throw an exception which matches EH_FILTER_TYPES or not,
12306 so we just ignore EH_FILTER_TYPES and assume that we might
12307 throw an exception which doesn't match. */
12308 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i
)));
12311 /* This case represents statements to be executed when an
12312 exception occurs. Those statements are implicitly followed
12313 by a RESX statement to resume execution after the exception.
12314 So in this case the TRY_CATCH never falls through. */
12319 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12320 need not be 100% accurate; simply be conservative and return true if we
12321 don't know. This is used only to avoid stupidly generating extra code.
12322 If we're wrong, we'll just delete the extra code later. */
12325 block_may_fallthru (const_tree block
)
12327 /* This CONST_CAST is okay because expr_last returns its argument
12328 unmodified and we assign it to a const_tree. */
12329 const_tree stmt
= expr_last (CONST_CAST_TREE (block
));
12331 switch (stmt
? TREE_CODE (stmt
) : ERROR_MARK
)
12335 /* Easy cases. If the last statement of the block implies
12336 control transfer, then we can't fall through. */
12340 /* If SWITCH_LABELS is set, this is lowered, and represents a
12341 branch to a selected label and hence can not fall through.
12342 Otherwise SWITCH_BODY is set, and the switch can fall
12344 return SWITCH_LABELS (stmt
) == NULL_TREE
;
12347 if (block_may_fallthru (COND_EXPR_THEN (stmt
)))
12349 return block_may_fallthru (COND_EXPR_ELSE (stmt
));
12352 return block_may_fallthru (BIND_EXPR_BODY (stmt
));
12354 case TRY_CATCH_EXPR
:
12355 return try_catch_may_fallthru (stmt
);
12357 case TRY_FINALLY_EXPR
:
12358 /* The finally clause is always executed after the try clause,
12359 so if it does not fall through, then the try-finally will not
12360 fall through. Otherwise, if the try clause does not fall
12361 through, then when the finally clause falls through it will
12362 resume execution wherever the try clause was going. So the
12363 whole try-finally will only fall through if both the try
12364 clause and the finally clause fall through. */
12365 return (block_may_fallthru (TREE_OPERAND (stmt
, 0))
12366 && block_may_fallthru (TREE_OPERAND (stmt
, 1)));
12369 if (TREE_CODE (TREE_OPERAND (stmt
, 1)) == CALL_EXPR
)
12370 stmt
= TREE_OPERAND (stmt
, 1);
12376 /* Functions that do not return do not fall through. */
12377 return (call_expr_flags (stmt
) & ECF_NORETURN
) == 0;
12379 case CLEANUP_POINT_EXPR
:
12380 return block_may_fallthru (TREE_OPERAND (stmt
, 0));
12383 return block_may_fallthru (TREE_OPERAND (stmt
, 1));
12389 return lang_hooks
.block_may_fallthru (stmt
);
12393 /* True if we are using EH to handle cleanups. */
12394 static bool using_eh_for_cleanups_flag
= false;
12396 /* This routine is called from front ends to indicate eh should be used for
12399 using_eh_for_cleanups (void)
12401 using_eh_for_cleanups_flag
= true;
12404 /* Query whether EH is used for cleanups. */
12406 using_eh_for_cleanups_p (void)
12408 return using_eh_for_cleanups_flag
;
12411 /* Wrapper for tree_code_name to ensure that tree code is valid */
12413 get_tree_code_name (enum tree_code code
)
12415 const char *invalid
= "<invalid tree code>";
12417 if (code
>= MAX_TREE_CODES
)
12420 return tree_code_name
[code
];
12423 #include "gt-tree.h"