1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
44 #include "filenames.h"
47 #include "langhooks.h"
48 #include "tree-inline.h"
49 #include "tree-iterator.h"
50 #include "basic-block.h"
51 #include "tree-flow.h"
53 #include "pointer-set.h"
54 #include "tree-pass.h"
55 #include "langhooks-def.h"
56 #include "diagnostic.h"
57 #include "tree-diagnostic.h"
58 #include "tree-pretty-print.h"
65 /* Tree code classes. */
67 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
68 #define END_OF_BASE_TREE_CODES tcc_exceptional,
70 const enum tree_code_class tree_code_type
[] = {
71 #include "all-tree.def"
75 #undef END_OF_BASE_TREE_CODES
77 /* Table indexed by tree code giving number of expression
78 operands beyond the fixed part of the node structure.
79 Not used for types or decls. */
81 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
82 #define END_OF_BASE_TREE_CODES 0,
84 const unsigned char tree_code_length
[] = {
85 #include "all-tree.def"
89 #undef END_OF_BASE_TREE_CODES
91 /* Names of tree components.
92 Used for printing out the tree and error messages. */
93 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
94 #define END_OF_BASE_TREE_CODES "@dummy",
96 const char *const tree_code_name
[] = {
97 #include "all-tree.def"
101 #undef END_OF_BASE_TREE_CODES
103 /* Each tree code class has an associated string representation.
104 These must correspond to the tree_code_class entries. */
106 const char *const tree_code_class_strings
[] =
121 /* obstack.[ch] explicitly declined to prototype this. */
122 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
124 #ifdef GATHER_STATISTICS
125 /* Statistics-gathering stuff. */
127 int tree_node_counts
[(int) all_kinds
];
128 int tree_node_sizes
[(int) all_kinds
];
130 /* Keep in sync with tree.h:enum tree_node_kind. */
131 static const char * const tree_node_kind_names
[] = {
149 #endif /* GATHER_STATISTICS */
151 /* Unique id for next decl created. */
152 static GTY(()) int next_decl_uid
;
153 /* Unique id for next type created. */
154 static GTY(()) int next_type_uid
= 1;
155 /* Unique id for next debug decl created. Use negative numbers,
156 to catch erroneous uses. */
157 static GTY(()) int next_debug_decl_uid
;
159 /* Since we cannot rehash a type after it is in the table, we have to
160 keep the hash code. */
162 struct GTY(()) type_hash
{
167 /* Initial size of the hash table (rounded to next prime). */
168 #define TYPE_HASH_INITIAL_SIZE 1000
170 /* Now here is the hash table. When recording a type, it is added to
171 the slot whose index is the hash code. Note that the hash table is
172 used for several kinds of types (function types, array types and
173 array index range types, for now). While all these live in the
174 same table, they are completely independent, and the hash code is
175 computed differently for each of these. */
177 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
178 htab_t type_hash_table
;
180 /* Hash table and temporary node for larger integer const values. */
181 static GTY (()) tree int_cst_node
;
182 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
183 htab_t int_cst_hash_table
;
185 /* Hash table for optimization flags and target option flags. Use the same
186 hash table for both sets of options. Nodes for building the current
187 optimization and target option nodes. The assumption is most of the time
188 the options created will already be in the hash table, so we avoid
189 allocating and freeing up a node repeatably. */
190 static GTY (()) tree cl_optimization_node
;
191 static GTY (()) tree cl_target_option_node
;
192 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
193 htab_t cl_option_hash_table
;
195 /* General tree->tree mapping structure for use in hash tables. */
198 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
199 htab_t debug_expr_for_decl
;
201 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
202 htab_t value_expr_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
);
222 tree global_trees
[TI_MAX
];
223 tree integer_types
[itk_none
];
225 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
227 /* Number of operands for each OpenMP clause. */
228 unsigned const char omp_clause_num_ops
[] =
230 0, /* OMP_CLAUSE_ERROR */
231 1, /* OMP_CLAUSE_PRIVATE */
232 1, /* OMP_CLAUSE_SHARED */
233 1, /* OMP_CLAUSE_FIRSTPRIVATE */
234 2, /* OMP_CLAUSE_LASTPRIVATE */
235 4, /* OMP_CLAUSE_REDUCTION */
236 1, /* OMP_CLAUSE_COPYIN */
237 1, /* OMP_CLAUSE_COPYPRIVATE */
238 1, /* OMP_CLAUSE_IF */
239 1, /* OMP_CLAUSE_NUM_THREADS */
240 1, /* OMP_CLAUSE_SCHEDULE */
241 0, /* OMP_CLAUSE_NOWAIT */
242 0, /* OMP_CLAUSE_ORDERED */
243 0, /* OMP_CLAUSE_DEFAULT */
244 3, /* OMP_CLAUSE_COLLAPSE */
245 0 /* OMP_CLAUSE_UNTIED */
248 const char * const omp_clause_code_name
[] =
269 /* Return the tree node structure used by tree code CODE. */
271 static inline enum tree_node_structure_enum
272 tree_node_structure_for_code (enum tree_code code
)
274 switch (TREE_CODE_CLASS (code
))
276 case tcc_declaration
:
281 return TS_FIELD_DECL
;
287 return TS_LABEL_DECL
;
289 return TS_RESULT_DECL
;
290 case DEBUG_EXPR_DECL
:
293 return TS_CONST_DECL
;
297 return TS_FUNCTION_DECL
;
298 case TRANSLATION_UNIT_DECL
:
299 return TS_TRANSLATION_UNIT_DECL
;
301 return TS_DECL_NON_COMMON
;
314 default: /* tcc_constant and tcc_exceptional */
319 /* tcc_constant cases. */
320 case INTEGER_CST
: return TS_INT_CST
;
321 case REAL_CST
: return TS_REAL_CST
;
322 case FIXED_CST
: return TS_FIXED_CST
;
323 case COMPLEX_CST
: return TS_COMPLEX
;
324 case VECTOR_CST
: return TS_VECTOR
;
325 case STRING_CST
: return TS_STRING
;
326 /* tcc_exceptional cases. */
327 case ERROR_MARK
: return TS_COMMON
;
328 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
329 case TREE_LIST
: return TS_LIST
;
330 case TREE_VEC
: return TS_VEC
;
331 case SSA_NAME
: return TS_SSA_NAME
;
332 case PLACEHOLDER_EXPR
: return TS_COMMON
;
333 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
334 case BLOCK
: return TS_BLOCK
;
335 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
336 case TREE_BINFO
: return TS_BINFO
;
337 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
338 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
339 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
347 /* Initialize tree_contains_struct to describe the hierarchy of tree
351 initialize_tree_contains_struct (void)
355 #define MARK_TS_BASE(C) \
357 tree_contains_struct[C][TS_BASE] = 1; \
360 #define MARK_TS_COMMON(C) \
363 tree_contains_struct[C][TS_COMMON] = 1; \
366 #define MARK_TS_DECL_MINIMAL(C) \
368 MARK_TS_COMMON (C); \
369 tree_contains_struct[C][TS_DECL_MINIMAL] = 1; \
372 #define MARK_TS_DECL_COMMON(C) \
374 MARK_TS_DECL_MINIMAL (C); \
375 tree_contains_struct[C][TS_DECL_COMMON] = 1; \
378 #define MARK_TS_DECL_WRTL(C) \
380 MARK_TS_DECL_COMMON (C); \
381 tree_contains_struct[C][TS_DECL_WRTL] = 1; \
384 #define MARK_TS_DECL_WITH_VIS(C) \
386 MARK_TS_DECL_WRTL (C); \
387 tree_contains_struct[C][TS_DECL_WITH_VIS] = 1; \
390 #define MARK_TS_DECL_NON_COMMON(C) \
392 MARK_TS_DECL_WITH_VIS (C); \
393 tree_contains_struct[C][TS_DECL_NON_COMMON] = 1; \
396 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
399 enum tree_node_structure_enum ts_code
;
401 code
= (enum tree_code
) i
;
402 ts_code
= tree_node_structure_for_code (code
);
404 /* Mark the TS structure itself. */
405 tree_contains_struct
[code
][ts_code
] = 1;
407 /* Mark all the structures that TS is derived from. */
421 case TS_DECL_MINIMAL
:
429 case TS_STATEMENT_LIST
:
432 case TS_OPTIMIZATION
:
433 case TS_TARGET_OPTION
:
434 MARK_TS_COMMON (code
);
438 MARK_TS_DECL_MINIMAL (code
);
442 MARK_TS_DECL_COMMON (code
);
445 case TS_DECL_NON_COMMON
:
446 MARK_TS_DECL_WITH_VIS (code
);
449 case TS_DECL_WITH_VIS
:
454 MARK_TS_DECL_WRTL (code
);
458 MARK_TS_DECL_COMMON (code
);
462 MARK_TS_DECL_WITH_VIS (code
);
466 case TS_FUNCTION_DECL
:
467 MARK_TS_DECL_NON_COMMON (code
);
470 case TS_TRANSLATION_UNIT_DECL
:
471 MARK_TS_DECL_COMMON (code
);
479 /* Basic consistency checks for attributes used in fold. */
480 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
481 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
482 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
483 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
484 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
485 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
486 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
487 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
488 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
489 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
490 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
491 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
]);
492 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
493 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
494 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
495 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
496 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
497 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
498 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
499 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
500 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
501 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
502 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
503 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
504 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
505 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
506 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
507 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
508 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
509 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
510 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
511 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
512 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
513 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
514 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
515 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
516 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
517 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
518 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
521 #undef MARK_TS_COMMON
522 #undef MARK_TS_DECL_MINIMAL
523 #undef MARK_TS_DECL_COMMON
524 #undef MARK_TS_DECL_WRTL
525 #undef MARK_TS_DECL_WITH_VIS
526 #undef MARK_TS_DECL_NON_COMMON
535 /* Initialize the hash table of types. */
536 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
539 debug_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
540 tree_decl_map_eq
, 0);
542 value_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
543 tree_decl_map_eq
, 0);
544 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
545 tree_priority_map_eq
, 0);
547 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
548 int_cst_hash_eq
, NULL
);
550 int_cst_node
= make_node (INTEGER_CST
);
552 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
553 cl_option_hash_eq
, NULL
);
555 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
556 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
558 /* Initialize the tree_contains_struct array. */
559 initialize_tree_contains_struct ();
560 lang_hooks
.init_ts ();
564 /* The name of the object as the assembler will see it (but before any
565 translations made by ASM_OUTPUT_LABELREF). Often this is the same
566 as DECL_NAME. It is an IDENTIFIER_NODE. */
568 decl_assembler_name (tree decl
)
570 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
571 lang_hooks
.set_decl_assembler_name (decl
);
572 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
575 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
578 decl_assembler_name_equal (tree decl
, const_tree asmname
)
580 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
581 const char *decl_str
;
582 const char *asmname_str
;
585 if (decl_asmname
== asmname
)
588 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
589 asmname_str
= IDENTIFIER_POINTER (asmname
);
592 /* If the target assembler name was set by the user, things are trickier.
593 We have a leading '*' to begin with. After that, it's arguable what
594 is the correct thing to do with -fleading-underscore. Arguably, we've
595 historically been doing the wrong thing in assemble_alias by always
596 printing the leading underscore. Since we're not changing that, make
597 sure user_label_prefix follows the '*' before matching. */
598 if (decl_str
[0] == '*')
600 size_t ulp_len
= strlen (user_label_prefix
);
606 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
607 decl_str
+= ulp_len
, test
=true;
611 if (asmname_str
[0] == '*')
613 size_t ulp_len
= strlen (user_label_prefix
);
619 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
620 asmname_str
+= ulp_len
, test
=true;
627 return strcmp (decl_str
, asmname_str
) == 0;
630 /* Hash asmnames ignoring the user specified marks. */
633 decl_assembler_name_hash (const_tree asmname
)
635 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
637 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
638 size_t ulp_len
= strlen (user_label_prefix
);
642 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
645 return htab_hash_string (decl_str
);
648 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
651 /* Compute the number of bytes occupied by a tree with code CODE.
652 This function cannot be used for nodes that have variable sizes,
653 including TREE_VEC, STRING_CST, and CALL_EXPR. */
655 tree_code_size (enum tree_code code
)
657 switch (TREE_CODE_CLASS (code
))
659 case tcc_declaration
: /* A decl node */
664 return sizeof (struct tree_field_decl
);
666 return sizeof (struct tree_parm_decl
);
668 return sizeof (struct tree_var_decl
);
670 return sizeof (struct tree_label_decl
);
672 return sizeof (struct tree_result_decl
);
674 return sizeof (struct tree_const_decl
);
676 return sizeof (struct tree_type_decl
);
678 return sizeof (struct tree_function_decl
);
679 case DEBUG_EXPR_DECL
:
680 return sizeof (struct tree_decl_with_rtl
);
682 return sizeof (struct tree_decl_non_common
);
686 case tcc_type
: /* a type node */
687 return sizeof (struct tree_type
);
689 case tcc_reference
: /* a reference */
690 case tcc_expression
: /* an expression */
691 case tcc_statement
: /* an expression with side effects */
692 case tcc_comparison
: /* a comparison expression */
693 case tcc_unary
: /* a unary arithmetic expression */
694 case tcc_binary
: /* a binary arithmetic expression */
695 return (sizeof (struct tree_exp
)
696 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
698 case tcc_constant
: /* a constant */
701 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
702 case REAL_CST
: return sizeof (struct tree_real_cst
);
703 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
704 case COMPLEX_CST
: return sizeof (struct tree_complex
);
705 case VECTOR_CST
: return sizeof (struct tree_vector
);
706 case STRING_CST
: gcc_unreachable ();
708 return lang_hooks
.tree_size (code
);
711 case tcc_exceptional
: /* something random, like an identifier. */
714 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
715 case TREE_LIST
: return sizeof (struct tree_list
);
718 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
721 case OMP_CLAUSE
: gcc_unreachable ();
723 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
725 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
726 case BLOCK
: return sizeof (struct tree_block
);
727 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
728 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
729 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
732 return lang_hooks
.tree_size (code
);
740 /* Compute the number of bytes occupied by NODE. This routine only
741 looks at TREE_CODE, except for those nodes that have variable sizes. */
743 tree_size (const_tree node
)
745 const enum tree_code code
= TREE_CODE (node
);
749 return (offsetof (struct tree_binfo
, base_binfos
)
750 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
753 return (sizeof (struct tree_vec
)
754 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
757 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
760 return (sizeof (struct tree_omp_clause
)
761 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
765 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
766 return (sizeof (struct tree_exp
)
767 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
769 return tree_code_size (code
);
773 /* Record interesting allocation statistics for a tree node with CODE
777 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
778 size_t length ATTRIBUTE_UNUSED
)
780 #ifdef GATHER_STATISTICS
781 enum tree_code_class type
= TREE_CODE_CLASS (code
);
786 case tcc_declaration
: /* A decl node */
790 case tcc_type
: /* a type node */
794 case tcc_statement
: /* an expression with side effects */
798 case tcc_reference
: /* a reference */
802 case tcc_expression
: /* an expression */
803 case tcc_comparison
: /* a comparison expression */
804 case tcc_unary
: /* a unary arithmetic expression */
805 case tcc_binary
: /* a binary arithmetic expression */
809 case tcc_constant
: /* a constant */
813 case tcc_exceptional
: /* something random, like an identifier. */
816 case IDENTIFIER_NODE
:
829 kind
= ssa_name_kind
;
841 kind
= omp_clause_kind
;
858 tree_node_counts
[(int) kind
]++;
859 tree_node_sizes
[(int) kind
] += length
;
863 /* Return a newly allocated node of code CODE. For decl and type
864 nodes, some other fields are initialized. The rest of the node is
865 initialized to zero. This function cannot be used for TREE_VEC or
866 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
868 Achoo! I got a code in the node. */
871 make_node_stat (enum tree_code code MEM_STAT_DECL
)
874 enum tree_code_class type
= TREE_CODE_CLASS (code
);
875 size_t length
= tree_code_size (code
);
877 record_node_allocation_statistics (code
, length
);
879 t
= ggc_alloc_zone_cleared_tree_node_stat (
880 (code
== IDENTIFIER_NODE
) ? &tree_id_zone
: &tree_zone
,
881 length PASS_MEM_STAT
);
882 TREE_SET_CODE (t
, code
);
887 TREE_SIDE_EFFECTS (t
) = 1;
890 case tcc_declaration
:
891 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
893 if (code
== FUNCTION_DECL
)
895 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
896 DECL_MODE (t
) = FUNCTION_MODE
;
901 DECL_SOURCE_LOCATION (t
) = input_location
;
902 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
903 DECL_UID (t
) = --next_debug_decl_uid
;
906 DECL_UID (t
) = next_decl_uid
++;
907 SET_DECL_PT_UID (t
, -1);
909 if (TREE_CODE (t
) == LABEL_DECL
)
910 LABEL_DECL_UID (t
) = -1;
915 TYPE_UID (t
) = next_type_uid
++;
916 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
917 TYPE_USER_ALIGN (t
) = 0;
918 TYPE_MAIN_VARIANT (t
) = t
;
919 TYPE_CANONICAL (t
) = t
;
921 /* Default to no attributes for type, but let target change that. */
922 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
923 targetm
.set_default_type_attributes (t
);
925 /* We have not yet computed the alias set for this type. */
926 TYPE_ALIAS_SET (t
) = -1;
930 TREE_CONSTANT (t
) = 1;
939 case PREDECREMENT_EXPR
:
940 case PREINCREMENT_EXPR
:
941 case POSTDECREMENT_EXPR
:
942 case POSTINCREMENT_EXPR
:
943 /* All of these have side-effects, no matter what their
945 TREE_SIDE_EFFECTS (t
) = 1;
954 /* Other classes need no special treatment. */
961 /* Return a new node with the same contents as NODE except that its
962 TREE_CHAIN is zero and it has a fresh uid. */
965 copy_node_stat (tree node MEM_STAT_DECL
)
968 enum tree_code code
= TREE_CODE (node
);
971 gcc_assert (code
!= STATEMENT_LIST
);
973 length
= tree_size (node
);
974 record_node_allocation_statistics (code
, length
);
975 t
= ggc_alloc_zone_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
976 memcpy (t
, node
, length
);
979 TREE_ASM_WRITTEN (t
) = 0;
980 TREE_VISITED (t
) = 0;
981 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
982 *DECL_VAR_ANN_PTR (t
) = 0;
984 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
986 if (code
== DEBUG_EXPR_DECL
)
987 DECL_UID (t
) = --next_debug_decl_uid
;
990 DECL_UID (t
) = next_decl_uid
++;
991 if (DECL_PT_UID_SET_P (node
))
992 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
994 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
995 && DECL_HAS_VALUE_EXPR_P (node
))
997 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
998 DECL_HAS_VALUE_EXPR_P (t
) = 1;
1000 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
1002 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
1003 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
1006 else if (TREE_CODE_CLASS (code
) == tcc_type
)
1008 TYPE_UID (t
) = next_type_uid
++;
1009 /* The following is so that the debug code for
1010 the copy is different from the original type.
1011 The two statements usually duplicate each other
1012 (because they clear fields of the same union),
1013 but the optimizer should catch that. */
1014 TYPE_SYMTAB_POINTER (t
) = 0;
1015 TYPE_SYMTAB_ADDRESS (t
) = 0;
1017 /* Do not copy the values cache. */
1018 if (TYPE_CACHED_VALUES_P(t
))
1020 TYPE_CACHED_VALUES_P (t
) = 0;
1021 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1028 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1029 For example, this can copy a list made of TREE_LIST nodes. */
1032 copy_list (tree list
)
1040 head
= prev
= copy_node (list
);
1041 next
= TREE_CHAIN (list
);
1044 TREE_CHAIN (prev
) = copy_node (next
);
1045 prev
= TREE_CHAIN (prev
);
1046 next
= TREE_CHAIN (next
);
1052 /* Create an INT_CST node with a LOW value sign extended. */
1055 build_int_cst (tree type
, HOST_WIDE_INT low
)
1057 /* Support legacy code. */
1059 type
= integer_type_node
;
1061 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
1064 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
1065 if it is negative. This function is similar to build_int_cst, but
1066 the extra bits outside of the type precision are cleared. Constants
1067 with these extra bits may confuse the fold so that it detects overflows
1068 even in cases when they do not occur, and in general should be avoided.
1069 We cannot however make this a default behavior of build_int_cst without
1070 more intrusive changes, since there are parts of gcc that rely on the extra
1071 precision of the integer constants. */
1074 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1078 return double_int_to_tree (type
, shwi_to_double_int (low
));
1081 /* Constructs tree in type TYPE from with value given by CST. Signedness
1082 of CST is assumed to be the same as the signedness of TYPE. */
1085 double_int_to_tree (tree type
, double_int cst
)
1087 /* Size types *are* sign extended. */
1088 bool sign_extended_type
= (!TYPE_UNSIGNED (type
)
1089 || (TREE_CODE (type
) == INTEGER_TYPE
1090 && TYPE_IS_SIZETYPE (type
)));
1092 cst
= double_int_ext (cst
, TYPE_PRECISION (type
), !sign_extended_type
);
1094 return build_int_cst_wide (type
, cst
.low
, cst
.high
);
1097 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1098 to be the same as the signedness of TYPE. */
1101 double_int_fits_to_tree_p (const_tree type
, double_int cst
)
1103 /* Size types *are* sign extended. */
1104 bool sign_extended_type
= (!TYPE_UNSIGNED (type
)
1105 || (TREE_CODE (type
) == INTEGER_TYPE
1106 && TYPE_IS_SIZETYPE (type
)));
1109 = double_int_ext (cst
, TYPE_PRECISION (type
), !sign_extended_type
);
1111 return double_int_equal_p (cst
, ext
);
1114 /* We force the double_int CST to the range of the type TYPE by sign or
1115 zero extending it. OVERFLOWABLE indicates if we are interested in
1116 overflow of the value, when >0 we are only interested in signed
1117 overflow, for <0 we are interested in any overflow. OVERFLOWED
1118 indicates whether overflow has already occurred. CONST_OVERFLOWED
1119 indicates whether constant overflow has already occurred. We force
1120 T's value to be within range of T's type (by setting to 0 or 1 all
1121 the bits outside the type's range). We set TREE_OVERFLOWED if,
1122 OVERFLOWED is nonzero,
1123 or OVERFLOWABLE is >0 and signed overflow occurs
1124 or OVERFLOWABLE is <0 and any overflow occurs
1125 We return a new tree node for the extended double_int. The node
1126 is shared if no overflow flags are set. */
1130 force_fit_type_double (tree type
, double_int cst
, int overflowable
,
1133 bool sign_extended_type
;
1135 /* Size types *are* sign extended. */
1136 sign_extended_type
= (!TYPE_UNSIGNED (type
)
1137 || (TREE_CODE (type
) == INTEGER_TYPE
1138 && TYPE_IS_SIZETYPE (type
)));
1140 /* If we need to set overflow flags, return a new unshared node. */
1141 if (overflowed
|| !double_int_fits_to_tree_p(type
, cst
))
1145 || (overflowable
> 0 && sign_extended_type
))
1147 tree t
= make_node (INTEGER_CST
);
1148 TREE_INT_CST (t
) = double_int_ext (cst
, TYPE_PRECISION (type
),
1149 !sign_extended_type
);
1150 TREE_TYPE (t
) = type
;
1151 TREE_OVERFLOW (t
) = 1;
1156 /* Else build a shared node. */
1157 return double_int_to_tree (type
, cst
);
1160 /* These are the hash table functions for the hash table of INTEGER_CST
1161 nodes of a sizetype. */
1163 /* Return the hash code code X, an INTEGER_CST. */
1166 int_cst_hash_hash (const void *x
)
1168 const_tree
const t
= (const_tree
) x
;
1170 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
1171 ^ htab_hash_pointer (TREE_TYPE (t
)));
1174 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1175 is the same as that given by *Y, which is the same. */
1178 int_cst_hash_eq (const void *x
, const void *y
)
1180 const_tree
const xt
= (const_tree
) x
;
1181 const_tree
const yt
= (const_tree
) y
;
1183 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
1184 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
1185 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
1188 /* Create an INT_CST node of TYPE and value HI:LOW.
1189 The returned node is always shared. For small integers we use a
1190 per-type vector cache, for larger ones we use a single hash table. */
1193 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
1201 switch (TREE_CODE (type
))
1204 gcc_assert (hi
== 0 && low
== 0);
1208 case REFERENCE_TYPE
:
1209 /* Cache NULL pointer. */
1218 /* Cache false or true. */
1226 if (TYPE_UNSIGNED (type
))
1229 limit
= INTEGER_SHARE_LIMIT
;
1230 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1236 limit
= INTEGER_SHARE_LIMIT
+ 1;
1237 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1239 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1253 /* Look for it in the type's vector of small shared ints. */
1254 if (!TYPE_CACHED_VALUES_P (type
))
1256 TYPE_CACHED_VALUES_P (type
) = 1;
1257 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1260 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1263 /* Make sure no one is clobbering the shared constant. */
1264 gcc_assert (TREE_TYPE (t
) == type
);
1265 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
1266 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
1270 /* Create a new shared int. */
1271 t
= make_node (INTEGER_CST
);
1273 TREE_INT_CST_LOW (t
) = low
;
1274 TREE_INT_CST_HIGH (t
) = hi
;
1275 TREE_TYPE (t
) = type
;
1277 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1282 /* Use the cache of larger shared ints. */
1285 TREE_INT_CST_LOW (int_cst_node
) = low
;
1286 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
1287 TREE_TYPE (int_cst_node
) = type
;
1289 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1293 /* Insert this one into the hash table. */
1296 /* Make a new node for next time round. */
1297 int_cst_node
= make_node (INTEGER_CST
);
1304 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1305 and the rest are zeros. */
1308 build_low_bits_mask (tree type
, unsigned bits
)
1312 gcc_assert (bits
<= TYPE_PRECISION (type
));
1314 if (bits
== TYPE_PRECISION (type
)
1315 && !TYPE_UNSIGNED (type
))
1316 /* Sign extended all-ones mask. */
1317 mask
= double_int_minus_one
;
1319 mask
= double_int_mask (bits
);
1321 return build_int_cst_wide (type
, mask
.low
, mask
.high
);
1324 /* Checks that X is integer constant that can be expressed in (unsigned)
1325 HOST_WIDE_INT without loss of precision. */
1328 cst_and_fits_in_hwi (const_tree x
)
1330 if (TREE_CODE (x
) != INTEGER_CST
)
1333 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1336 return (TREE_INT_CST_HIGH (x
) == 0
1337 || TREE_INT_CST_HIGH (x
) == -1);
1340 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1341 are in a list pointed to by VALS. */
1344 build_vector (tree type
, tree vals
)
1346 tree v
= make_node (VECTOR_CST
);
1351 TREE_VECTOR_CST_ELTS (v
) = vals
;
1352 TREE_TYPE (v
) = type
;
1354 /* Iterate through elements and check for overflow. */
1355 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1357 tree value
= TREE_VALUE (link
);
1360 /* Don't crash if we get an address constant. */
1361 if (!CONSTANT_CLASS_P (value
))
1364 over
|= TREE_OVERFLOW (value
);
1367 gcc_assert (cnt
== TYPE_VECTOR_SUBPARTS (type
));
1369 TREE_OVERFLOW (v
) = over
;
1373 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1374 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1377 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1379 tree list
= NULL_TREE
;
1380 unsigned HOST_WIDE_INT idx
;
1383 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1384 list
= tree_cons (NULL_TREE
, value
, list
);
1385 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1386 list
= tree_cons (NULL_TREE
,
1387 build_zero_cst (TREE_TYPE (type
)), list
);
1388 return build_vector (type
, nreverse (list
));
1391 /* Build a vector of type VECTYPE where all the elements are SCs. */
1393 build_vector_from_val (tree vectype
, tree sc
)
1395 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1396 VEC(constructor_elt
, gc
) *v
= NULL
;
1398 if (sc
== error_mark_node
)
1401 /* Verify that the vector type is suitable for SC. Note that there
1402 is some inconsistency in the type-system with respect to restrict
1403 qualifications of pointers. Vector types always have a main-variant
1404 element type and the qualification is applied to the vector-type.
1405 So TREE_TYPE (vector-type) does not return a properly qualified
1406 vector element-type. */
1407 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1408 TREE_TYPE (vectype
)));
1410 v
= VEC_alloc (constructor_elt
, gc
, nunits
);
1411 for (i
= 0; i
< nunits
; ++i
)
1412 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1414 if (CONSTANT_CLASS_P (sc
))
1415 return build_vector_from_ctor (vectype
, v
);
1417 return build_constructor (vectype
, v
);
1420 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1421 are in the VEC pointed to by VALS. */
1423 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1425 tree c
= make_node (CONSTRUCTOR
);
1427 constructor_elt
*elt
;
1428 bool constant_p
= true;
1430 TREE_TYPE (c
) = type
;
1431 CONSTRUCTOR_ELTS (c
) = vals
;
1433 FOR_EACH_VEC_ELT (constructor_elt
, vals
, i
, elt
)
1434 if (!TREE_CONSTANT (elt
->value
))
1440 TREE_CONSTANT (c
) = constant_p
;
1445 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1448 build_constructor_single (tree type
, tree index
, tree value
)
1450 VEC(constructor_elt
,gc
) *v
;
1451 constructor_elt
*elt
;
1453 v
= VEC_alloc (constructor_elt
, gc
, 1);
1454 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1458 return build_constructor (type
, v
);
1462 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1463 are in a list pointed to by VALS. */
1465 build_constructor_from_list (tree type
, tree vals
)
1468 VEC(constructor_elt
,gc
) *v
= NULL
;
1472 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1473 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1474 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1477 return build_constructor (type
, v
);
1480 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1483 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1486 FIXED_VALUE_TYPE
*fp
;
1488 v
= make_node (FIXED_CST
);
1489 fp
= ggc_alloc_fixed_value ();
1490 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1492 TREE_TYPE (v
) = type
;
1493 TREE_FIXED_CST_PTR (v
) = fp
;
1497 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1500 build_real (tree type
, REAL_VALUE_TYPE d
)
1503 REAL_VALUE_TYPE
*dp
;
1506 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1507 Consider doing it via real_convert now. */
1509 v
= make_node (REAL_CST
);
1510 dp
= ggc_alloc_real_value ();
1511 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1513 TREE_TYPE (v
) = type
;
1514 TREE_REAL_CST_PTR (v
) = dp
;
1515 TREE_OVERFLOW (v
) = overflow
;
1519 /* Return a new REAL_CST node whose type is TYPE
1520 and whose value is the integer value of the INTEGER_CST node I. */
1523 real_value_from_int_cst (const_tree type
, const_tree i
)
1527 /* Clear all bits of the real value type so that we can later do
1528 bitwise comparisons to see if two values are the same. */
1529 memset (&d
, 0, sizeof d
);
1531 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1532 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1533 TYPE_UNSIGNED (TREE_TYPE (i
)));
1537 /* Given a tree representing an integer constant I, return a tree
1538 representing the same value as a floating-point constant of type TYPE. */
1541 build_real_from_int_cst (tree type
, const_tree i
)
1544 int overflow
= TREE_OVERFLOW (i
);
1546 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1548 TREE_OVERFLOW (v
) |= overflow
;
1552 /* Return a newly constructed STRING_CST node whose value is
1553 the LEN characters at STR.
1554 The TREE_TYPE is not initialized. */
1557 build_string (int len
, const char *str
)
1562 /* Do not waste bytes provided by padding of struct tree_string. */
1563 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1565 record_node_allocation_statistics (STRING_CST
, length
);
1567 s
= ggc_alloc_tree_node (length
);
1569 memset (s
, 0, sizeof (struct tree_common
));
1570 TREE_SET_CODE (s
, STRING_CST
);
1571 TREE_CONSTANT (s
) = 1;
1572 TREE_STRING_LENGTH (s
) = len
;
1573 memcpy (s
->string
.str
, str
, len
);
1574 s
->string
.str
[len
] = '\0';
1579 /* Return a newly constructed COMPLEX_CST node whose value is
1580 specified by the real and imaginary parts REAL and IMAG.
1581 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1582 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1585 build_complex (tree type
, tree real
, tree imag
)
1587 tree t
= make_node (COMPLEX_CST
);
1589 TREE_REALPART (t
) = real
;
1590 TREE_IMAGPART (t
) = imag
;
1591 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1592 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1596 /* Return a constant of arithmetic type TYPE which is the
1597 multiplicative identity of the set TYPE. */
1600 build_one_cst (tree type
)
1602 switch (TREE_CODE (type
))
1604 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1605 case POINTER_TYPE
: case REFERENCE_TYPE
:
1607 return build_int_cst (type
, 1);
1610 return build_real (type
, dconst1
);
1612 case FIXED_POINT_TYPE
:
1613 /* We can only generate 1 for accum types. */
1614 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1615 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1619 tree scalar
= build_one_cst (TREE_TYPE (type
));
1621 return build_vector_from_val (type
, scalar
);
1625 return build_complex (type
,
1626 build_one_cst (TREE_TYPE (type
)),
1627 build_zero_cst (TREE_TYPE (type
)));
1634 /* Build 0 constant of type TYPE. This is used by constructor folding
1635 and thus the constant should be represented in memory by
1639 build_zero_cst (tree type
)
1641 switch (TREE_CODE (type
))
1643 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1644 case POINTER_TYPE
: case REFERENCE_TYPE
:
1646 return build_int_cst (type
, 0);
1649 return build_real (type
, dconst0
);
1651 case FIXED_POINT_TYPE
:
1652 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
1656 tree scalar
= build_zero_cst (TREE_TYPE (type
));
1658 return build_vector_from_val (type
, scalar
);
1663 tree zero
= build_zero_cst (TREE_TYPE (type
));
1665 return build_complex (type
, zero
, zero
);
1669 if (!AGGREGATE_TYPE_P (type
))
1670 return fold_convert (type
, integer_zero_node
);
1671 return build_constructor (type
, NULL
);
1676 /* Build a BINFO with LEN language slots. */
1679 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1682 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1683 + VEC_embedded_size (tree
, base_binfos
));
1685 record_node_allocation_statistics (TREE_BINFO
, length
);
1687 t
= ggc_alloc_zone_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
1689 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1691 TREE_SET_CODE (t
, TREE_BINFO
);
1693 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1699 /* Build a newly constructed TREE_VEC node of length LEN. */
1702 make_tree_vec_stat (int len MEM_STAT_DECL
)
1705 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1707 record_node_allocation_statistics (TREE_VEC
, length
);
1709 t
= ggc_alloc_zone_cleared_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
1711 TREE_SET_CODE (t
, TREE_VEC
);
1712 TREE_VEC_LENGTH (t
) = len
;
1717 /* Return 1 if EXPR is the integer constant zero or a complex constant
1721 integer_zerop (const_tree expr
)
1725 return ((TREE_CODE (expr
) == INTEGER_CST
1726 && TREE_INT_CST_LOW (expr
) == 0
1727 && TREE_INT_CST_HIGH (expr
) == 0)
1728 || (TREE_CODE (expr
) == COMPLEX_CST
1729 && integer_zerop (TREE_REALPART (expr
))
1730 && integer_zerop (TREE_IMAGPART (expr
))));
1733 /* Return 1 if EXPR is the integer constant one or the corresponding
1734 complex constant. */
1737 integer_onep (const_tree expr
)
1741 return ((TREE_CODE (expr
) == INTEGER_CST
1742 && TREE_INT_CST_LOW (expr
) == 1
1743 && TREE_INT_CST_HIGH (expr
) == 0)
1744 || (TREE_CODE (expr
) == COMPLEX_CST
1745 && integer_onep (TREE_REALPART (expr
))
1746 && integer_zerop (TREE_IMAGPART (expr
))));
1749 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1750 it contains. Likewise for the corresponding complex constant. */
1753 integer_all_onesp (const_tree expr
)
1760 if (TREE_CODE (expr
) == COMPLEX_CST
1761 && integer_all_onesp (TREE_REALPART (expr
))
1762 && integer_zerop (TREE_IMAGPART (expr
)))
1765 else if (TREE_CODE (expr
) != INTEGER_CST
)
1768 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1769 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1770 && TREE_INT_CST_HIGH (expr
) == -1)
1775 /* Note that using TYPE_PRECISION here is wrong. We care about the
1776 actual bits, not the (arbitrary) range of the type. */
1777 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1778 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1780 HOST_WIDE_INT high_value
;
1783 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1785 /* Can not handle precisions greater than twice the host int size. */
1786 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1787 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1788 /* Shifting by the host word size is undefined according to the ANSI
1789 standard, so we must handle this as a special case. */
1792 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1794 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1795 && TREE_INT_CST_HIGH (expr
) == high_value
);
1798 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1801 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1805 integer_pow2p (const_tree expr
)
1808 HOST_WIDE_INT high
, low
;
1812 if (TREE_CODE (expr
) == COMPLEX_CST
1813 && integer_pow2p (TREE_REALPART (expr
))
1814 && integer_zerop (TREE_IMAGPART (expr
)))
1817 if (TREE_CODE (expr
) != INTEGER_CST
)
1820 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1821 high
= TREE_INT_CST_HIGH (expr
);
1822 low
= TREE_INT_CST_LOW (expr
);
1824 /* First clear all bits that are beyond the type's precision in case
1825 we've been sign extended. */
1827 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1829 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1830 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1834 if (prec
< HOST_BITS_PER_WIDE_INT
)
1835 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1838 if (high
== 0 && low
== 0)
1841 return ((high
== 0 && (low
& (low
- 1)) == 0)
1842 || (low
== 0 && (high
& (high
- 1)) == 0));
1845 /* Return 1 if EXPR is an integer constant other than zero or a
1846 complex constant other than zero. */
1849 integer_nonzerop (const_tree expr
)
1853 return ((TREE_CODE (expr
) == INTEGER_CST
1854 && (TREE_INT_CST_LOW (expr
) != 0
1855 || TREE_INT_CST_HIGH (expr
) != 0))
1856 || (TREE_CODE (expr
) == COMPLEX_CST
1857 && (integer_nonzerop (TREE_REALPART (expr
))
1858 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1861 /* Return 1 if EXPR is the fixed-point constant zero. */
1864 fixed_zerop (const_tree expr
)
1866 return (TREE_CODE (expr
) == FIXED_CST
1867 && double_int_zero_p (TREE_FIXED_CST (expr
).data
));
1870 /* Return the power of two represented by a tree node known to be a
1874 tree_log2 (const_tree expr
)
1877 HOST_WIDE_INT high
, low
;
1881 if (TREE_CODE (expr
) == COMPLEX_CST
)
1882 return tree_log2 (TREE_REALPART (expr
));
1884 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1885 high
= TREE_INT_CST_HIGH (expr
);
1886 low
= TREE_INT_CST_LOW (expr
);
1888 /* First clear all bits that are beyond the type's precision in case
1889 we've been sign extended. */
1891 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1893 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1894 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1898 if (prec
< HOST_BITS_PER_WIDE_INT
)
1899 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1902 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1903 : exact_log2 (low
));
1906 /* Similar, but return the largest integer Y such that 2 ** Y is less
1907 than or equal to EXPR. */
1910 tree_floor_log2 (const_tree expr
)
1913 HOST_WIDE_INT high
, low
;
1917 if (TREE_CODE (expr
) == COMPLEX_CST
)
1918 return tree_log2 (TREE_REALPART (expr
));
1920 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1921 high
= TREE_INT_CST_HIGH (expr
);
1922 low
= TREE_INT_CST_LOW (expr
);
1924 /* First clear all bits that are beyond the type's precision in case
1925 we've been sign extended. Ignore if type's precision hasn't been set
1926 since what we are doing is setting it. */
1928 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1930 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1931 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1935 if (prec
< HOST_BITS_PER_WIDE_INT
)
1936 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1939 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1940 : floor_log2 (low
));
1943 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
1944 decimal float constants, so don't return 1 for them. */
1947 real_zerop (const_tree expr
)
1951 return ((TREE_CODE (expr
) == REAL_CST
1952 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
1953 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1954 || (TREE_CODE (expr
) == COMPLEX_CST
1955 && real_zerop (TREE_REALPART (expr
))
1956 && real_zerop (TREE_IMAGPART (expr
))));
1959 /* Return 1 if EXPR is the real constant one in real or complex form.
1960 Trailing zeroes matter for decimal float constants, so don't return
1964 real_onep (const_tree expr
)
1968 return ((TREE_CODE (expr
) == REAL_CST
1969 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
1970 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1971 || (TREE_CODE (expr
) == COMPLEX_CST
1972 && real_onep (TREE_REALPART (expr
))
1973 && real_zerop (TREE_IMAGPART (expr
))));
1976 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
1977 for decimal float constants, so don't return 1 for them. */
1980 real_twop (const_tree expr
)
1984 return ((TREE_CODE (expr
) == REAL_CST
1985 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
)
1986 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1987 || (TREE_CODE (expr
) == COMPLEX_CST
1988 && real_twop (TREE_REALPART (expr
))
1989 && real_zerop (TREE_IMAGPART (expr
))));
1992 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
1993 matter for decimal float constants, so don't return 1 for them. */
1996 real_minus_onep (const_tree expr
)
2000 return ((TREE_CODE (expr
) == REAL_CST
2001 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
2002 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
2003 || (TREE_CODE (expr
) == COMPLEX_CST
2004 && real_minus_onep (TREE_REALPART (expr
))
2005 && real_zerop (TREE_IMAGPART (expr
))));
2008 /* Nonzero if EXP is a constant or a cast of a constant. */
2011 really_constant_p (const_tree exp
)
2013 /* This is not quite the same as STRIP_NOPS. It does more. */
2014 while (CONVERT_EXPR_P (exp
)
2015 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2016 exp
= TREE_OPERAND (exp
, 0);
2017 return TREE_CONSTANT (exp
);
2020 /* Return first list element whose TREE_VALUE is ELEM.
2021 Return 0 if ELEM is not in LIST. */
2024 value_member (tree elem
, tree list
)
2028 if (elem
== TREE_VALUE (list
))
2030 list
= TREE_CHAIN (list
);
2035 /* Return first list element whose TREE_PURPOSE is ELEM.
2036 Return 0 if ELEM is not in LIST. */
2039 purpose_member (const_tree elem
, tree list
)
2043 if (elem
== TREE_PURPOSE (list
))
2045 list
= TREE_CHAIN (list
);
2050 /* Return true if ELEM is in V. */
2053 vec_member (const_tree elem
, VEC(tree
,gc
) *v
)
2057 FOR_EACH_VEC_ELT (tree
, v
, ix
, t
)
2063 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2067 chain_index (int idx
, tree chain
)
2069 for (; chain
&& idx
> 0; --idx
)
2070 chain
= TREE_CHAIN (chain
);
2074 /* Return nonzero if ELEM is part of the chain CHAIN. */
2077 chain_member (const_tree elem
, const_tree chain
)
2083 chain
= DECL_CHAIN (chain
);
2089 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2090 We expect a null pointer to mark the end of the chain.
2091 This is the Lisp primitive `length'. */
2094 list_length (const_tree t
)
2097 #ifdef ENABLE_TREE_CHECKING
2105 #ifdef ENABLE_TREE_CHECKING
2108 gcc_assert (p
!= q
);
2116 /* Returns the number of FIELD_DECLs in TYPE. */
2119 fields_length (const_tree type
)
2121 tree t
= TYPE_FIELDS (type
);
2124 for (; t
; t
= DECL_CHAIN (t
))
2125 if (TREE_CODE (t
) == FIELD_DECL
)
2131 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2132 UNION_TYPE TYPE, or NULL_TREE if none. */
2135 first_field (const_tree type
)
2137 tree t
= TYPE_FIELDS (type
);
2138 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2143 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2144 by modifying the last node in chain 1 to point to chain 2.
2145 This is the Lisp primitive `nconc'. */
2148 chainon (tree op1
, tree op2
)
2157 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2159 TREE_CHAIN (t1
) = op2
;
2161 #ifdef ENABLE_TREE_CHECKING
2164 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2165 gcc_assert (t2
!= t1
);
2172 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2175 tree_last (tree chain
)
2179 while ((next
= TREE_CHAIN (chain
)))
2184 /* Reverse the order of elements in the chain T,
2185 and return the new head of the chain (old last element). */
2190 tree prev
= 0, decl
, next
;
2191 for (decl
= t
; decl
; decl
= next
)
2193 /* We shouldn't be using this function to reverse BLOCK chains; we
2194 have blocks_nreverse for that. */
2195 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2196 next
= TREE_CHAIN (decl
);
2197 TREE_CHAIN (decl
) = prev
;
2203 /* Return a newly created TREE_LIST node whose
2204 purpose and value fields are PARM and VALUE. */
2207 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2209 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2210 TREE_PURPOSE (t
) = parm
;
2211 TREE_VALUE (t
) = value
;
2215 /* Build a chain of TREE_LIST nodes from a vector. */
2218 build_tree_list_vec_stat (const VEC(tree
,gc
) *vec MEM_STAT_DECL
)
2220 tree ret
= NULL_TREE
;
2224 FOR_EACH_VEC_ELT (tree
, vec
, i
, t
)
2226 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2227 pp
= &TREE_CHAIN (*pp
);
2232 /* Return a newly created TREE_LIST node whose
2233 purpose and value fields are PURPOSE and VALUE
2234 and whose TREE_CHAIN is CHAIN. */
2237 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2241 node
= ggc_alloc_zone_tree_node_stat (&tree_zone
, sizeof (struct tree_list
)
2243 memset (node
, 0, sizeof (struct tree_common
));
2245 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2247 TREE_SET_CODE (node
, TREE_LIST
);
2248 TREE_CHAIN (node
) = chain
;
2249 TREE_PURPOSE (node
) = purpose
;
2250 TREE_VALUE (node
) = value
;
2254 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2258 ctor_to_vec (tree ctor
)
2260 VEC(tree
, gc
) *vec
= VEC_alloc (tree
, gc
, CONSTRUCTOR_NELTS (ctor
));
2264 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2265 VEC_quick_push (tree
, vec
, val
);
2270 /* Return the size nominally occupied by an object of type TYPE
2271 when it resides in memory. The value is measured in units of bytes,
2272 and its data type is that normally used for type sizes
2273 (which is the first type created by make_signed_type or
2274 make_unsigned_type). */
2277 size_in_bytes (const_tree type
)
2281 if (type
== error_mark_node
)
2282 return integer_zero_node
;
2284 type
= TYPE_MAIN_VARIANT (type
);
2285 t
= TYPE_SIZE_UNIT (type
);
2289 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2290 return size_zero_node
;
2296 /* Return the size of TYPE (in bytes) as a wide integer
2297 or return -1 if the size can vary or is larger than an integer. */
2300 int_size_in_bytes (const_tree type
)
2304 if (type
== error_mark_node
)
2307 type
= TYPE_MAIN_VARIANT (type
);
2308 t
= TYPE_SIZE_UNIT (type
);
2310 || TREE_CODE (t
) != INTEGER_CST
2311 || TREE_INT_CST_HIGH (t
) != 0
2312 /* If the result would appear negative, it's too big to represent. */
2313 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
2316 return TREE_INT_CST_LOW (t
);
2319 /* Return the maximum size of TYPE (in bytes) as a wide integer
2320 or return -1 if the size can vary or is larger than an integer. */
2323 max_int_size_in_bytes (const_tree type
)
2325 HOST_WIDE_INT size
= -1;
2328 /* If this is an array type, check for a possible MAX_SIZE attached. */
2330 if (TREE_CODE (type
) == ARRAY_TYPE
)
2332 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2334 if (size_tree
&& host_integerp (size_tree
, 1))
2335 size
= tree_low_cst (size_tree
, 1);
2338 /* If we still haven't been able to get a size, see if the language
2339 can compute a maximum size. */
2343 size_tree
= lang_hooks
.types
.max_size (type
);
2345 if (size_tree
&& host_integerp (size_tree
, 1))
2346 size
= tree_low_cst (size_tree
, 1);
2352 /* Returns a tree for the size of EXP in bytes. */
2355 tree_expr_size (const_tree exp
)
2358 && DECL_SIZE_UNIT (exp
) != 0)
2359 return DECL_SIZE_UNIT (exp
);
2361 return size_in_bytes (TREE_TYPE (exp
));
2364 /* Return the bit position of FIELD, in bits from the start of the record.
2365 This is a tree of type bitsizetype. */
2368 bit_position (const_tree field
)
2370 return bit_from_pos (DECL_FIELD_OFFSET (field
),
2371 DECL_FIELD_BIT_OFFSET (field
));
2374 /* Likewise, but return as an integer. It must be representable in
2375 that way (since it could be a signed value, we don't have the
2376 option of returning -1 like int_size_in_byte can. */
2379 int_bit_position (const_tree field
)
2381 return tree_low_cst (bit_position (field
), 0);
2384 /* Return the byte position of FIELD, in bytes from the start of the record.
2385 This is a tree of type sizetype. */
2388 byte_position (const_tree field
)
2390 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2391 DECL_FIELD_BIT_OFFSET (field
));
2394 /* Likewise, but return as an integer. It must be representable in
2395 that way (since it could be a signed value, we don't have the
2396 option of returning -1 like int_size_in_byte can. */
2399 int_byte_position (const_tree field
)
2401 return tree_low_cst (byte_position (field
), 0);
2404 /* Return the strictest alignment, in bits, that T is known to have. */
2407 expr_align (const_tree t
)
2409 unsigned int align0
, align1
;
2411 switch (TREE_CODE (t
))
2413 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2414 /* If we have conversions, we know that the alignment of the
2415 object must meet each of the alignments of the types. */
2416 align0
= expr_align (TREE_OPERAND (t
, 0));
2417 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2418 return MAX (align0
, align1
);
2420 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2421 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2422 case CLEANUP_POINT_EXPR
:
2423 /* These don't change the alignment of an object. */
2424 return expr_align (TREE_OPERAND (t
, 0));
2427 /* The best we can do is say that the alignment is the least aligned
2429 align0
= expr_align (TREE_OPERAND (t
, 1));
2430 align1
= expr_align (TREE_OPERAND (t
, 2));
2431 return MIN (align0
, align1
);
2433 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2434 meaningfully, it's always 1. */
2435 case LABEL_DECL
: case CONST_DECL
:
2436 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2438 gcc_assert (DECL_ALIGN (t
) != 0);
2439 return DECL_ALIGN (t
);
2445 /* Otherwise take the alignment from that of the type. */
2446 return TYPE_ALIGN (TREE_TYPE (t
));
2449 /* Return, as a tree node, the number of elements for TYPE (which is an
2450 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2453 array_type_nelts (const_tree type
)
2455 tree index_type
, min
, max
;
2457 /* If they did it with unspecified bounds, then we should have already
2458 given an error about it before we got here. */
2459 if (! TYPE_DOMAIN (type
))
2460 return error_mark_node
;
2462 index_type
= TYPE_DOMAIN (type
);
2463 min
= TYPE_MIN_VALUE (index_type
);
2464 max
= TYPE_MAX_VALUE (index_type
);
2466 return (integer_zerop (min
)
2468 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2471 /* If arg is static -- a reference to an object in static storage -- then
2472 return the object. This is not the same as the C meaning of `static'.
2473 If arg isn't static, return NULL. */
2478 switch (TREE_CODE (arg
))
2481 /* Nested functions are static, even though taking their address will
2482 involve a trampoline as we unnest the nested function and create
2483 the trampoline on the tree level. */
2487 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2488 && ! DECL_THREAD_LOCAL_P (arg
)
2489 && ! DECL_DLLIMPORT_P (arg
)
2493 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2497 return TREE_STATIC (arg
) ? arg
: NULL
;
2504 /* If the thing being referenced is not a field, then it is
2505 something language specific. */
2506 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
2508 /* If we are referencing a bitfield, we can't evaluate an
2509 ADDR_EXPR at compile time and so it isn't a constant. */
2510 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2513 return staticp (TREE_OPERAND (arg
, 0));
2519 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2522 case ARRAY_RANGE_REF
:
2523 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2524 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2525 return staticp (TREE_OPERAND (arg
, 0));
2529 case COMPOUND_LITERAL_EXPR
:
2530 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
2540 /* Return whether OP is a DECL whose address is function-invariant. */
2543 decl_address_invariant_p (const_tree op
)
2545 /* The conditions below are slightly less strict than the one in
2548 switch (TREE_CODE (op
))
2557 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2558 || DECL_THREAD_LOCAL_P (op
)
2559 || DECL_CONTEXT (op
) == current_function_decl
2560 || decl_function_context (op
) == current_function_decl
)
2565 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2566 || decl_function_context (op
) == current_function_decl
)
2577 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2580 decl_address_ip_invariant_p (const_tree op
)
2582 /* The conditions below are slightly less strict than the one in
2585 switch (TREE_CODE (op
))
2593 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2594 && !DECL_DLLIMPORT_P (op
))
2595 || DECL_THREAD_LOCAL_P (op
))
2600 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2612 /* Return true if T is function-invariant (internal function, does
2613 not handle arithmetic; that's handled in skip_simple_arithmetic and
2614 tree_invariant_p). */
2616 static bool tree_invariant_p (tree t
);
2619 tree_invariant_p_1 (tree t
)
2623 if (TREE_CONSTANT (t
)
2624 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2627 switch (TREE_CODE (t
))
2633 op
= TREE_OPERAND (t
, 0);
2634 while (handled_component_p (op
))
2636 switch (TREE_CODE (op
))
2639 case ARRAY_RANGE_REF
:
2640 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2641 || TREE_OPERAND (op
, 2) != NULL_TREE
2642 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2647 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2653 op
= TREE_OPERAND (op
, 0);
2656 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2665 /* Return true if T is function-invariant. */
2668 tree_invariant_p (tree t
)
2670 tree inner
= skip_simple_arithmetic (t
);
2671 return tree_invariant_p_1 (inner
);
2674 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2675 Do this to any expression which may be used in more than one place,
2676 but must be evaluated only once.
2678 Normally, expand_expr would reevaluate the expression each time.
2679 Calling save_expr produces something that is evaluated and recorded
2680 the first time expand_expr is called on it. Subsequent calls to
2681 expand_expr just reuse the recorded value.
2683 The call to expand_expr that generates code that actually computes
2684 the value is the first call *at compile time*. Subsequent calls
2685 *at compile time* generate code to use the saved value.
2686 This produces correct result provided that *at run time* control
2687 always flows through the insns made by the first expand_expr
2688 before reaching the other places where the save_expr was evaluated.
2689 You, the caller of save_expr, must make sure this is so.
2691 Constants, and certain read-only nodes, are returned with no
2692 SAVE_EXPR because that is safe. Expressions containing placeholders
2693 are not touched; see tree.def for an explanation of what these
2697 save_expr (tree expr
)
2699 tree t
= fold (expr
);
2702 /* If the tree evaluates to a constant, then we don't want to hide that
2703 fact (i.e. this allows further folding, and direct checks for constants).
2704 However, a read-only object that has side effects cannot be bypassed.
2705 Since it is no problem to reevaluate literals, we just return the
2707 inner
= skip_simple_arithmetic (t
);
2708 if (TREE_CODE (inner
) == ERROR_MARK
)
2711 if (tree_invariant_p_1 (inner
))
2714 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2715 it means that the size or offset of some field of an object depends on
2716 the value within another field.
2718 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2719 and some variable since it would then need to be both evaluated once and
2720 evaluated more than once. Front-ends must assure this case cannot
2721 happen by surrounding any such subexpressions in their own SAVE_EXPR
2722 and forcing evaluation at the proper time. */
2723 if (contains_placeholder_p (inner
))
2726 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2727 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
2729 /* This expression might be placed ahead of a jump to ensure that the
2730 value was computed on both sides of the jump. So make sure it isn't
2731 eliminated as dead. */
2732 TREE_SIDE_EFFECTS (t
) = 1;
2736 /* Look inside EXPR and into any simple arithmetic operations. Return
2737 the innermost non-arithmetic node. */
2740 skip_simple_arithmetic (tree expr
)
2744 /* We don't care about whether this can be used as an lvalue in this
2746 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2747 expr
= TREE_OPERAND (expr
, 0);
2749 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2750 a constant, it will be more efficient to not make another SAVE_EXPR since
2751 it will allow better simplification and GCSE will be able to merge the
2752 computations if they actually occur. */
2756 if (UNARY_CLASS_P (inner
))
2757 inner
= TREE_OPERAND (inner
, 0);
2758 else if (BINARY_CLASS_P (inner
))
2760 if (tree_invariant_p (TREE_OPERAND (inner
, 1)))
2761 inner
= TREE_OPERAND (inner
, 0);
2762 else if (tree_invariant_p (TREE_OPERAND (inner
, 0)))
2763 inner
= TREE_OPERAND (inner
, 1);
2775 /* Return which tree structure is used by T. */
2777 enum tree_node_structure_enum
2778 tree_node_structure (const_tree t
)
2780 const enum tree_code code
= TREE_CODE (t
);
2781 return tree_node_structure_for_code (code
);
2784 /* Set various status flags when building a CALL_EXPR object T. */
2787 process_call_operands (tree t
)
2789 bool side_effects
= TREE_SIDE_EFFECTS (t
);
2790 bool read_only
= false;
2791 int i
= call_expr_flags (t
);
2793 /* Calls have side-effects, except those to const or pure functions. */
2794 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
2795 side_effects
= true;
2796 /* Propagate TREE_READONLY of arguments for const functions. */
2800 if (!side_effects
|| read_only
)
2801 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
2803 tree op
= TREE_OPERAND (t
, i
);
2804 if (op
&& TREE_SIDE_EFFECTS (op
))
2805 side_effects
= true;
2806 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
2810 TREE_SIDE_EFFECTS (t
) = side_effects
;
2811 TREE_READONLY (t
) = read_only
;
2814 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
2815 size or offset that depends on a field within a record. */
2818 contains_placeholder_p (const_tree exp
)
2820 enum tree_code code
;
2825 code
= TREE_CODE (exp
);
2826 if (code
== PLACEHOLDER_EXPR
)
2829 switch (TREE_CODE_CLASS (code
))
2832 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2833 position computations since they will be converted into a
2834 WITH_RECORD_EXPR involving the reference, which will assume
2835 here will be valid. */
2836 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2838 case tcc_exceptional
:
2839 if (code
== TREE_LIST
)
2840 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2841 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2846 case tcc_comparison
:
2847 case tcc_expression
:
2851 /* Ignoring the first operand isn't quite right, but works best. */
2852 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2855 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2856 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2857 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2860 /* The save_expr function never wraps anything containing
2861 a PLACEHOLDER_EXPR. */
2868 switch (TREE_CODE_LENGTH (code
))
2871 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2873 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2874 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2885 const_call_expr_arg_iterator iter
;
2886 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
2887 if (CONTAINS_PLACEHOLDER_P (arg
))
2901 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
2902 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
2906 type_contains_placeholder_1 (const_tree type
)
2908 /* If the size contains a placeholder or the parent type (component type in
2909 the case of arrays) type involves a placeholder, this type does. */
2910 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2911 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2912 || (!POINTER_TYPE_P (type
)
2914 && type_contains_placeholder_p (TREE_TYPE (type
))))
2917 /* Now do type-specific checks. Note that the last part of the check above
2918 greatly limits what we have to do below. */
2919 switch (TREE_CODE (type
))
2927 case REFERENCE_TYPE
:
2935 case FIXED_POINT_TYPE
:
2936 /* Here we just check the bounds. */
2937 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2938 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2941 /* We have already checked the component type above, so just check the
2943 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2947 case QUAL_UNION_TYPE
:
2951 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
2952 if (TREE_CODE (field
) == FIELD_DECL
2953 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2954 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2955 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2956 || type_contains_placeholder_p (TREE_TYPE (field
))))
2967 /* Wrapper around above function used to cache its result. */
2970 type_contains_placeholder_p (tree type
)
2974 /* If the contains_placeholder_bits field has been initialized,
2975 then we know the answer. */
2976 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2977 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2979 /* Indicate that we've seen this type node, and the answer is false.
2980 This is what we want to return if we run into recursion via fields. */
2981 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2983 /* Compute the real value. */
2984 result
= type_contains_placeholder_1 (type
);
2986 /* Store the real value. */
2987 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2992 /* Push tree EXP onto vector QUEUE if it is not already present. */
2995 push_without_duplicates (tree exp
, VEC (tree
, heap
) **queue
)
3000 FOR_EACH_VEC_ELT (tree
, *queue
, i
, iter
)
3001 if (simple_cst_equal (iter
, exp
) == 1)
3005 VEC_safe_push (tree
, heap
, *queue
, exp
);
3008 /* Given a tree EXP, find all occurences of references to fields
3009 in a PLACEHOLDER_EXPR and place them in vector REFS without
3010 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3011 we assume here that EXP contains only arithmetic expressions
3012 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3016 find_placeholder_in_expr (tree exp
, VEC (tree
, heap
) **refs
)
3018 enum tree_code code
= TREE_CODE (exp
);
3022 /* We handle TREE_LIST and COMPONENT_REF separately. */
3023 if (code
== TREE_LIST
)
3025 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3026 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3028 else if (code
== COMPONENT_REF
)
3030 for (inner
= TREE_OPERAND (exp
, 0);
3031 REFERENCE_CLASS_P (inner
);
3032 inner
= TREE_OPERAND (inner
, 0))
3035 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3036 push_without_duplicates (exp
, refs
);
3038 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3041 switch (TREE_CODE_CLASS (code
))
3046 case tcc_declaration
:
3047 /* Variables allocated to static storage can stay. */
3048 if (!TREE_STATIC (exp
))
3049 push_without_duplicates (exp
, refs
);
3052 case tcc_expression
:
3053 /* This is the pattern built in ada/make_aligning_type. */
3054 if (code
== ADDR_EXPR
3055 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3057 push_without_duplicates (exp
, refs
);
3061 /* Fall through... */
3063 case tcc_exceptional
:
3066 case tcc_comparison
:
3068 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3069 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3073 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3074 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3082 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3083 return a tree with all occurrences of references to F in a
3084 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3085 CONST_DECLs. Note that we assume here that EXP contains only
3086 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3087 occurring only in their argument list. */
3090 substitute_in_expr (tree exp
, tree f
, tree r
)
3092 enum tree_code code
= TREE_CODE (exp
);
3093 tree op0
, op1
, op2
, op3
;
3096 /* We handle TREE_LIST and COMPONENT_REF separately. */
3097 if (code
== TREE_LIST
)
3099 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3100 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3101 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3104 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3106 else if (code
== COMPONENT_REF
)
3110 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3111 and it is the right field, replace it with R. */
3112 for (inner
= TREE_OPERAND (exp
, 0);
3113 REFERENCE_CLASS_P (inner
);
3114 inner
= TREE_OPERAND (inner
, 0))
3118 op1
= TREE_OPERAND (exp
, 1);
3120 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3123 /* If this expression hasn't been completed let, leave it alone. */
3124 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3127 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3128 if (op0
== TREE_OPERAND (exp
, 0))
3132 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3135 switch (TREE_CODE_CLASS (code
))
3140 case tcc_declaration
:
3146 case tcc_expression
:
3150 /* Fall through... */
3152 case tcc_exceptional
:
3155 case tcc_comparison
:
3157 switch (TREE_CODE_LENGTH (code
))
3163 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3164 if (op0
== TREE_OPERAND (exp
, 0))
3167 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3171 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3172 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3174 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3177 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3181 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3182 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3183 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3185 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3186 && op2
== TREE_OPERAND (exp
, 2))
3189 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3193 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3194 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3195 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3196 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3198 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3199 && op2
== TREE_OPERAND (exp
, 2)
3200 && op3
== TREE_OPERAND (exp
, 3))
3204 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3216 new_tree
= NULL_TREE
;
3218 /* If we are trying to replace F with a constant, inline back
3219 functions which do nothing else than computing a value from
3220 the arguments they are passed. This makes it possible to
3221 fold partially or entirely the replacement expression. */
3222 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3224 tree t
= maybe_inline_call_in_expr (exp
);
3226 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3229 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3231 tree op
= TREE_OPERAND (exp
, i
);
3232 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3236 new_tree
= copy_node (exp
);
3237 TREE_OPERAND (new_tree
, i
) = new_op
;
3243 new_tree
= fold (new_tree
);
3244 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3245 process_call_operands (new_tree
);
3256 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3258 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3259 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3264 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3265 for it within OBJ, a tree that is an object or a chain of references. */
3268 substitute_placeholder_in_expr (tree exp
, tree obj
)
3270 enum tree_code code
= TREE_CODE (exp
);
3271 tree op0
, op1
, op2
, op3
;
3274 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3275 in the chain of OBJ. */
3276 if (code
== PLACEHOLDER_EXPR
)
3278 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3281 for (elt
= obj
; elt
!= 0;
3282 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3283 || TREE_CODE (elt
) == COND_EXPR
)
3284 ? TREE_OPERAND (elt
, 1)
3285 : (REFERENCE_CLASS_P (elt
)
3286 || UNARY_CLASS_P (elt
)
3287 || BINARY_CLASS_P (elt
)
3288 || VL_EXP_CLASS_P (elt
)
3289 || EXPRESSION_CLASS_P (elt
))
3290 ? TREE_OPERAND (elt
, 0) : 0))
3291 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3294 for (elt
= obj
; elt
!= 0;
3295 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3296 || TREE_CODE (elt
) == COND_EXPR
)
3297 ? TREE_OPERAND (elt
, 1)
3298 : (REFERENCE_CLASS_P (elt
)
3299 || UNARY_CLASS_P (elt
)
3300 || BINARY_CLASS_P (elt
)
3301 || VL_EXP_CLASS_P (elt
)
3302 || EXPRESSION_CLASS_P (elt
))
3303 ? TREE_OPERAND (elt
, 0) : 0))
3304 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3305 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3307 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3309 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3310 survives until RTL generation, there will be an error. */
3314 /* TREE_LIST is special because we need to look at TREE_VALUE
3315 and TREE_CHAIN, not TREE_OPERANDS. */
3316 else if (code
== TREE_LIST
)
3318 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3319 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3320 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3323 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3326 switch (TREE_CODE_CLASS (code
))
3329 case tcc_declaration
:
3332 case tcc_exceptional
:
3335 case tcc_comparison
:
3336 case tcc_expression
:
3339 switch (TREE_CODE_LENGTH (code
))
3345 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3346 if (op0
== TREE_OPERAND (exp
, 0))
3349 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3353 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3354 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3356 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3359 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3363 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3364 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3365 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3367 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3368 && op2
== TREE_OPERAND (exp
, 2))
3371 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3375 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3376 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3377 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3378 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3380 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3381 && op2
== TREE_OPERAND (exp
, 2)
3382 && op3
== TREE_OPERAND (exp
, 3))
3386 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3398 new_tree
= NULL_TREE
;
3400 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3402 tree op
= TREE_OPERAND (exp
, i
);
3403 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
3407 new_tree
= copy_node (exp
);
3408 TREE_OPERAND (new_tree
, i
) = new_op
;
3414 new_tree
= fold (new_tree
);
3415 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3416 process_call_operands (new_tree
);
3427 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3429 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3430 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3435 /* Stabilize a reference so that we can use it any number of times
3436 without causing its operands to be evaluated more than once.
3437 Returns the stabilized reference. This works by means of save_expr,
3438 so see the caveats in the comments about save_expr.
3440 Also allows conversion expressions whose operands are references.
3441 Any other kind of expression is returned unchanged. */
3444 stabilize_reference (tree ref
)
3447 enum tree_code code
= TREE_CODE (ref
);
3454 /* No action is needed in this case. */
3459 case FIX_TRUNC_EXPR
:
3460 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
3464 result
= build_nt (INDIRECT_REF
,
3465 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
3469 result
= build_nt (COMPONENT_REF
,
3470 stabilize_reference (TREE_OPERAND (ref
, 0)),
3471 TREE_OPERAND (ref
, 1), NULL_TREE
);
3475 result
= build_nt (BIT_FIELD_REF
,
3476 stabilize_reference (TREE_OPERAND (ref
, 0)),
3477 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3478 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
3482 result
= build_nt (ARRAY_REF
,
3483 stabilize_reference (TREE_OPERAND (ref
, 0)),
3484 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3485 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3488 case ARRAY_RANGE_REF
:
3489 result
= build_nt (ARRAY_RANGE_REF
,
3490 stabilize_reference (TREE_OPERAND (ref
, 0)),
3491 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3492 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3496 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3497 it wouldn't be ignored. This matters when dealing with
3499 return stabilize_reference_1 (ref
);
3501 /* If arg isn't a kind of lvalue we recognize, make no change.
3502 Caller should recognize the error for an invalid lvalue. */
3507 return error_mark_node
;
3510 TREE_TYPE (result
) = TREE_TYPE (ref
);
3511 TREE_READONLY (result
) = TREE_READONLY (ref
);
3512 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3513 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3518 /* Subroutine of stabilize_reference; this is called for subtrees of
3519 references. Any expression with side-effects must be put in a SAVE_EXPR
3520 to ensure that it is only evaluated once.
3522 We don't put SAVE_EXPR nodes around everything, because assigning very
3523 simple expressions to temporaries causes us to miss good opportunities
3524 for optimizations. Among other things, the opportunity to fold in the
3525 addition of a constant into an addressing mode often gets lost, e.g.
3526 "y[i+1] += x;". In general, we take the approach that we should not make
3527 an assignment unless we are forced into it - i.e., that any non-side effect
3528 operator should be allowed, and that cse should take care of coalescing
3529 multiple utterances of the same expression should that prove fruitful. */
3532 stabilize_reference_1 (tree e
)
3535 enum tree_code code
= TREE_CODE (e
);
3537 /* We cannot ignore const expressions because it might be a reference
3538 to a const array but whose index contains side-effects. But we can
3539 ignore things that are actual constant or that already have been
3540 handled by this function. */
3542 if (tree_invariant_p (e
))
3545 switch (TREE_CODE_CLASS (code
))
3547 case tcc_exceptional
:
3549 case tcc_declaration
:
3550 case tcc_comparison
:
3552 case tcc_expression
:
3555 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3556 so that it will only be evaluated once. */
3557 /* The reference (r) and comparison (<) classes could be handled as
3558 below, but it is generally faster to only evaluate them once. */
3559 if (TREE_SIDE_EFFECTS (e
))
3560 return save_expr (e
);
3564 /* Constants need no processing. In fact, we should never reach
3569 /* Division is slow and tends to be compiled with jumps,
3570 especially the division by powers of 2 that is often
3571 found inside of an array reference. So do it just once. */
3572 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3573 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3574 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3575 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3576 return save_expr (e
);
3577 /* Recursively stabilize each operand. */
3578 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3579 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3583 /* Recursively stabilize each operand. */
3584 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3591 TREE_TYPE (result
) = TREE_TYPE (e
);
3592 TREE_READONLY (result
) = TREE_READONLY (e
);
3593 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3594 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3599 /* Low-level constructors for expressions. */
3601 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3602 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3605 recompute_tree_invariant_for_addr_expr (tree t
)
3608 bool tc
= true, se
= false;
3610 /* We started out assuming this address is both invariant and constant, but
3611 does not have side effects. Now go down any handled components and see if
3612 any of them involve offsets that are either non-constant or non-invariant.
3613 Also check for side-effects.
3615 ??? Note that this code makes no attempt to deal with the case where
3616 taking the address of something causes a copy due to misalignment. */
3618 #define UPDATE_FLAGS(NODE) \
3619 do { tree _node = (NODE); \
3620 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3621 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3623 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3624 node
= TREE_OPERAND (node
, 0))
3626 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3627 array reference (probably made temporarily by the G++ front end),
3628 so ignore all the operands. */
3629 if ((TREE_CODE (node
) == ARRAY_REF
3630 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3631 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3633 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3634 if (TREE_OPERAND (node
, 2))
3635 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3636 if (TREE_OPERAND (node
, 3))
3637 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3639 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3640 FIELD_DECL, apparently. The G++ front end can put something else
3641 there, at least temporarily. */
3642 else if (TREE_CODE (node
) == COMPONENT_REF
3643 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3645 if (TREE_OPERAND (node
, 2))
3646 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3648 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
3649 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3652 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3654 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3655 the address, since &(*a)->b is a form of addition. If it's a constant, the
3656 address is constant too. If it's a decl, its address is constant if the
3657 decl is static. Everything else is not constant and, furthermore,
3658 taking the address of a volatile variable is not volatile. */
3659 if (TREE_CODE (node
) == INDIRECT_REF
3660 || TREE_CODE (node
) == MEM_REF
)
3661 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3662 else if (CONSTANT_CLASS_P (node
))
3664 else if (DECL_P (node
))
3665 tc
&= (staticp (node
) != NULL_TREE
);
3669 se
|= TREE_SIDE_EFFECTS (node
);
3673 TREE_CONSTANT (t
) = tc
;
3674 TREE_SIDE_EFFECTS (t
) = se
;
3678 /* Build an expression of code CODE, data type TYPE, and operands as
3679 specified. Expressions and reference nodes can be created this way.
3680 Constants, decls, types and misc nodes cannot be.
3682 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3683 enough for all extant tree codes. */
3686 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3690 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3692 t
= make_node_stat (code PASS_MEM_STAT
);
3699 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3701 int length
= sizeof (struct tree_exp
);
3704 record_node_allocation_statistics (code
, length
);
3706 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3708 t
= ggc_alloc_zone_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
3710 memset (t
, 0, sizeof (struct tree_common
));
3712 TREE_SET_CODE (t
, code
);
3714 TREE_TYPE (t
) = type
;
3715 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3716 TREE_OPERAND (t
, 0) = node
;
3717 TREE_BLOCK (t
) = NULL_TREE
;
3718 if (node
&& !TYPE_P (node
))
3720 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3721 TREE_READONLY (t
) = TREE_READONLY (node
);
3724 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3725 TREE_SIDE_EFFECTS (t
) = 1;
3729 /* All of these have side-effects, no matter what their
3731 TREE_SIDE_EFFECTS (t
) = 1;
3732 TREE_READONLY (t
) = 0;
3736 /* Whether a dereference is readonly has nothing to do with whether
3737 its operand is readonly. */
3738 TREE_READONLY (t
) = 0;
3743 recompute_tree_invariant_for_addr_expr (t
);
3747 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3748 && node
&& !TYPE_P (node
)
3749 && TREE_CONSTANT (node
))
3750 TREE_CONSTANT (t
) = 1;
3751 if (TREE_CODE_CLASS (code
) == tcc_reference
3752 && node
&& TREE_THIS_VOLATILE (node
))
3753 TREE_THIS_VOLATILE (t
) = 1;
3760 #define PROCESS_ARG(N) \
3762 TREE_OPERAND (t, N) = arg##N; \
3763 if (arg##N &&!TYPE_P (arg##N)) \
3765 if (TREE_SIDE_EFFECTS (arg##N)) \
3767 if (!TREE_READONLY (arg##N) \
3768 && !CONSTANT_CLASS_P (arg##N)) \
3769 (void) (read_only = 0); \
3770 if (!TREE_CONSTANT (arg##N)) \
3771 (void) (constant = 0); \
3776 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3778 bool constant
, read_only
, side_effects
;
3781 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3783 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3784 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
3785 /* When sizetype precision doesn't match that of pointers
3786 we need to be able to build explicit extensions or truncations
3787 of the offset argument. */
3788 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
3789 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
3790 && TREE_CODE (arg1
) == INTEGER_CST
);
3792 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
3793 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
3794 && INTEGRAL_TYPE_P (TREE_TYPE (arg1
))
3795 && useless_type_conversion_p (sizetype
, TREE_TYPE (arg1
)));
3797 t
= make_node_stat (code PASS_MEM_STAT
);
3800 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3801 result based on those same flags for the arguments. But if the
3802 arguments aren't really even `tree' expressions, we shouldn't be trying
3805 /* Expressions without side effects may be constant if their
3806 arguments are as well. */
3807 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3808 || TREE_CODE_CLASS (code
) == tcc_binary
);
3810 side_effects
= TREE_SIDE_EFFECTS (t
);
3815 TREE_READONLY (t
) = read_only
;
3816 TREE_CONSTANT (t
) = constant
;
3817 TREE_SIDE_EFFECTS (t
) = side_effects
;
3818 TREE_THIS_VOLATILE (t
)
3819 = (TREE_CODE_CLASS (code
) == tcc_reference
3820 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3827 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3828 tree arg2 MEM_STAT_DECL
)
3830 bool constant
, read_only
, side_effects
;
3833 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
3834 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3836 t
= make_node_stat (code PASS_MEM_STAT
);
3841 /* As a special exception, if COND_EXPR has NULL branches, we
3842 assume that it is a gimple statement and always consider
3843 it to have side effects. */
3844 if (code
== COND_EXPR
3845 && tt
== void_type_node
3846 && arg1
== NULL_TREE
3847 && arg2
== NULL_TREE
)
3848 side_effects
= true;
3850 side_effects
= TREE_SIDE_EFFECTS (t
);
3856 if (code
== COND_EXPR
)
3857 TREE_READONLY (t
) = read_only
;
3859 TREE_SIDE_EFFECTS (t
) = side_effects
;
3860 TREE_THIS_VOLATILE (t
)
3861 = (TREE_CODE_CLASS (code
) == tcc_reference
3862 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3868 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3869 tree arg2
, tree arg3 MEM_STAT_DECL
)
3871 bool constant
, read_only
, side_effects
;
3874 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
3876 t
= make_node_stat (code PASS_MEM_STAT
);
3879 side_effects
= TREE_SIDE_EFFECTS (t
);
3886 TREE_SIDE_EFFECTS (t
) = side_effects
;
3887 TREE_THIS_VOLATILE (t
)
3888 = (TREE_CODE_CLASS (code
) == tcc_reference
3889 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3895 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3896 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
3898 bool constant
, read_only
, side_effects
;
3901 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
3903 t
= make_node_stat (code PASS_MEM_STAT
);
3906 side_effects
= TREE_SIDE_EFFECTS (t
);
3914 TREE_SIDE_EFFECTS (t
) = side_effects
;
3915 TREE_THIS_VOLATILE (t
)
3916 = (TREE_CODE_CLASS (code
) == tcc_reference
3917 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3923 build6_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3924 tree arg2
, tree arg3
, tree arg4
, tree arg5 MEM_STAT_DECL
)
3926 bool constant
, read_only
, side_effects
;
3929 gcc_assert (code
== TARGET_MEM_REF
);
3931 t
= make_node_stat (code PASS_MEM_STAT
);
3934 side_effects
= TREE_SIDE_EFFECTS (t
);
3941 if (code
== TARGET_MEM_REF
)
3945 TREE_SIDE_EFFECTS (t
) = side_effects
;
3946 TREE_THIS_VOLATILE (t
)
3947 = (code
== TARGET_MEM_REF
3948 && arg5
&& TREE_THIS_VOLATILE (arg5
));
3953 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
3954 on the pointer PTR. */
3957 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
3959 HOST_WIDE_INT offset
= 0;
3960 tree ptype
= TREE_TYPE (ptr
);
3962 /* For convenience allow addresses that collapse to a simple base
3964 if (TREE_CODE (ptr
) == ADDR_EXPR
3965 && (handled_component_p (TREE_OPERAND (ptr
, 0))
3966 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
3968 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
3970 ptr
= build_fold_addr_expr (ptr
);
3971 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
3973 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
3974 ptr
, build_int_cst (ptype
, offset
));
3975 SET_EXPR_LOCATION (tem
, loc
);
3979 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
3982 mem_ref_offset (const_tree t
)
3984 tree toff
= TREE_OPERAND (t
, 1);
3985 return double_int_sext (tree_to_double_int (toff
),
3986 TYPE_PRECISION (TREE_TYPE (toff
)));
3989 /* Return the pointer-type relevant for TBAA purposes from the
3990 gimple memory reference tree T. This is the type to be used for
3991 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T. */
3994 reference_alias_ptr_type (const_tree t
)
3996 const_tree base
= t
;
3997 while (handled_component_p (base
))
3998 base
= TREE_OPERAND (base
, 0);
3999 if (TREE_CODE (base
) == MEM_REF
)
4000 return TREE_TYPE (TREE_OPERAND (base
, 1));
4001 else if (TREE_CODE (base
) == TARGET_MEM_REF
)
4002 return TREE_TYPE (TMR_OFFSET (base
));
4004 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (base
)));
4007 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4008 offsetted by OFFSET units. */
4011 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4013 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4014 build_fold_addr_expr (base
),
4015 build_int_cst (ptr_type_node
, offset
));
4016 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4017 recompute_tree_invariant_for_addr_expr (addr
);
4021 /* Similar except don't specify the TREE_TYPE
4022 and leave the TREE_SIDE_EFFECTS as 0.
4023 It is permissible for arguments to be null,
4024 or even garbage if their values do not matter. */
4027 build_nt (enum tree_code code
, ...)
4034 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4038 t
= make_node (code
);
4039 length
= TREE_CODE_LENGTH (code
);
4041 for (i
= 0; i
< length
; i
++)
4042 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4048 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4052 build_nt_call_vec (tree fn
, VEC(tree
,gc
) *args
)
4057 ret
= build_vl_exp (CALL_EXPR
, VEC_length (tree
, args
) + 3);
4058 CALL_EXPR_FN (ret
) = fn
;
4059 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4060 FOR_EACH_VEC_ELT (tree
, args
, ix
, t
)
4061 CALL_EXPR_ARG (ret
, ix
) = t
;
4065 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4066 We do NOT enter this node in any sort of symbol table.
4068 LOC is the location of the decl.
4070 layout_decl is used to set up the decl's storage layout.
4071 Other slots are initialized to 0 or null pointers. */
4074 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4075 tree type MEM_STAT_DECL
)
4079 t
= make_node_stat (code PASS_MEM_STAT
);
4080 DECL_SOURCE_LOCATION (t
) = loc
;
4082 /* if (type == error_mark_node)
4083 type = integer_type_node; */
4084 /* That is not done, deliberately, so that having error_mark_node
4085 as the type can suppress useless errors in the use of this variable. */
4087 DECL_NAME (t
) = name
;
4088 TREE_TYPE (t
) = type
;
4090 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4096 /* Builds and returns function declaration with NAME and TYPE. */
4099 build_fn_decl (const char *name
, tree type
)
4101 tree id
= get_identifier (name
);
4102 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4104 DECL_EXTERNAL (decl
) = 1;
4105 TREE_PUBLIC (decl
) = 1;
4106 DECL_ARTIFICIAL (decl
) = 1;
4107 TREE_NOTHROW (decl
) = 1;
4112 VEC(tree
,gc
) *all_translation_units
;
4114 /* Builds a new translation-unit decl with name NAME, queues it in the
4115 global list of translation-unit decls and returns it. */
4118 build_translation_unit_decl (tree name
)
4120 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4122 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4123 VEC_safe_push (tree
, gc
, all_translation_units
, tu
);
4128 /* BLOCK nodes are used to represent the structure of binding contours
4129 and declarations, once those contours have been exited and their contents
4130 compiled. This information is used for outputting debugging info. */
4133 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4135 tree block
= make_node (BLOCK
);
4137 BLOCK_VARS (block
) = vars
;
4138 BLOCK_SUBBLOCKS (block
) = subblocks
;
4139 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4140 BLOCK_CHAIN (block
) = chain
;
4145 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4147 LOC is the location to use in tree T. */
4150 protected_set_expr_location (tree t
, location_t loc
)
4152 if (t
&& CAN_HAVE_LOCATION_P (t
))
4153 SET_EXPR_LOCATION (t
, loc
);
4156 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4160 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4162 DECL_ATTRIBUTES (ddecl
) = attribute
;
4166 /* Borrowed from hashtab.c iterative_hash implementation. */
4167 #define mix(a,b,c) \
4169 a -= b; a -= c; a ^= (c>>13); \
4170 b -= c; b -= a; b ^= (a<< 8); \
4171 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4172 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4173 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4174 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4175 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4176 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4177 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4181 /* Produce good hash value combining VAL and VAL2. */
4183 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
4185 /* the golden ratio; an arbitrary value. */
4186 hashval_t a
= 0x9e3779b9;
4192 /* Produce good hash value combining VAL and VAL2. */
4194 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
4196 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
4197 return iterative_hash_hashval_t (val
, val2
);
4200 hashval_t a
= (hashval_t
) val
;
4201 /* Avoid warnings about shifting of more than the width of the type on
4202 hosts that won't execute this path. */
4204 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
4206 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
4208 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
4209 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
4216 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4217 is ATTRIBUTE and its qualifiers are QUALS.
4219 Record such modified types already made so we don't make duplicates. */
4222 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4224 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4226 hashval_t hashcode
= 0;
4228 enum tree_code code
= TREE_CODE (ttype
);
4230 /* Building a distinct copy of a tagged type is inappropriate; it
4231 causes breakage in code that expects there to be a one-to-one
4232 relationship between a struct and its fields.
4233 build_duplicate_type is another solution (as used in
4234 handle_transparent_union_attribute), but that doesn't play well
4235 with the stronger C++ type identity model. */
4236 if (TREE_CODE (ttype
) == RECORD_TYPE
4237 || TREE_CODE (ttype
) == UNION_TYPE
4238 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4239 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4241 warning (OPT_Wattributes
,
4242 "ignoring attributes applied to %qT after definition",
4243 TYPE_MAIN_VARIANT (ttype
));
4244 return build_qualified_type (ttype
, quals
);
4247 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4248 ntype
= build_distinct_type_copy (ttype
);
4250 TYPE_ATTRIBUTES (ntype
) = attribute
;
4252 hashcode
= iterative_hash_object (code
, hashcode
);
4253 if (TREE_TYPE (ntype
))
4254 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
4256 hashcode
= attribute_hash_list (attribute
, hashcode
);
4258 switch (TREE_CODE (ntype
))
4261 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
4264 if (TYPE_DOMAIN (ntype
))
4265 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
4269 hashcode
= iterative_hash_object
4270 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
4271 hashcode
= iterative_hash_object
4272 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
4275 case FIXED_POINT_TYPE
:
4277 unsigned int precision
= TYPE_PRECISION (ntype
);
4278 hashcode
= iterative_hash_object (precision
, hashcode
);
4285 ntype
= type_hash_canon (hashcode
, ntype
);
4287 /* If the target-dependent attributes make NTYPE different from
4288 its canonical type, we will need to use structural equality
4289 checks for this type. */
4290 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4291 || !comp_type_attributes (ntype
, ttype
))
4292 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4293 else if (TYPE_CANONICAL (ntype
) == ntype
)
4294 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4296 ttype
= build_qualified_type (ntype
, quals
);
4298 else if (TYPE_QUALS (ttype
) != quals
)
4299 ttype
= build_qualified_type (ttype
, quals
);
4304 /* Compare two attributes for their value identity. Return true if the
4305 attribute values are known to be equal; otherwise return false.
4309 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4311 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4314 if (TREE_VALUE (attr1
) != NULL_TREE
4315 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4316 && TREE_VALUE (attr2
) != NULL
4317 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4318 return (simple_cst_list_equal (TREE_VALUE (attr1
),
4319 TREE_VALUE (attr2
)) == 1);
4321 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
4324 /* Return 0 if the attributes for two types are incompatible, 1 if they
4325 are compatible, and 2 if they are nearly compatible (which causes a
4326 warning to be generated). */
4328 comp_type_attributes (const_tree type1
, const_tree type2
)
4330 const_tree a1
= TYPE_ATTRIBUTES (type1
);
4331 const_tree a2
= TYPE_ATTRIBUTES (type2
);
4336 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4338 const struct attribute_spec
*as
;
4341 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
4342 if (!as
|| as
->affects_type_identity
== false)
4345 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
4346 if (!attr
|| !attribute_value_equal (a
, attr
))
4351 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4353 const struct attribute_spec
*as
;
4355 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
4356 if (!as
|| as
->affects_type_identity
== false)
4359 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
4361 /* We don't need to compare trees again, as we did this
4362 already in first loop. */
4364 /* All types - affecting identity - are equal, so
4365 there is no need to call target hook for comparison. */
4369 /* As some type combinations - like default calling-convention - might
4370 be compatible, we have to call the target hook to get the final result. */
4371 return targetm
.comp_type_attributes (type1
, type2
);
4374 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4377 Record such modified types already made so we don't make duplicates. */
4380 build_type_attribute_variant (tree ttype
, tree attribute
)
4382 return build_type_attribute_qual_variant (ttype
, attribute
,
4383 TYPE_QUALS (ttype
));
4387 /* Reset the expression *EXPR_P, a size or position.
4389 ??? We could reset all non-constant sizes or positions. But it's cheap
4390 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4392 We need to reset self-referential sizes or positions because they cannot
4393 be gimplified and thus can contain a CALL_EXPR after the gimplification
4394 is finished, which will run afoul of LTO streaming. And they need to be
4395 reset to something essentially dummy but not constant, so as to preserve
4396 the properties of the object they are attached to. */
4399 free_lang_data_in_one_sizepos (tree
*expr_p
)
4401 tree expr
= *expr_p
;
4402 if (CONTAINS_PLACEHOLDER_P (expr
))
4403 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
4407 /* Reset all the fields in a binfo node BINFO. We only keep
4408 BINFO_VIRTUALS, which is used by gimple_fold_obj_type_ref. */
4411 free_lang_data_in_binfo (tree binfo
)
4416 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
4418 BINFO_VTABLE (binfo
) = NULL_TREE
;
4419 BINFO_BASE_ACCESSES (binfo
) = NULL
;
4420 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
4421 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
4423 FOR_EACH_VEC_ELT (tree
, BINFO_BASE_BINFOS (binfo
), i
, t
)
4424 free_lang_data_in_binfo (t
);
4428 /* Reset all language specific information still present in TYPE. */
4431 free_lang_data_in_type (tree type
)
4433 gcc_assert (TYPE_P (type
));
4435 /* Give the FE a chance to remove its own data first. */
4436 lang_hooks
.free_lang_data (type
);
4438 TREE_LANG_FLAG_0 (type
) = 0;
4439 TREE_LANG_FLAG_1 (type
) = 0;
4440 TREE_LANG_FLAG_2 (type
) = 0;
4441 TREE_LANG_FLAG_3 (type
) = 0;
4442 TREE_LANG_FLAG_4 (type
) = 0;
4443 TREE_LANG_FLAG_5 (type
) = 0;
4444 TREE_LANG_FLAG_6 (type
) = 0;
4446 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4448 /* Remove the const and volatile qualifiers from arguments. The
4449 C++ front end removes them, but the C front end does not,
4450 leading to false ODR violation errors when merging two
4451 instances of the same function signature compiled by
4452 different front ends. */
4455 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
4457 tree arg_type
= TREE_VALUE (p
);
4459 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
4461 int quals
= TYPE_QUALS (arg_type
)
4463 & ~TYPE_QUAL_VOLATILE
;
4464 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
4465 free_lang_data_in_type (TREE_VALUE (p
));
4470 /* Remove members that are not actually FIELD_DECLs from the field
4471 list of an aggregate. These occur in C++. */
4472 if (RECORD_OR_UNION_TYPE_P (type
))
4476 /* Note that TYPE_FIELDS can be shared across distinct
4477 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4478 to be removed, we cannot set its TREE_CHAIN to NULL.
4479 Otherwise, we would not be able to find all the other fields
4480 in the other instances of this TREE_TYPE.
4482 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4484 member
= TYPE_FIELDS (type
);
4487 if (TREE_CODE (member
) == FIELD_DECL
)
4490 TREE_CHAIN (prev
) = member
;
4492 TYPE_FIELDS (type
) = member
;
4496 member
= TREE_CHAIN (member
);
4500 TREE_CHAIN (prev
) = NULL_TREE
;
4502 TYPE_FIELDS (type
) = NULL_TREE
;
4504 TYPE_METHODS (type
) = NULL_TREE
;
4505 if (TYPE_BINFO (type
))
4506 free_lang_data_in_binfo (TYPE_BINFO (type
));
4510 /* For non-aggregate types, clear out the language slot (which
4511 overloads TYPE_BINFO). */
4512 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
4514 if (INTEGRAL_TYPE_P (type
)
4515 || SCALAR_FLOAT_TYPE_P (type
)
4516 || FIXED_POINT_TYPE_P (type
))
4518 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
4519 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
4523 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
4524 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
4526 if (debug_info_level
< DINFO_LEVEL_TERSE
4527 || (TYPE_CONTEXT (type
)
4528 && TREE_CODE (TYPE_CONTEXT (type
)) != FUNCTION_DECL
4529 && TREE_CODE (TYPE_CONTEXT (type
)) != NAMESPACE_DECL
))
4530 TYPE_CONTEXT (type
) = NULL_TREE
;
4532 if (debug_info_level
< DINFO_LEVEL_TERSE
)
4533 TYPE_STUB_DECL (type
) = NULL_TREE
;
4537 /* Return true if DECL may need an assembler name to be set. */
4540 need_assembler_name_p (tree decl
)
4542 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4543 if (TREE_CODE (decl
) != FUNCTION_DECL
4544 && TREE_CODE (decl
) != VAR_DECL
)
4547 /* If DECL already has its assembler name set, it does not need a
4549 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
4550 || DECL_ASSEMBLER_NAME_SET_P (decl
))
4553 /* Abstract decls do not need an assembler name. */
4554 if (DECL_ABSTRACT (decl
))
4557 /* For VAR_DECLs, only static, public and external symbols need an
4559 if (TREE_CODE (decl
) == VAR_DECL
4560 && !TREE_STATIC (decl
)
4561 && !TREE_PUBLIC (decl
)
4562 && !DECL_EXTERNAL (decl
))
4565 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4567 /* Do not set assembler name on builtins. Allow RTL expansion to
4568 decide whether to expand inline or via a regular call. */
4569 if (DECL_BUILT_IN (decl
)
4570 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
4573 /* Functions represented in the callgraph need an assembler name. */
4574 if (cgraph_get_node (decl
) != NULL
)
4577 /* Unused and not public functions don't need an assembler name. */
4578 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
4586 /* Reset all language specific information still present in symbol
4590 free_lang_data_in_decl (tree decl
)
4592 gcc_assert (DECL_P (decl
));
4594 /* Give the FE a chance to remove its own data first. */
4595 lang_hooks
.free_lang_data (decl
);
4597 TREE_LANG_FLAG_0 (decl
) = 0;
4598 TREE_LANG_FLAG_1 (decl
) = 0;
4599 TREE_LANG_FLAG_2 (decl
) = 0;
4600 TREE_LANG_FLAG_3 (decl
) = 0;
4601 TREE_LANG_FLAG_4 (decl
) = 0;
4602 TREE_LANG_FLAG_5 (decl
) = 0;
4603 TREE_LANG_FLAG_6 (decl
) = 0;
4605 /* Identifiers need not have a type. */
4606 if (DECL_NAME (decl
))
4607 TREE_TYPE (DECL_NAME (decl
)) = NULL_TREE
;
4609 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
4610 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
4611 if (TREE_CODE (decl
) == FIELD_DECL
)
4612 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
4614 /* DECL_FCONTEXT is only used for debug info generation. */
4615 if (TREE_CODE (decl
) == FIELD_DECL
4616 && debug_info_level
< DINFO_LEVEL_TERSE
)
4617 DECL_FCONTEXT (decl
) = NULL_TREE
;
4619 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4621 if (gimple_has_body_p (decl
))
4625 /* If DECL has a gimple body, then the context for its
4626 arguments must be DECL. Otherwise, it doesn't really
4627 matter, as we will not be emitting any code for DECL. In
4628 general, there may be other instances of DECL created by
4629 the front end and since PARM_DECLs are generally shared,
4630 their DECL_CONTEXT changes as the replicas of DECL are
4631 created. The only time where DECL_CONTEXT is important
4632 is for the FUNCTION_DECLs that have a gimple body (since
4633 the PARM_DECL will be used in the function's body). */
4634 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
4635 DECL_CONTEXT (t
) = decl
;
4638 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
4639 At this point, it is not needed anymore. */
4640 DECL_SAVED_TREE (decl
) = NULL_TREE
;
4642 /* Clear the abstract origin if it refers to a method. Otherwise
4643 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
4644 origin will not be output correctly. */
4645 if (DECL_ABSTRACT_ORIGIN (decl
)
4646 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
4647 && RECORD_OR_UNION_TYPE_P
4648 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
4649 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
4651 else if (TREE_CODE (decl
) == VAR_DECL
)
4653 if ((DECL_EXTERNAL (decl
)
4654 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
4655 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
4656 DECL_INITIAL (decl
) = NULL_TREE
;
4658 else if (TREE_CODE (decl
) == TYPE_DECL
)
4659 DECL_INITIAL (decl
) = NULL_TREE
;
4660 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
4661 && DECL_INITIAL (decl
)
4662 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
4664 /* Strip builtins from the translation-unit BLOCK. We still have
4665 targets without builtin_decl support and also builtins are
4666 shared nodes and thus we can't use TREE_CHAIN in multiple
4668 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
4672 if (TREE_CODE (var
) == FUNCTION_DECL
4673 && DECL_BUILT_IN (var
))
4674 *nextp
= TREE_CHAIN (var
);
4676 nextp
= &TREE_CHAIN (var
);
4682 /* Data used when collecting DECLs and TYPEs for language data removal. */
4684 struct free_lang_data_d
4686 /* Worklist to avoid excessive recursion. */
4687 VEC(tree
,heap
) *worklist
;
4689 /* Set of traversed objects. Used to avoid duplicate visits. */
4690 struct pointer_set_t
*pset
;
4692 /* Array of symbols to process with free_lang_data_in_decl. */
4693 VEC(tree
,heap
) *decls
;
4695 /* Array of types to process with free_lang_data_in_type. */
4696 VEC(tree
,heap
) *types
;
4700 /* Save all language fields needed to generate proper debug information
4701 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4704 save_debug_info_for_decl (tree t
)
4706 /*struct saved_debug_info_d *sdi;*/
4708 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
4710 /* FIXME. Partial implementation for saving debug info removed. */
4714 /* Save all language fields needed to generate proper debug information
4715 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
4718 save_debug_info_for_type (tree t
)
4720 /*struct saved_debug_info_d *sdi;*/
4722 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
4724 /* FIXME. Partial implementation for saving debug info removed. */
4728 /* Add type or decl T to one of the list of tree nodes that need their
4729 language data removed. The lists are held inside FLD. */
4732 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
4736 VEC_safe_push (tree
, heap
, fld
->decls
, t
);
4737 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4738 save_debug_info_for_decl (t
);
4740 else if (TYPE_P (t
))
4742 VEC_safe_push (tree
, heap
, fld
->types
, t
);
4743 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4744 save_debug_info_for_type (t
);
4750 /* Push tree node T into FLD->WORKLIST. */
4753 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
4755 if (t
&& !is_lang_specific (t
) && !pointer_set_contains (fld
->pset
, t
))
4756 VEC_safe_push (tree
, heap
, fld
->worklist
, (t
));
4760 /* Operand callback helper for free_lang_data_in_node. *TP is the
4761 subtree operand being considered. */
4764 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
4767 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
4769 if (TREE_CODE (t
) == TREE_LIST
)
4772 /* Language specific nodes will be removed, so there is no need
4773 to gather anything under them. */
4774 if (is_lang_specific (t
))
4782 /* Note that walk_tree does not traverse every possible field in
4783 decls, so we have to do our own traversals here. */
4784 add_tree_to_fld_list (t
, fld
);
4786 fld_worklist_push (DECL_NAME (t
), fld
);
4787 fld_worklist_push (DECL_CONTEXT (t
), fld
);
4788 fld_worklist_push (DECL_SIZE (t
), fld
);
4789 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
4791 /* We are going to remove everything under DECL_INITIAL for
4792 TYPE_DECLs. No point walking them. */
4793 if (TREE_CODE (t
) != TYPE_DECL
)
4794 fld_worklist_push (DECL_INITIAL (t
), fld
);
4796 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
4797 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
4799 if (TREE_CODE (t
) == FUNCTION_DECL
)
4801 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
4802 fld_worklist_push (DECL_RESULT (t
), fld
);
4804 else if (TREE_CODE (t
) == TYPE_DECL
)
4806 fld_worklist_push (DECL_ARGUMENT_FLD (t
), fld
);
4807 fld_worklist_push (DECL_VINDEX (t
), fld
);
4809 else if (TREE_CODE (t
) == FIELD_DECL
)
4811 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
4812 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
4813 fld_worklist_push (DECL_QUALIFIER (t
), fld
);
4814 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
4815 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
4817 else if (TREE_CODE (t
) == VAR_DECL
)
4819 fld_worklist_push (DECL_SECTION_NAME (t
), fld
);
4820 fld_worklist_push (DECL_COMDAT_GROUP (t
), fld
);
4823 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
4824 && DECL_HAS_VALUE_EXPR_P (t
))
4825 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
4827 if (TREE_CODE (t
) != FIELD_DECL
4828 && TREE_CODE (t
) != TYPE_DECL
)
4829 fld_worklist_push (TREE_CHAIN (t
), fld
);
4832 else if (TYPE_P (t
))
4834 /* Note that walk_tree does not traverse every possible field in
4835 types, so we have to do our own traversals here. */
4836 add_tree_to_fld_list (t
, fld
);
4838 if (!RECORD_OR_UNION_TYPE_P (t
))
4839 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
4840 fld_worklist_push (TYPE_SIZE (t
), fld
);
4841 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
4842 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
4843 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
4844 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
4845 fld_worklist_push (TYPE_NAME (t
), fld
);
4846 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
4847 them and thus do not and want not to reach unused pointer types
4849 if (!POINTER_TYPE_P (t
))
4850 fld_worklist_push (TYPE_MINVAL (t
), fld
);
4851 if (!RECORD_OR_UNION_TYPE_P (t
))
4852 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
4853 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
4854 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
4855 do not and want not to reach unused variants this way. */
4856 fld_worklist_push (TYPE_CONTEXT (t
), fld
);
4857 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
4858 and want not to reach unused types this way. */
4860 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
4864 for (i
= 0; VEC_iterate (tree
, BINFO_BASE_BINFOS (TYPE_BINFO (t
)),
4866 fld_worklist_push (TREE_TYPE (tem
), fld
);
4867 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
4869 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
4870 && TREE_CODE (tem
) == TREE_LIST
)
4873 fld_worklist_push (TREE_VALUE (tem
), fld
);
4874 tem
= TREE_CHAIN (tem
);
4878 if (RECORD_OR_UNION_TYPE_P (t
))
4881 /* Push all TYPE_FIELDS - there can be interleaving interesting
4882 and non-interesting things. */
4883 tem
= TYPE_FIELDS (t
);
4886 if (TREE_CODE (tem
) == FIELD_DECL
)
4887 fld_worklist_push (tem
, fld
);
4888 tem
= TREE_CHAIN (tem
);
4892 fld_worklist_push (TREE_CHAIN (t
), fld
);
4895 else if (TREE_CODE (t
) == BLOCK
)
4898 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
4899 fld_worklist_push (tem
, fld
);
4900 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
4901 fld_worklist_push (tem
, fld
);
4902 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
4905 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
4906 fld_worklist_push (TREE_TYPE (t
), fld
);
4912 /* Find decls and types in T. */
4915 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
4919 if (!pointer_set_contains (fld
->pset
, t
))
4920 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
4921 if (VEC_empty (tree
, fld
->worklist
))
4923 t
= VEC_pop (tree
, fld
->worklist
);
4927 /* Translate all the types in LIST with the corresponding runtime
4931 get_eh_types_for_runtime (tree list
)
4935 if (list
== NULL_TREE
)
4938 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
4940 list
= TREE_CHAIN (list
);
4943 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
4944 TREE_CHAIN (prev
) = n
;
4945 prev
= TREE_CHAIN (prev
);
4946 list
= TREE_CHAIN (list
);
4953 /* Find decls and types referenced in EH region R and store them in
4954 FLD->DECLS and FLD->TYPES. */
4957 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
4968 /* The types referenced in each catch must first be changed to the
4969 EH types used at runtime. This removes references to FE types
4971 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
4973 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
4974 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
4979 case ERT_ALLOWED_EXCEPTIONS
:
4980 r
->u
.allowed
.type_list
4981 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
4982 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
4985 case ERT_MUST_NOT_THROW
:
4986 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
4987 find_decls_types_r
, fld
, fld
->pset
);
4993 /* Find decls and types referenced in cgraph node N and store them in
4994 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
4995 look for *every* kind of DECL and TYPE node reachable from N,
4996 including those embedded inside types and decls (i.e,, TYPE_DECLs,
4997 NAMESPACE_DECLs, etc). */
5000 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5003 struct function
*fn
;
5007 find_decls_types (n
->decl
, fld
);
5009 if (!gimple_has_body_p (n
->decl
))
5012 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5014 fn
= DECL_STRUCT_FUNCTION (n
->decl
);
5016 /* Traverse locals. */
5017 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5018 find_decls_types (t
, fld
);
5020 /* Traverse EH regions in FN. */
5023 FOR_ALL_EH_REGION_FN (r
, fn
)
5024 find_decls_types_in_eh_region (r
, fld
);
5027 /* Traverse every statement in FN. */
5028 FOR_EACH_BB_FN (bb
, fn
)
5030 gimple_stmt_iterator si
;
5033 for (si
= gsi_start_phis (bb
); !gsi_end_p (si
); gsi_next (&si
))
5035 gimple phi
= gsi_stmt (si
);
5037 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5039 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5040 find_decls_types (*arg_p
, fld
);
5044 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5046 gimple stmt
= gsi_stmt (si
);
5048 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5050 tree arg
= gimple_op (stmt
, i
);
5051 find_decls_types (arg
, fld
);
5058 /* Find decls and types referenced in varpool node N and store them in
5059 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5060 look for *every* kind of DECL and TYPE node reachable from N,
5061 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5062 NAMESPACE_DECLs, etc). */
5065 find_decls_types_in_var (struct varpool_node
*v
, struct free_lang_data_d
*fld
)
5067 find_decls_types (v
->decl
, fld
);
5070 /* If T needs an assembler name, have one created for it. */
5073 assign_assembler_name_if_neeeded (tree t
)
5075 if (need_assembler_name_p (t
))
5077 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5078 diagnostics that use input_location to show locus
5079 information. The problem here is that, at this point,
5080 input_location is generally anchored to the end of the file
5081 (since the parser is long gone), so we don't have a good
5082 position to pin it to.
5084 To alleviate this problem, this uses the location of T's
5085 declaration. Examples of this are
5086 testsuite/g++.dg/template/cond2.C and
5087 testsuite/g++.dg/template/pr35240.C. */
5088 location_t saved_location
= input_location
;
5089 input_location
= DECL_SOURCE_LOCATION (t
);
5091 decl_assembler_name (t
);
5093 input_location
= saved_location
;
5098 /* Free language specific information for every operand and expression
5099 in every node of the call graph. This process operates in three stages:
5101 1- Every callgraph node and varpool node is traversed looking for
5102 decls and types embedded in them. This is a more exhaustive
5103 search than that done by find_referenced_vars, because it will
5104 also collect individual fields, decls embedded in types, etc.
5106 2- All the decls found are sent to free_lang_data_in_decl.
5108 3- All the types found are sent to free_lang_data_in_type.
5110 The ordering between decls and types is important because
5111 free_lang_data_in_decl sets assembler names, which includes
5112 mangling. So types cannot be freed up until assembler names have
5116 free_lang_data_in_cgraph (void)
5118 struct cgraph_node
*n
;
5119 struct varpool_node
*v
;
5120 struct free_lang_data_d fld
;
5125 /* Initialize sets and arrays to store referenced decls and types. */
5126 fld
.pset
= pointer_set_create ();
5127 fld
.worklist
= NULL
;
5128 fld
.decls
= VEC_alloc (tree
, heap
, 100);
5129 fld
.types
= VEC_alloc (tree
, heap
, 100);
5131 /* Find decls and types in the body of every function in the callgraph. */
5132 for (n
= cgraph_nodes
; n
; n
= n
->next
)
5133 find_decls_types_in_node (n
, &fld
);
5135 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5136 find_decls_types (p
->decl
, &fld
);
5138 /* Find decls and types in every varpool symbol. */
5139 for (v
= varpool_nodes
; v
; v
= v
->next
)
5140 find_decls_types_in_var (v
, &fld
);
5142 /* Set the assembler name on every decl found. We need to do this
5143 now because free_lang_data_in_decl will invalidate data needed
5144 for mangling. This breaks mangling on interdependent decls. */
5145 FOR_EACH_VEC_ELT (tree
, fld
.decls
, i
, t
)
5146 assign_assembler_name_if_neeeded (t
);
5148 /* Traverse every decl found freeing its language data. */
5149 FOR_EACH_VEC_ELT (tree
, fld
.decls
, i
, t
)
5150 free_lang_data_in_decl (t
);
5152 /* Traverse every type found freeing its language data. */
5153 FOR_EACH_VEC_ELT (tree
, fld
.types
, i
, t
)
5154 free_lang_data_in_type (t
);
5156 pointer_set_destroy (fld
.pset
);
5157 VEC_free (tree
, heap
, fld
.worklist
);
5158 VEC_free (tree
, heap
, fld
.decls
);
5159 VEC_free (tree
, heap
, fld
.types
);
5163 /* Free resources that are used by FE but are not needed once they are done. */
5166 free_lang_data (void)
5170 /* If we are the LTO frontend we have freed lang-specific data already. */
5172 || !flag_generate_lto
)
5175 /* Allocate and assign alias sets to the standard integer types
5176 while the slots are still in the way the frontends generated them. */
5177 for (i
= 0; i
< itk_none
; ++i
)
5178 if (integer_types
[i
])
5179 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5181 /* Traverse the IL resetting language specific information for
5182 operands, expressions, etc. */
5183 free_lang_data_in_cgraph ();
5185 /* Create gimple variants for common types. */
5186 ptrdiff_type_node
= integer_type_node
;
5187 fileptr_type_node
= ptr_type_node
;
5188 if (TREE_CODE (boolean_type_node
) != BOOLEAN_TYPE
5189 || (TYPE_MODE (boolean_type_node
)
5190 != mode_for_size (BOOL_TYPE_SIZE
, MODE_INT
, 0))
5191 || TYPE_PRECISION (boolean_type_node
) != 1
5192 || !TYPE_UNSIGNED (boolean_type_node
))
5194 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
5195 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
5196 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
5197 TYPE_PRECISION (boolean_type_node
) = 1;
5198 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
5199 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
5202 /* Unify char_type_node with its properly signed variant. */
5203 if (TYPE_UNSIGNED (char_type_node
))
5204 unsigned_char_type_node
= char_type_node
;
5206 signed_char_type_node
= char_type_node
;
5208 /* Reset some langhooks. Do not reset types_compatible_p, it may
5209 still be used indirectly via the get_alias_set langhook. */
5210 lang_hooks
.callgraph
.analyze_expr
= NULL
;
5211 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5212 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5213 lang_hooks
.set_decl_assembler_name
= lhd_set_decl_assembler_name
;
5215 /* Reset diagnostic machinery. */
5216 diagnostic_starter (global_dc
) = default_tree_diagnostic_starter
;
5217 diagnostic_finalizer (global_dc
) = default_diagnostic_finalizer
;
5218 diagnostic_format_decoder (global_dc
) = default_tree_printer
;
5224 struct simple_ipa_opt_pass pass_ipa_free_lang_data
=
5228 "*free_lang_data", /* name */
5230 free_lang_data
, /* execute */
5233 0, /* static_pass_number */
5234 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5235 0, /* properties_required */
5236 0, /* properties_provided */
5237 0, /* properties_destroyed */
5238 0, /* todo_flags_start */
5239 TODO_ggc_collect
/* todo_flags_finish */
5243 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5246 We try both `text' and `__text__', ATTR may be either one. */
5247 /* ??? It might be a reasonable simplification to require ATTR to be only
5248 `text'. One might then also require attribute lists to be stored in
5249 their canonicalized form. */
5252 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
5257 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
5260 p
= IDENTIFIER_POINTER (ident
);
5261 ident_len
= IDENTIFIER_LENGTH (ident
);
5263 if (ident_len
== attr_len
5264 && strcmp (attr
, p
) == 0)
5267 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
5270 gcc_assert (attr
[1] == '_');
5271 gcc_assert (attr
[attr_len
- 2] == '_');
5272 gcc_assert (attr
[attr_len
- 1] == '_');
5273 if (ident_len
== attr_len
- 4
5274 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
5279 if (ident_len
== attr_len
+ 4
5280 && p
[0] == '_' && p
[1] == '_'
5281 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5282 && strncmp (attr
, p
+ 2, attr_len
) == 0)
5289 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5292 We try both `text' and `__text__', ATTR may be either one. */
5295 is_attribute_p (const char *attr
, const_tree ident
)
5297 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
5300 /* Given an attribute name and a list of attributes, return a pointer to the
5301 attribute's list element if the attribute is part of the list, or NULL_TREE
5302 if not found. If the attribute appears more than once, this only
5303 returns the first occurrence; the TREE_CHAIN of the return value should
5304 be passed back in if further occurrences are wanted. */
5307 lookup_attribute (const char *attr_name
, tree list
)
5310 size_t attr_len
= strlen (attr_name
);
5312 for (l
= list
; l
; l
= TREE_CHAIN (l
))
5314 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
5315 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
5321 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5325 remove_attribute (const char *attr_name
, tree list
)
5328 size_t attr_len
= strlen (attr_name
);
5330 for (p
= &list
; *p
; )
5333 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
5334 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
5335 *p
= TREE_CHAIN (l
);
5337 p
= &TREE_CHAIN (l
);
5343 /* Return an attribute list that is the union of a1 and a2. */
5346 merge_attributes (tree a1
, tree a2
)
5350 /* Either one unset? Take the set one. */
5352 if ((attributes
= a1
) == 0)
5355 /* One that completely contains the other? Take it. */
5357 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
5359 if (attribute_list_contained (a2
, a1
))
5363 /* Pick the longest list, and hang on the other list. */
5365 if (list_length (a1
) < list_length (a2
))
5366 attributes
= a2
, a2
= a1
;
5368 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
5371 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
5373 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
5374 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
5379 a1
= copy_node (a2
);
5380 TREE_CHAIN (a1
) = attributes
;
5389 /* Given types T1 and T2, merge their attributes and return
5393 merge_type_attributes (tree t1
, tree t2
)
5395 return merge_attributes (TYPE_ATTRIBUTES (t1
),
5396 TYPE_ATTRIBUTES (t2
));
5399 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5403 merge_decl_attributes (tree olddecl
, tree newdecl
)
5405 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
5406 DECL_ATTRIBUTES (newdecl
));
5409 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5411 /* Specialization of merge_decl_attributes for various Windows targets.
5413 This handles the following situation:
5415 __declspec (dllimport) int foo;
5418 The second instance of `foo' nullifies the dllimport. */
5421 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
5424 int delete_dllimport_p
= 1;
5426 /* What we need to do here is remove from `old' dllimport if it doesn't
5427 appear in `new'. dllimport behaves like extern: if a declaration is
5428 marked dllimport and a definition appears later, then the object
5429 is not dllimport'd. We also remove a `new' dllimport if the old list
5430 contains dllexport: dllexport always overrides dllimport, regardless
5431 of the order of declaration. */
5432 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
5433 delete_dllimport_p
= 0;
5434 else if (DECL_DLLIMPORT_P (new_tree
)
5435 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
5437 DECL_DLLIMPORT_P (new_tree
) = 0;
5438 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
5439 "dllimport ignored", new_tree
);
5441 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
5443 /* Warn about overriding a symbol that has already been used, e.g.:
5444 extern int __attribute__ ((dllimport)) foo;
5445 int* bar () {return &foo;}
5448 if (TREE_USED (old
))
5450 warning (0, "%q+D redeclared without dllimport attribute "
5451 "after being referenced with dll linkage", new_tree
);
5452 /* If we have used a variable's address with dllimport linkage,
5453 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5454 decl may already have had TREE_CONSTANT computed.
5455 We still remove the attribute so that assembler code refers
5456 to '&foo rather than '_imp__foo'. */
5457 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
5458 DECL_DLLIMPORT_P (new_tree
) = 1;
5461 /* Let an inline definition silently override the external reference,
5462 but otherwise warn about attribute inconsistency. */
5463 else if (TREE_CODE (new_tree
) == VAR_DECL
5464 || !DECL_DECLARED_INLINE_P (new_tree
))
5465 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
5466 "previous dllimport ignored", new_tree
);
5469 delete_dllimport_p
= 0;
5471 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
5473 if (delete_dllimport_p
)
5476 const size_t attr_len
= strlen ("dllimport");
5478 /* Scan the list for dllimport and delete it. */
5479 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
5481 if (is_attribute_with_length_p ("dllimport", attr_len
,
5484 if (prev
== NULL_TREE
)
5487 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
5496 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5497 struct attribute_spec.handler. */
5500 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
5506 /* These attributes may apply to structure and union types being created,
5507 but otherwise should pass to the declaration involved. */
5510 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
5511 | (int) ATTR_FLAG_ARRAY_NEXT
))
5513 *no_add_attrs
= true;
5514 return tree_cons (name
, args
, NULL_TREE
);
5516 if (TREE_CODE (node
) == RECORD_TYPE
5517 || TREE_CODE (node
) == UNION_TYPE
)
5519 node
= TYPE_NAME (node
);
5525 warning (OPT_Wattributes
, "%qE attribute ignored",
5527 *no_add_attrs
= true;
5532 if (TREE_CODE (node
) != FUNCTION_DECL
5533 && TREE_CODE (node
) != VAR_DECL
5534 && TREE_CODE (node
) != TYPE_DECL
)
5536 *no_add_attrs
= true;
5537 warning (OPT_Wattributes
, "%qE attribute ignored",
5542 if (TREE_CODE (node
) == TYPE_DECL
5543 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
5544 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
5546 *no_add_attrs
= true;
5547 warning (OPT_Wattributes
, "%qE attribute ignored",
5552 is_dllimport
= is_attribute_p ("dllimport", name
);
5554 /* Report error on dllimport ambiguities seen now before they cause
5558 /* Honor any target-specific overrides. */
5559 if (!targetm
.valid_dllimport_attribute_p (node
))
5560 *no_add_attrs
= true;
5562 else if (TREE_CODE (node
) == FUNCTION_DECL
5563 && DECL_DECLARED_INLINE_P (node
))
5565 warning (OPT_Wattributes
, "inline function %q+D declared as "
5566 " dllimport: attribute ignored", node
);
5567 *no_add_attrs
= true;
5569 /* Like MS, treat definition of dllimported variables and
5570 non-inlined functions on declaration as syntax errors. */
5571 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
5573 error ("function %q+D definition is marked dllimport", node
);
5574 *no_add_attrs
= true;
5577 else if (TREE_CODE (node
) == VAR_DECL
)
5579 if (DECL_INITIAL (node
))
5581 error ("variable %q+D definition is marked dllimport",
5583 *no_add_attrs
= true;
5586 /* `extern' needn't be specified with dllimport.
5587 Specify `extern' now and hope for the best. Sigh. */
5588 DECL_EXTERNAL (node
) = 1;
5589 /* Also, implicitly give dllimport'd variables declared within
5590 a function global scope, unless declared static. */
5591 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
5592 TREE_PUBLIC (node
) = 1;
5595 if (*no_add_attrs
== false)
5596 DECL_DLLIMPORT_P (node
) = 1;
5598 else if (TREE_CODE (node
) == FUNCTION_DECL
5599 && DECL_DECLARED_INLINE_P (node
)
5600 && flag_keep_inline_dllexport
)
5601 /* An exported function, even if inline, must be emitted. */
5602 DECL_EXTERNAL (node
) = 0;
5604 /* Report error if symbol is not accessible at global scope. */
5605 if (!TREE_PUBLIC (node
)
5606 && (TREE_CODE (node
) == VAR_DECL
5607 || TREE_CODE (node
) == FUNCTION_DECL
))
5609 error ("external linkage required for symbol %q+D because of "
5610 "%qE attribute", node
, name
);
5611 *no_add_attrs
= true;
5614 /* A dllexport'd entity must have default visibility so that other
5615 program units (shared libraries or the main executable) can see
5616 it. A dllimport'd entity must have default visibility so that
5617 the linker knows that undefined references within this program
5618 unit can be resolved by the dynamic linker. */
5621 if (DECL_VISIBILITY_SPECIFIED (node
)
5622 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
5623 error ("%qE implies default visibility, but %qD has already "
5624 "been declared with a different visibility",
5626 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
5627 DECL_VISIBILITY_SPECIFIED (node
) = 1;
5633 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
5635 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5636 of the various TYPE_QUAL values. */
5639 set_type_quals (tree type
, int type_quals
)
5641 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
5642 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
5643 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
5644 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
5647 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5650 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
5652 return (TYPE_QUALS (cand
) == type_quals
5653 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5654 /* Apparently this is needed for Objective-C. */
5655 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5656 /* Check alignment. */
5657 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
5658 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5659 TYPE_ATTRIBUTES (base
)));
5662 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5665 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
5667 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
5668 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5669 /* Apparently this is needed for Objective-C. */
5670 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5671 /* Check alignment. */
5672 && TYPE_ALIGN (cand
) == align
5673 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5674 TYPE_ATTRIBUTES (base
)));
5677 /* Return a version of the TYPE, qualified as indicated by the
5678 TYPE_QUALS, if one exists. If no qualified version exists yet,
5679 return NULL_TREE. */
5682 get_qualified_type (tree type
, int type_quals
)
5686 if (TYPE_QUALS (type
) == type_quals
)
5689 /* Search the chain of variants to see if there is already one there just
5690 like the one we need to have. If so, use that existing one. We must
5691 preserve the TYPE_NAME, since there is code that depends on this. */
5692 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5693 if (check_qualified_type (t
, type
, type_quals
))
5699 /* Like get_qualified_type, but creates the type if it does not
5700 exist. This function never returns NULL_TREE. */
5703 build_qualified_type (tree type
, int type_quals
)
5707 /* See if we already have the appropriate qualified variant. */
5708 t
= get_qualified_type (type
, type_quals
);
5710 /* If not, build it. */
5713 t
= build_variant_type_copy (type
);
5714 set_type_quals (t
, type_quals
);
5716 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5717 /* Propagate structural equality. */
5718 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5719 else if (TYPE_CANONICAL (type
) != type
)
5720 /* Build the underlying canonical type, since it is different
5722 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
5725 /* T is its own canonical type. */
5726 TYPE_CANONICAL (t
) = t
;
5733 /* Create a variant of type T with alignment ALIGN. */
5736 build_aligned_type (tree type
, unsigned int align
)
5740 if (TYPE_PACKED (type
)
5741 || TYPE_ALIGN (type
) == align
)
5744 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5745 if (check_aligned_type (t
, type
, align
))
5748 t
= build_variant_type_copy (type
);
5749 TYPE_ALIGN (t
) = align
;
5754 /* Create a new distinct copy of TYPE. The new type is made its own
5755 MAIN_VARIANT. If TYPE requires structural equality checks, the
5756 resulting type requires structural equality checks; otherwise, its
5757 TYPE_CANONICAL points to itself. */
5760 build_distinct_type_copy (tree type
)
5762 tree t
= copy_node (type
);
5764 TYPE_POINTER_TO (t
) = 0;
5765 TYPE_REFERENCE_TO (t
) = 0;
5767 /* Set the canonical type either to a new equivalence class, or
5768 propagate the need for structural equality checks. */
5769 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5770 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5772 TYPE_CANONICAL (t
) = t
;
5774 /* Make it its own variant. */
5775 TYPE_MAIN_VARIANT (t
) = t
;
5776 TYPE_NEXT_VARIANT (t
) = 0;
5778 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5779 whose TREE_TYPE is not t. This can also happen in the Ada
5780 frontend when using subtypes. */
5785 /* Create a new variant of TYPE, equivalent but distinct. This is so
5786 the caller can modify it. TYPE_CANONICAL for the return type will
5787 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5788 are considered equal by the language itself (or that both types
5789 require structural equality checks). */
5792 build_variant_type_copy (tree type
)
5794 tree t
, m
= TYPE_MAIN_VARIANT (type
);
5796 t
= build_distinct_type_copy (type
);
5798 /* Since we're building a variant, assume that it is a non-semantic
5799 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5800 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
5802 /* Add the new type to the chain of variants of TYPE. */
5803 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
5804 TYPE_NEXT_VARIANT (m
) = t
;
5805 TYPE_MAIN_VARIANT (t
) = m
;
5810 /* Return true if the from tree in both tree maps are equal. */
5813 tree_map_base_eq (const void *va
, const void *vb
)
5815 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
5816 *const b
= (const struct tree_map_base
*) vb
;
5817 return (a
->from
== b
->from
);
5820 /* Hash a from tree in a tree_base_map. */
5823 tree_map_base_hash (const void *item
)
5825 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
5828 /* Return true if this tree map structure is marked for garbage collection
5829 purposes. We simply return true if the from tree is marked, so that this
5830 structure goes away when the from tree goes away. */
5833 tree_map_base_marked_p (const void *p
)
5835 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
5838 /* Hash a from tree in a tree_map. */
5841 tree_map_hash (const void *item
)
5843 return (((const struct tree_map
*) item
)->hash
);
5846 /* Hash a from tree in a tree_decl_map. */
5849 tree_decl_map_hash (const void *item
)
5851 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
5854 /* Return the initialization priority for DECL. */
5857 decl_init_priority_lookup (tree decl
)
5859 struct tree_priority_map
*h
;
5860 struct tree_map_base in
;
5862 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
5864 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
5865 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
5868 /* Return the finalization priority for DECL. */
5871 decl_fini_priority_lookup (tree decl
)
5873 struct tree_priority_map
*h
;
5874 struct tree_map_base in
;
5876 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
5878 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
5879 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
5882 /* Return the initialization and finalization priority information for
5883 DECL. If there is no previous priority information, a freshly
5884 allocated structure is returned. */
5886 static struct tree_priority_map
*
5887 decl_priority_info (tree decl
)
5889 struct tree_priority_map in
;
5890 struct tree_priority_map
*h
;
5893 in
.base
.from
= decl
;
5894 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
5895 h
= (struct tree_priority_map
*) *loc
;
5898 h
= ggc_alloc_cleared_tree_priority_map ();
5900 h
->base
.from
= decl
;
5901 h
->init
= DEFAULT_INIT_PRIORITY
;
5902 h
->fini
= DEFAULT_INIT_PRIORITY
;
5908 /* Set the initialization priority for DECL to PRIORITY. */
5911 decl_init_priority_insert (tree decl
, priority_type priority
)
5913 struct tree_priority_map
*h
;
5915 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
5916 h
= decl_priority_info (decl
);
5920 /* Set the finalization priority for DECL to PRIORITY. */
5923 decl_fini_priority_insert (tree decl
, priority_type priority
)
5925 struct tree_priority_map
*h
;
5927 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
5928 h
= decl_priority_info (decl
);
5932 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5935 print_debug_expr_statistics (void)
5937 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
5938 (long) htab_size (debug_expr_for_decl
),
5939 (long) htab_elements (debug_expr_for_decl
),
5940 htab_collisions (debug_expr_for_decl
));
5943 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
5946 print_value_expr_statistics (void)
5948 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
5949 (long) htab_size (value_expr_for_decl
),
5950 (long) htab_elements (value_expr_for_decl
),
5951 htab_collisions (value_expr_for_decl
));
5954 /* Lookup a debug expression for FROM, and return it if we find one. */
5957 decl_debug_expr_lookup (tree from
)
5959 struct tree_decl_map
*h
, in
;
5960 in
.base
.from
= from
;
5962 h
= (struct tree_decl_map
*)
5963 htab_find_with_hash (debug_expr_for_decl
, &in
, DECL_UID (from
));
5969 /* Insert a mapping FROM->TO in the debug expression hashtable. */
5972 decl_debug_expr_insert (tree from
, tree to
)
5974 struct tree_decl_map
*h
;
5977 h
= ggc_alloc_tree_decl_map ();
5978 h
->base
.from
= from
;
5980 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, DECL_UID (from
),
5982 *(struct tree_decl_map
**) loc
= h
;
5985 /* Lookup a value expression for FROM, and return it if we find one. */
5988 decl_value_expr_lookup (tree from
)
5990 struct tree_decl_map
*h
, in
;
5991 in
.base
.from
= from
;
5993 h
= (struct tree_decl_map
*)
5994 htab_find_with_hash (value_expr_for_decl
, &in
, DECL_UID (from
));
6000 /* Insert a mapping FROM->TO in the value expression hashtable. */
6003 decl_value_expr_insert (tree from
, tree to
)
6005 struct tree_decl_map
*h
;
6008 h
= ggc_alloc_tree_decl_map ();
6009 h
->base
.from
= from
;
6011 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, DECL_UID (from
),
6013 *(struct tree_decl_map
**) loc
= h
;
6016 /* Hashing of types so that we don't make duplicates.
6017 The entry point is `type_hash_canon'. */
6019 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6020 with types in the TREE_VALUE slots), by adding the hash codes
6021 of the individual types. */
6024 type_hash_list (const_tree list
, hashval_t hashcode
)
6028 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6029 if (TREE_VALUE (tail
) != error_mark_node
)
6030 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
6036 /* These are the Hashtable callback functions. */
6038 /* Returns true iff the types are equivalent. */
6041 type_hash_eq (const void *va
, const void *vb
)
6043 const struct type_hash
*const a
= (const struct type_hash
*) va
,
6044 *const b
= (const struct type_hash
*) vb
;
6046 /* First test the things that are the same for all types. */
6047 if (a
->hash
!= b
->hash
6048 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6049 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6050 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6051 TYPE_ATTRIBUTES (b
->type
))
6052 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6053 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6056 /* Be careful about comparing arrays before and after the element type
6057 has been completed; don't compare TYPE_ALIGN unless both types are
6059 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6060 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6061 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6064 switch (TREE_CODE (a
->type
))
6069 case REFERENCE_TYPE
:
6073 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6076 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6077 && !(TYPE_VALUES (a
->type
)
6078 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6079 && TYPE_VALUES (b
->type
)
6080 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6081 && type_list_equal (TYPE_VALUES (a
->type
),
6082 TYPE_VALUES (b
->type
))))
6085 /* ... fall through ... */
6090 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6091 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6092 TYPE_MAX_VALUE (b
->type
)))
6093 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6094 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6095 TYPE_MIN_VALUE (b
->type
))));
6097 case FIXED_POINT_TYPE
:
6098 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6101 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6104 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6105 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6106 || (TYPE_ARG_TYPES (a
->type
)
6107 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6108 && TYPE_ARG_TYPES (b
->type
)
6109 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6110 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6111 TYPE_ARG_TYPES (b
->type
)))))
6115 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6119 case QUAL_UNION_TYPE
:
6120 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6121 || (TYPE_FIELDS (a
->type
)
6122 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6123 && TYPE_FIELDS (b
->type
)
6124 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6125 && type_list_equal (TYPE_FIELDS (a
->type
),
6126 TYPE_FIELDS (b
->type
))));
6129 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6130 || (TYPE_ARG_TYPES (a
->type
)
6131 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6132 && TYPE_ARG_TYPES (b
->type
)
6133 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6134 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6135 TYPE_ARG_TYPES (b
->type
))))
6143 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6144 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6149 /* Return the cached hash value. */
6152 type_hash_hash (const void *item
)
6154 return ((const struct type_hash
*) item
)->hash
;
6157 /* Look in the type hash table for a type isomorphic to TYPE.
6158 If one is found, return it. Otherwise return 0. */
6161 type_hash_lookup (hashval_t hashcode
, tree type
)
6163 struct type_hash
*h
, in
;
6165 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6166 must call that routine before comparing TYPE_ALIGNs. */
6172 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
6179 /* Add an entry to the type-hash-table
6180 for a type TYPE whose hash code is HASHCODE. */
6183 type_hash_add (hashval_t hashcode
, tree type
)
6185 struct type_hash
*h
;
6188 h
= ggc_alloc_type_hash ();
6191 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
6195 /* Given TYPE, and HASHCODE its hash code, return the canonical
6196 object for an identical type if one already exists.
6197 Otherwise, return TYPE, and record it as the canonical object.
6199 To use this function, first create a type of the sort you want.
6200 Then compute its hash code from the fields of the type that
6201 make it different from other similar types.
6202 Then call this function and use the value. */
6205 type_hash_canon (unsigned int hashcode
, tree type
)
6209 /* The hash table only contains main variants, so ensure that's what we're
6211 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6213 /* See if the type is in the hash table already. If so, return it.
6214 Otherwise, add the type. */
6215 t1
= type_hash_lookup (hashcode
, type
);
6218 #ifdef GATHER_STATISTICS
6219 tree_node_counts
[(int) t_kind
]--;
6220 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
6226 type_hash_add (hashcode
, type
);
6231 /* See if the data pointed to by the type hash table is marked. We consider
6232 it marked if the type is marked or if a debug type number or symbol
6233 table entry has been made for the type. */
6236 type_hash_marked_p (const void *p
)
6238 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
6240 return ggc_marked_p (type
);
6244 print_type_hash_statistics (void)
6246 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6247 (long) htab_size (type_hash_table
),
6248 (long) htab_elements (type_hash_table
),
6249 htab_collisions (type_hash_table
));
6252 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6253 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6254 by adding the hash codes of the individual attributes. */
6257 attribute_hash_list (const_tree list
, hashval_t hashcode
)
6261 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6262 /* ??? Do we want to add in TREE_VALUE too? */
6263 hashcode
= iterative_hash_object
6264 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
6268 /* Given two lists of attributes, return true if list l2 is
6269 equivalent to l1. */
6272 attribute_list_equal (const_tree l1
, const_tree l2
)
6274 return attribute_list_contained (l1
, l2
)
6275 && attribute_list_contained (l2
, l1
);
6278 /* Given two lists of attributes, return true if list L2 is
6279 completely contained within L1. */
6280 /* ??? This would be faster if attribute names were stored in a canonicalized
6281 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6282 must be used to show these elements are equivalent (which they are). */
6283 /* ??? It's not clear that attributes with arguments will always be handled
6287 attribute_list_contained (const_tree l1
, const_tree l2
)
6291 /* First check the obvious, maybe the lists are identical. */
6295 /* Maybe the lists are similar. */
6296 for (t1
= l1
, t2
= l2
;
6298 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
6299 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
6300 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
6302 /* Maybe the lists are equal. */
6303 if (t1
== 0 && t2
== 0)
6306 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
6309 /* This CONST_CAST is okay because lookup_attribute does not
6310 modify its argument and the return value is assigned to a
6312 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
6313 CONST_CAST_TREE(l1
));
6314 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
6315 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
6319 if (attr
== NULL_TREE
)
6326 /* Given two lists of types
6327 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6328 return 1 if the lists contain the same types in the same order.
6329 Also, the TREE_PURPOSEs must match. */
6332 type_list_equal (const_tree l1
, const_tree l2
)
6336 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6337 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6338 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6339 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6340 && (TREE_TYPE (TREE_PURPOSE (t1
))
6341 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6347 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6348 given by TYPE. If the argument list accepts variable arguments,
6349 then this function counts only the ordinary arguments. */
6352 type_num_arguments (const_tree type
)
6357 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
6358 /* If the function does not take a variable number of arguments,
6359 the last element in the list will have type `void'. */
6360 if (VOID_TYPE_P (TREE_VALUE (t
)))
6368 /* Nonzero if integer constants T1 and T2
6369 represent the same constant value. */
6372 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6377 if (t1
== 0 || t2
== 0)
6380 if (TREE_CODE (t1
) == INTEGER_CST
6381 && TREE_CODE (t2
) == INTEGER_CST
6382 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6383 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
6389 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6390 The precise way of comparison depends on their data type. */
6393 tree_int_cst_lt (const_tree t1
, const_tree t2
)
6398 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
6400 int t1_sgn
= tree_int_cst_sgn (t1
);
6401 int t2_sgn
= tree_int_cst_sgn (t2
);
6403 if (t1_sgn
< t2_sgn
)
6405 else if (t1_sgn
> t2_sgn
)
6407 /* Otherwise, both are non-negative, so we compare them as
6408 unsigned just in case one of them would overflow a signed
6411 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
6412 return INT_CST_LT (t1
, t2
);
6414 return INT_CST_LT_UNSIGNED (t1
, t2
);
6417 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6420 tree_int_cst_compare (const_tree t1
, const_tree t2
)
6422 if (tree_int_cst_lt (t1
, t2
))
6424 else if (tree_int_cst_lt (t2
, t1
))
6430 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6431 the host. If POS is zero, the value can be represented in a single
6432 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6433 be represented in a single unsigned HOST_WIDE_INT. */
6436 host_integerp (const_tree t
, int pos
)
6441 return (TREE_CODE (t
) == INTEGER_CST
6442 && ((TREE_INT_CST_HIGH (t
) == 0
6443 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
6444 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
6445 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
6446 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
6447 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
6448 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
6449 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
6452 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6453 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6454 be non-negative. We must be able to satisfy the above conditions. */
6457 tree_low_cst (const_tree t
, int pos
)
6459 gcc_assert (host_integerp (t
, pos
));
6460 return TREE_INT_CST_LOW (t
);
6463 /* Return the most significant bit of the integer constant T. */
6466 tree_int_cst_msb (const_tree t
)
6470 unsigned HOST_WIDE_INT l
;
6472 /* Note that using TYPE_PRECISION here is wrong. We care about the
6473 actual bits, not the (arbitrary) range of the type. */
6474 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
6475 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
6476 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
6477 return (l
& 1) == 1;
6480 /* Return an indication of the sign of the integer constant T.
6481 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6482 Note that -1 will never be returned if T's type is unsigned. */
6485 tree_int_cst_sgn (const_tree t
)
6487 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
6489 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6491 else if (TREE_INT_CST_HIGH (t
) < 0)
6497 /* Return the minimum number of bits needed to represent VALUE in a
6498 signed or unsigned type, UNSIGNEDP says which. */
6501 tree_int_cst_min_precision (tree value
, bool unsignedp
)
6505 /* If the value is negative, compute its negative minus 1. The latter
6506 adjustment is because the absolute value of the largest negative value
6507 is one larger than the largest positive value. This is equivalent to
6508 a bit-wise negation, so use that operation instead. */
6510 if (tree_int_cst_sgn (value
) < 0)
6511 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
6513 /* Return the number of bits needed, taking into account the fact
6514 that we need one more bit for a signed than unsigned type. */
6516 if (integer_zerop (value
))
6519 log
= tree_floor_log2 (value
);
6521 return log
+ 1 + !unsignedp
;
6524 /* Compare two constructor-element-type constants. Return 1 if the lists
6525 are known to be equal; otherwise return 0. */
6528 simple_cst_list_equal (const_tree l1
, const_tree l2
)
6530 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
6532 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
6535 l1
= TREE_CHAIN (l1
);
6536 l2
= TREE_CHAIN (l2
);
6542 /* Return truthvalue of whether T1 is the same tree structure as T2.
6543 Return 1 if they are the same.
6544 Return 0 if they are understandably different.
6545 Return -1 if either contains tree structure not understood by
6549 simple_cst_equal (const_tree t1
, const_tree t2
)
6551 enum tree_code code1
, code2
;
6557 if (t1
== 0 || t2
== 0)
6560 code1
= TREE_CODE (t1
);
6561 code2
= TREE_CODE (t2
);
6563 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
6565 if (CONVERT_EXPR_CODE_P (code2
)
6566 || code2
== NON_LVALUE_EXPR
)
6567 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6569 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
6572 else if (CONVERT_EXPR_CODE_P (code2
)
6573 || code2
== NON_LVALUE_EXPR
)
6574 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
6582 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6583 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
6586 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
6589 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
6592 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
6593 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
6594 TREE_STRING_LENGTH (t1
)));
6598 unsigned HOST_WIDE_INT idx
;
6599 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
6600 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
6602 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
6605 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
6606 /* ??? Should we handle also fields here? */
6607 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
6608 VEC_index (constructor_elt
, v2
, idx
)->value
))
6614 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6617 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
6620 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
6623 const_tree arg1
, arg2
;
6624 const_call_expr_arg_iterator iter1
, iter2
;
6625 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
6626 arg2
= first_const_call_expr_arg (t2
, &iter2
);
6628 arg1
= next_const_call_expr_arg (&iter1
),
6629 arg2
= next_const_call_expr_arg (&iter2
))
6631 cmp
= simple_cst_equal (arg1
, arg2
);
6635 return arg1
== arg2
;
6639 /* Special case: if either target is an unallocated VAR_DECL,
6640 it means that it's going to be unified with whatever the
6641 TARGET_EXPR is really supposed to initialize, so treat it
6642 as being equivalent to anything. */
6643 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
6644 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
6645 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
6646 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
6647 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
6648 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
6651 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6656 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
6658 case WITH_CLEANUP_EXPR
:
6659 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6663 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
6666 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
6667 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6681 /* This general rule works for most tree codes. All exceptions should be
6682 handled above. If this is a language-specific tree code, we can't
6683 trust what might be in the operand, so say we don't know
6685 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
6688 switch (TREE_CODE_CLASS (code1
))
6692 case tcc_comparison
:
6693 case tcc_expression
:
6697 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
6699 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
6711 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6712 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6713 than U, respectively. */
6716 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
6718 if (tree_int_cst_sgn (t
) < 0)
6720 else if (TREE_INT_CST_HIGH (t
) != 0)
6722 else if (TREE_INT_CST_LOW (t
) == u
)
6724 else if (TREE_INT_CST_LOW (t
) < u
)
6730 /* Return true if CODE represents an associative tree code. Otherwise
6733 associative_tree_code (enum tree_code code
)
6752 /* Return true if CODE represents a commutative tree code. Otherwise
6755 commutative_tree_code (enum tree_code code
)
6768 case UNORDERED_EXPR
:
6772 case TRUTH_AND_EXPR
:
6773 case TRUTH_XOR_EXPR
:
6783 /* Return true if CODE represents a ternary tree code for which the
6784 first two operands are commutative. Otherwise return false. */
6786 commutative_ternary_tree_code (enum tree_code code
)
6790 case WIDEN_MULT_PLUS_EXPR
:
6791 case WIDEN_MULT_MINUS_EXPR
:
6800 /* Generate a hash value for an expression. This can be used iteratively
6801 by passing a previous result as the VAL argument.
6803 This function is intended to produce the same hash for expressions which
6804 would compare equal using operand_equal_p. */
6807 iterative_hash_expr (const_tree t
, hashval_t val
)
6810 enum tree_code code
;
6814 return iterative_hash_hashval_t (0, val
);
6816 code
= TREE_CODE (t
);
6820 /* Alas, constants aren't shared, so we can't rely on pointer
6823 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
6824 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
6827 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
6829 return iterative_hash_hashval_t (val2
, val
);
6833 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
6835 return iterative_hash_hashval_t (val2
, val
);
6838 return iterative_hash (TREE_STRING_POINTER (t
),
6839 TREE_STRING_LENGTH (t
), val
);
6841 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
6842 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
6844 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
6846 /* We can just compare by pointer. */
6847 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
6848 case PLACEHOLDER_EXPR
:
6849 /* The node itself doesn't matter. */
6852 /* A list of expressions, for a CALL_EXPR or as the elements of a
6854 for (; t
; t
= TREE_CHAIN (t
))
6855 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
6859 unsigned HOST_WIDE_INT idx
;
6861 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
6863 val
= iterative_hash_expr (field
, val
);
6864 val
= iterative_hash_expr (value
, val
);
6870 /* The type of the second operand is relevant, except for
6871 its top-level qualifiers. */
6872 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t
, 1)));
6874 val
= iterative_hash_object (TYPE_HASH (type
), val
);
6876 /* We could use the standard hash computation from this point
6878 val
= iterative_hash_object (code
, val
);
6879 val
= iterative_hash_expr (TREE_OPERAND (t
, 1), val
);
6880 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
6884 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
6885 Otherwise nodes that compare equal according to operand_equal_p might
6886 get different hash codes. However, don't do this for machine specific
6887 or front end builtins, since the function code is overloaded in those
6889 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
6890 && built_in_decls
[DECL_FUNCTION_CODE (t
)])
6892 t
= built_in_decls
[DECL_FUNCTION_CODE (t
)];
6893 code
= TREE_CODE (t
);
6897 tclass
= TREE_CODE_CLASS (code
);
6899 if (tclass
== tcc_declaration
)
6901 /* DECL's have a unique ID */
6902 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
6906 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
6908 val
= iterative_hash_object (code
, val
);
6910 /* Don't hash the type, that can lead to having nodes which
6911 compare equal according to operand_equal_p, but which
6912 have different hash codes. */
6913 if (CONVERT_EXPR_CODE_P (code
)
6914 || code
== NON_LVALUE_EXPR
)
6916 /* Make sure to include signness in the hash computation. */
6917 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
6918 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
6921 else if (commutative_tree_code (code
))
6923 /* It's a commutative expression. We want to hash it the same
6924 however it appears. We do this by first hashing both operands
6925 and then rehashing based on the order of their independent
6927 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
6928 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
6932 t
= one
, one
= two
, two
= t
;
6934 val
= iterative_hash_hashval_t (one
, val
);
6935 val
= iterative_hash_hashval_t (two
, val
);
6938 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
6939 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
6946 /* Generate a hash value for a pair of expressions. This can be used
6947 iteratively by passing a previous result as the VAL argument.
6949 The same hash value is always returned for a given pair of expressions,
6950 regardless of the order in which they are presented. This is useful in
6951 hashing the operands of commutative functions. */
6954 iterative_hash_exprs_commutative (const_tree t1
,
6955 const_tree t2
, hashval_t val
)
6957 hashval_t one
= iterative_hash_expr (t1
, 0);
6958 hashval_t two
= iterative_hash_expr (t2
, 0);
6962 t
= one
, one
= two
, two
= t
;
6963 val
= iterative_hash_hashval_t (one
, val
);
6964 val
= iterative_hash_hashval_t (two
, val
);
6969 /* Constructors for pointer, array and function types.
6970 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
6971 constructed by language-dependent code, not here.) */
6973 /* Construct, lay out and return the type of pointers to TO_TYPE with
6974 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
6975 reference all of memory. If such a type has already been
6976 constructed, reuse it. */
6979 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
6984 if (to_type
== error_mark_node
)
6985 return error_mark_node
;
6987 /* If the pointed-to type has the may_alias attribute set, force
6988 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
6989 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
6990 can_alias_all
= true;
6992 /* In some cases, languages will have things that aren't a POINTER_TYPE
6993 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
6994 In that case, return that type without regard to the rest of our
6997 ??? This is a kludge, but consistent with the way this function has
6998 always operated and there doesn't seem to be a good way to avoid this
7000 if (TYPE_POINTER_TO (to_type
) != 0
7001 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7002 return TYPE_POINTER_TO (to_type
);
7004 /* First, if we already have a type for pointers to TO_TYPE and it's
7005 the proper mode, use it. */
7006 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7007 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7010 t
= make_node (POINTER_TYPE
);
7012 TREE_TYPE (t
) = to_type
;
7013 SET_TYPE_MODE (t
, mode
);
7014 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7015 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7016 TYPE_POINTER_TO (to_type
) = t
;
7018 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7019 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7020 else if (TYPE_CANONICAL (to_type
) != to_type
)
7022 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7023 mode
, can_alias_all
);
7025 /* Lay out the type. This function has many callers that are concerned
7026 with expression-construction, and this simplifies them all. */
7032 /* By default build pointers in ptr_mode. */
7035 build_pointer_type (tree to_type
)
7037 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7038 : TYPE_ADDR_SPACE (to_type
);
7039 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7040 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7043 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7046 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
7051 if (to_type
== error_mark_node
)
7052 return error_mark_node
;
7054 /* If the pointed-to type has the may_alias attribute set, force
7055 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7056 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7057 can_alias_all
= true;
7059 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7060 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7061 In that case, return that type without regard to the rest of our
7064 ??? This is a kludge, but consistent with the way this function has
7065 always operated and there doesn't seem to be a good way to avoid this
7067 if (TYPE_REFERENCE_TO (to_type
) != 0
7068 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7069 return TYPE_REFERENCE_TO (to_type
);
7071 /* First, if we already have a type for pointers to TO_TYPE and it's
7072 the proper mode, use it. */
7073 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7074 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7077 t
= make_node (REFERENCE_TYPE
);
7079 TREE_TYPE (t
) = to_type
;
7080 SET_TYPE_MODE (t
, mode
);
7081 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7082 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7083 TYPE_REFERENCE_TO (to_type
) = t
;
7085 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7086 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7087 else if (TYPE_CANONICAL (to_type
) != to_type
)
7089 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7090 mode
, can_alias_all
);
7098 /* Build the node for the type of references-to-TO_TYPE by default
7102 build_reference_type (tree to_type
)
7104 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7105 : TYPE_ADDR_SPACE (to_type
);
7106 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7107 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7110 /* Build a type that is compatible with t but has no cv quals anywhere
7113 const char *const *const * -> char ***. */
7116 build_type_no_quals (tree t
)
7118 switch (TREE_CODE (t
))
7121 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7123 TYPE_REF_CAN_ALIAS_ALL (t
));
7124 case REFERENCE_TYPE
:
7126 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7128 TYPE_REF_CAN_ALIAS_ALL (t
));
7130 return TYPE_MAIN_VARIANT (t
);
7134 #define MAX_INT_CACHED_PREC \
7135 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7136 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7138 /* Builds a signed or unsigned integer type of precision PRECISION.
7139 Used for C bitfields whose precision does not match that of
7140 built-in target types. */
7142 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7148 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7150 if (precision
<= MAX_INT_CACHED_PREC
)
7152 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7157 itype
= make_node (INTEGER_TYPE
);
7158 TYPE_PRECISION (itype
) = precision
;
7161 fixup_unsigned_type (itype
);
7163 fixup_signed_type (itype
);
7166 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
7167 ret
= type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
7168 if (precision
<= MAX_INT_CACHED_PREC
)
7169 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7174 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7175 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7176 is true, reuse such a type that has already been constructed. */
7179 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7181 tree itype
= make_node (INTEGER_TYPE
);
7182 hashval_t hashcode
= 0;
7184 TREE_TYPE (itype
) = type
;
7186 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7187 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7189 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7190 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7191 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7192 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7193 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
7194 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7199 if ((TYPE_MIN_VALUE (itype
)
7200 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7201 || (TYPE_MAX_VALUE (itype
)
7202 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7204 /* Since we cannot reliably merge this type, we need to compare it using
7205 structural equality checks. */
7206 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7210 hashcode
= iterative_hash_expr (TYPE_MIN_VALUE (itype
), hashcode
);
7211 hashcode
= iterative_hash_expr (TYPE_MAX_VALUE (itype
), hashcode
);
7212 hashcode
= iterative_hash_hashval_t (TYPE_HASH (type
), hashcode
);
7213 itype
= type_hash_canon (hashcode
, itype
);
7218 /* Wrapper around build_range_type_1 with SHARED set to true. */
7221 build_range_type (tree type
, tree lowval
, tree highval
)
7223 return build_range_type_1 (type
, lowval
, highval
, true);
7226 /* Wrapper around build_range_type_1 with SHARED set to false. */
7229 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7231 return build_range_type_1 (type
, lowval
, highval
, false);
7234 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7235 MAXVAL should be the maximum value in the domain
7236 (one less than the length of the array).
7238 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7239 We don't enforce this limit, that is up to caller (e.g. language front end).
7240 The limit exists because the result is a signed type and we don't handle
7241 sizes that use more than one HOST_WIDE_INT. */
7244 build_index_type (tree maxval
)
7246 return build_range_type (sizetype
, size_zero_node
, maxval
);
7249 /* Return true if the debug information for TYPE, a subtype, should be emitted
7250 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7251 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7252 debug info and doesn't reflect the source code. */
7255 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7257 tree base_type
= TREE_TYPE (type
), low
, high
;
7259 /* Subrange types have a base type which is an integral type. */
7260 if (!INTEGRAL_TYPE_P (base_type
))
7263 /* Get the real bounds of the subtype. */
7264 if (lang_hooks
.types
.get_subrange_bounds
)
7265 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7268 low
= TYPE_MIN_VALUE (type
);
7269 high
= TYPE_MAX_VALUE (type
);
7272 /* If the type and its base type have the same representation and the same
7273 name, then the type is not a subrange but a copy of the base type. */
7274 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7275 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7276 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7277 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7278 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
7280 tree type_name
= TYPE_NAME (type
);
7281 tree base_type_name
= TYPE_NAME (base_type
);
7283 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
7284 type_name
= DECL_NAME (type_name
);
7286 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
7287 base_type_name
= DECL_NAME (base_type_name
);
7289 if (type_name
== base_type_name
)
7300 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7301 and number of elements specified by the range of values of INDEX_TYPE.
7302 If SHARED is true, reuse such a type that has already been constructed. */
7305 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
7309 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7311 error ("arrays of functions are not meaningful");
7312 elt_type
= integer_type_node
;
7315 t
= make_node (ARRAY_TYPE
);
7316 TREE_TYPE (t
) = elt_type
;
7317 TYPE_DOMAIN (t
) = index_type
;
7318 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7321 /* If the element type is incomplete at this point we get marked for
7322 structural equality. Do not record these types in the canonical
7324 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
7329 hashval_t hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), 0);
7331 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
7332 t
= type_hash_canon (hashcode
, t
);
7335 if (TYPE_CANONICAL (t
) == t
)
7337 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7338 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
7339 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7340 else if (TYPE_CANONICAL (elt_type
) != elt_type
7341 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7343 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7345 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7352 /* Wrapper around build_array_type_1 with SHARED set to true. */
7355 build_array_type (tree elt_type
, tree index_type
)
7357 return build_array_type_1 (elt_type
, index_type
, true);
7360 /* Wrapper around build_array_type_1 with SHARED set to false. */
7363 build_nonshared_array_type (tree elt_type
, tree index_type
)
7365 return build_array_type_1 (elt_type
, index_type
, false);
7368 /* Recursively examines the array elements of TYPE, until a non-array
7369 element type is found. */
7372 strip_array_types (tree type
)
7374 while (TREE_CODE (type
) == ARRAY_TYPE
)
7375 type
= TREE_TYPE (type
);
7380 /* Computes the canonical argument types from the argument type list
7383 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7384 on entry to this function, or if any of the ARGTYPES are
7387 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7388 true on entry to this function, or if any of the ARGTYPES are
7391 Returns a canonical argument list, which may be ARGTYPES when the
7392 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7393 true) or would not differ from ARGTYPES. */
7396 maybe_canonicalize_argtypes(tree argtypes
,
7397 bool *any_structural_p
,
7398 bool *any_noncanonical_p
)
7401 bool any_noncanonical_argtypes_p
= false;
7403 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7405 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7406 /* Fail gracefully by stating that the type is structural. */
7407 *any_structural_p
= true;
7408 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7409 *any_structural_p
= true;
7410 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7411 || TREE_PURPOSE (arg
))
7412 /* If the argument has a default argument, we consider it
7413 non-canonical even though the type itself is canonical.
7414 That way, different variants of function and method types
7415 with default arguments will all point to the variant with
7416 no defaults as their canonical type. */
7417 any_noncanonical_argtypes_p
= true;
7420 if (*any_structural_p
)
7423 if (any_noncanonical_argtypes_p
)
7425 /* Build the canonical list of argument types. */
7426 tree canon_argtypes
= NULL_TREE
;
7427 bool is_void
= false;
7429 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7431 if (arg
== void_list_node
)
7434 canon_argtypes
= tree_cons (NULL_TREE
,
7435 TYPE_CANONICAL (TREE_VALUE (arg
)),
7439 canon_argtypes
= nreverse (canon_argtypes
);
7441 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7443 /* There is a non-canonical type. */
7444 *any_noncanonical_p
= true;
7445 return canon_argtypes
;
7448 /* The canonical argument types are the same as ARGTYPES. */
7452 /* Construct, lay out and return
7453 the type of functions returning type VALUE_TYPE
7454 given arguments of types ARG_TYPES.
7455 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7456 are data type nodes for the arguments of the function.
7457 If such a type has already been constructed, reuse it. */
7460 build_function_type (tree value_type
, tree arg_types
)
7463 hashval_t hashcode
= 0;
7464 bool any_structural_p
, any_noncanonical_p
;
7465 tree canon_argtypes
;
7467 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
7469 error ("function return type cannot be function");
7470 value_type
= integer_type_node
;
7473 /* Make a node of the sort we want. */
7474 t
= make_node (FUNCTION_TYPE
);
7475 TREE_TYPE (t
) = value_type
;
7476 TYPE_ARG_TYPES (t
) = arg_types
;
7478 /* If we already have such a type, use the old one. */
7479 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
7480 hashcode
= type_hash_list (arg_types
, hashcode
);
7481 t
= type_hash_canon (hashcode
, t
);
7483 /* Set up the canonical type. */
7484 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
7485 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
7486 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
7488 &any_noncanonical_p
);
7489 if (any_structural_p
)
7490 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7491 else if (any_noncanonical_p
)
7492 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
7495 if (!COMPLETE_TYPE_P (t
))
7500 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
7503 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
)
7505 tree new_type
= NULL
;
7506 tree args
, new_args
= NULL
, t
;
7510 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
7511 args
= TREE_CHAIN (args
), i
++)
7512 if (!bitmap_bit_p (args_to_skip
, i
))
7513 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
7515 new_reversed
= nreverse (new_args
);
7519 TREE_CHAIN (new_args
) = void_list_node
;
7521 new_reversed
= void_list_node
;
7524 /* Use copy_node to preserve as much as possible from original type
7525 (debug info, attribute lists etc.)
7526 Exception is METHOD_TYPEs must have THIS argument.
7527 When we are asked to remove it, we need to build new FUNCTION_TYPE
7529 if (TREE_CODE (orig_type
) != METHOD_TYPE
7530 || !bitmap_bit_p (args_to_skip
, 0))
7532 new_type
= build_distinct_type_copy (orig_type
);
7533 TYPE_ARG_TYPES (new_type
) = new_reversed
;
7538 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
7540 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
7543 /* This is a new type, not a copy of an old type. Need to reassociate
7544 variants. We can handle everything except the main variant lazily. */
7545 t
= TYPE_MAIN_VARIANT (orig_type
);
7548 TYPE_MAIN_VARIANT (new_type
) = t
;
7549 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
7550 TYPE_NEXT_VARIANT (t
) = new_type
;
7554 TYPE_MAIN_VARIANT (new_type
) = new_type
;
7555 TYPE_NEXT_VARIANT (new_type
) = NULL
;
7560 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
7562 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
7563 linked by TREE_CHAIN directly. The caller is responsible for eliminating
7564 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
7567 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
)
7569 tree new_decl
= copy_node (orig_decl
);
7572 new_type
= TREE_TYPE (orig_decl
);
7573 if (prototype_p (new_type
))
7574 new_type
= build_function_type_skip_args (new_type
, args_to_skip
);
7575 TREE_TYPE (new_decl
) = new_type
;
7577 /* For declarations setting DECL_VINDEX (i.e. methods)
7578 we expect first argument to be THIS pointer. */
7579 if (bitmap_bit_p (args_to_skip
, 0))
7580 DECL_VINDEX (new_decl
) = NULL_TREE
;
7582 /* When signature changes, we need to clear builtin info. */
7583 if (DECL_BUILT_IN (new_decl
) && !bitmap_empty_p (args_to_skip
))
7585 DECL_BUILT_IN_CLASS (new_decl
) = NOT_BUILT_IN
;
7586 DECL_FUNCTION_CODE (new_decl
) = (enum built_in_function
) 0;
7591 /* Build a function type. The RETURN_TYPE is the type returned by the
7592 function. If VAARGS is set, no void_type_node is appended to the
7593 the list. ARGP must be always be terminated be a NULL_TREE. */
7596 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
7600 t
= va_arg (argp
, tree
);
7601 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
7602 args
= tree_cons (NULL_TREE
, t
, args
);
7607 if (args
!= NULL_TREE
)
7608 args
= nreverse (args
);
7609 gcc_assert (last
!= void_list_node
);
7611 else if (args
== NULL_TREE
)
7612 args
= void_list_node
;
7616 args
= nreverse (args
);
7617 TREE_CHAIN (last
) = void_list_node
;
7619 args
= build_function_type (return_type
, args
);
7624 /* Build a function type. The RETURN_TYPE is the type returned by the
7625 function. If additional arguments are provided, they are
7626 additional argument types. The list of argument types must always
7627 be terminated by NULL_TREE. */
7630 build_function_type_list (tree return_type
, ...)
7635 va_start (p
, return_type
);
7636 args
= build_function_type_list_1 (false, return_type
, p
);
7641 /* Build a variable argument function type. The RETURN_TYPE is the
7642 type returned by the function. If additional arguments are provided,
7643 they are additional argument types. The list of argument types must
7644 always be terminated by NULL_TREE. */
7647 build_varargs_function_type_list (tree return_type
, ...)
7652 va_start (p
, return_type
);
7653 args
= build_function_type_list_1 (true, return_type
, p
);
7659 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7660 and ARGTYPES (a TREE_LIST) are the return type and arguments types
7661 for the method. An implicit additional parameter (of type
7662 pointer-to-BASETYPE) is added to the ARGTYPES. */
7665 build_method_type_directly (tree basetype
,
7672 bool any_structural_p
, any_noncanonical_p
;
7673 tree canon_argtypes
;
7675 /* Make a node of the sort we want. */
7676 t
= make_node (METHOD_TYPE
);
7678 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7679 TREE_TYPE (t
) = rettype
;
7680 ptype
= build_pointer_type (basetype
);
7682 /* The actual arglist for this function includes a "hidden" argument
7683 which is "this". Put it into the list of argument types. */
7684 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
7685 TYPE_ARG_TYPES (t
) = argtypes
;
7687 /* If we already have such a type, use the old one. */
7688 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
7689 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
7690 hashcode
= type_hash_list (argtypes
, hashcode
);
7691 t
= type_hash_canon (hashcode
, t
);
7693 /* Set up the canonical type. */
7695 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7696 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
7698 = (TYPE_CANONICAL (basetype
) != basetype
7699 || TYPE_CANONICAL (rettype
) != rettype
);
7700 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
7702 &any_noncanonical_p
);
7703 if (any_structural_p
)
7704 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7705 else if (any_noncanonical_p
)
7707 = build_method_type_directly (TYPE_CANONICAL (basetype
),
7708 TYPE_CANONICAL (rettype
),
7710 if (!COMPLETE_TYPE_P (t
))
7716 /* Construct, lay out and return the type of methods belonging to class
7717 BASETYPE and whose arguments and values are described by TYPE.
7718 If that type exists already, reuse it.
7719 TYPE must be a FUNCTION_TYPE node. */
7722 build_method_type (tree basetype
, tree type
)
7724 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
7726 return build_method_type_directly (basetype
,
7728 TYPE_ARG_TYPES (type
));
7731 /* Construct, lay out and return the type of offsets to a value
7732 of type TYPE, within an object of type BASETYPE.
7733 If a suitable offset type exists already, reuse it. */
7736 build_offset_type (tree basetype
, tree type
)
7739 hashval_t hashcode
= 0;
7741 /* Make a node of the sort we want. */
7742 t
= make_node (OFFSET_TYPE
);
7744 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7745 TREE_TYPE (t
) = type
;
7747 /* If we already have such a type, use the old one. */
7748 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
7749 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
7750 t
= type_hash_canon (hashcode
, t
);
7752 if (!COMPLETE_TYPE_P (t
))
7755 if (TYPE_CANONICAL (t
) == t
)
7757 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7758 || TYPE_STRUCTURAL_EQUALITY_P (type
))
7759 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7760 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
7761 || TYPE_CANONICAL (type
) != type
)
7763 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
7764 TYPE_CANONICAL (type
));
7770 /* Create a complex type whose components are COMPONENT_TYPE. */
7773 build_complex_type (tree component_type
)
7778 gcc_assert (INTEGRAL_TYPE_P (component_type
)
7779 || SCALAR_FLOAT_TYPE_P (component_type
)
7780 || FIXED_POINT_TYPE_P (component_type
));
7782 /* Make a node of the sort we want. */
7783 t
= make_node (COMPLEX_TYPE
);
7785 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
7787 /* If we already have such a type, use the old one. */
7788 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
7789 t
= type_hash_canon (hashcode
, t
);
7791 if (!COMPLETE_TYPE_P (t
))
7794 if (TYPE_CANONICAL (t
) == t
)
7796 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
7797 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7798 else if (TYPE_CANONICAL (component_type
) != component_type
)
7800 = build_complex_type (TYPE_CANONICAL (component_type
));
7803 /* We need to create a name, since complex is a fundamental type. */
7804 if (! TYPE_NAME (t
))
7807 if (component_type
== char_type_node
)
7808 name
= "complex char";
7809 else if (component_type
== signed_char_type_node
)
7810 name
= "complex signed char";
7811 else if (component_type
== unsigned_char_type_node
)
7812 name
= "complex unsigned char";
7813 else if (component_type
== short_integer_type_node
)
7814 name
= "complex short int";
7815 else if (component_type
== short_unsigned_type_node
)
7816 name
= "complex short unsigned int";
7817 else if (component_type
== integer_type_node
)
7818 name
= "complex int";
7819 else if (component_type
== unsigned_type_node
)
7820 name
= "complex unsigned int";
7821 else if (component_type
== long_integer_type_node
)
7822 name
= "complex long int";
7823 else if (component_type
== long_unsigned_type_node
)
7824 name
= "complex long unsigned int";
7825 else if (component_type
== long_long_integer_type_node
)
7826 name
= "complex long long int";
7827 else if (component_type
== long_long_unsigned_type_node
)
7828 name
= "complex long long unsigned int";
7833 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
7834 get_identifier (name
), t
);
7837 return build_qualified_type (t
, TYPE_QUALS (component_type
));
7840 /* If TYPE is a real or complex floating-point type and the target
7841 does not directly support arithmetic on TYPE then return the wider
7842 type to be used for arithmetic on TYPE. Otherwise, return
7846 excess_precision_type (tree type
)
7848 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
7850 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
7851 switch (TREE_CODE (type
))
7854 switch (flt_eval_method
)
7857 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
7858 return double_type_node
;
7861 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
7862 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
7863 return long_double_type_node
;
7870 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
7872 switch (flt_eval_method
)
7875 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
7876 return complex_double_type_node
;
7879 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
7880 || (TYPE_MODE (TREE_TYPE (type
))
7881 == TYPE_MODE (double_type_node
)))
7882 return complex_long_double_type_node
;
7895 /* Return OP, stripped of any conversions to wider types as much as is safe.
7896 Converting the value back to OP's type makes a value equivalent to OP.
7898 If FOR_TYPE is nonzero, we return a value which, if converted to
7899 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
7901 OP must have integer, real or enumeral type. Pointers are not allowed!
7903 There are some cases where the obvious value we could return
7904 would regenerate to OP if converted to OP's type,
7905 but would not extend like OP to wider types.
7906 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
7907 For example, if OP is (unsigned short)(signed char)-1,
7908 we avoid returning (signed char)-1 if FOR_TYPE is int,
7909 even though extending that to an unsigned short would regenerate OP,
7910 since the result of extending (signed char)-1 to (int)
7911 is different from (int) OP. */
7914 get_unwidened (tree op
, tree for_type
)
7916 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
7917 tree type
= TREE_TYPE (op
);
7919 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
7921 = (for_type
!= 0 && for_type
!= type
7922 && final_prec
> TYPE_PRECISION (type
)
7923 && TYPE_UNSIGNED (type
));
7926 while (CONVERT_EXPR_P (op
))
7930 /* TYPE_PRECISION on vector types has different meaning
7931 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
7932 so avoid them here. */
7933 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
7936 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
7937 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
7939 /* Truncations are many-one so cannot be removed.
7940 Unless we are later going to truncate down even farther. */
7942 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
7945 /* See what's inside this conversion. If we decide to strip it,
7947 op
= TREE_OPERAND (op
, 0);
7949 /* If we have not stripped any zero-extensions (uns is 0),
7950 we can strip any kind of extension.
7951 If we have previously stripped a zero-extension,
7952 only zero-extensions can safely be stripped.
7953 Any extension can be stripped if the bits it would produce
7954 are all going to be discarded later by truncating to FOR_TYPE. */
7958 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
7960 /* TYPE_UNSIGNED says whether this is a zero-extension.
7961 Let's avoid computing it if it does not affect WIN
7962 and if UNS will not be needed again. */
7964 || CONVERT_EXPR_P (op
))
7965 && TYPE_UNSIGNED (TREE_TYPE (op
)))
7973 /* If we finally reach a constant see if it fits in for_type and
7974 in that case convert it. */
7976 && TREE_CODE (win
) == INTEGER_CST
7977 && TREE_TYPE (win
) != for_type
7978 && int_fits_type_p (win
, for_type
))
7979 win
= fold_convert (for_type
, win
);
7984 /* Return OP or a simpler expression for a narrower value
7985 which can be sign-extended or zero-extended to give back OP.
7986 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
7987 or 0 if the value should be sign-extended. */
7990 get_narrower (tree op
, int *unsignedp_ptr
)
7995 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
7997 while (TREE_CODE (op
) == NOP_EXPR
)
8000 = (TYPE_PRECISION (TREE_TYPE (op
))
8001 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8003 /* Truncations are many-one so cannot be removed. */
8007 /* See what's inside this conversion. If we decide to strip it,
8012 op
= TREE_OPERAND (op
, 0);
8013 /* An extension: the outermost one can be stripped,
8014 but remember whether it is zero or sign extension. */
8016 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8017 /* Otherwise, if a sign extension has been stripped,
8018 only sign extensions can now be stripped;
8019 if a zero extension has been stripped, only zero-extensions. */
8020 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8024 else /* bitschange == 0 */
8026 /* A change in nominal type can always be stripped, but we must
8027 preserve the unsignedness. */
8029 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8031 op
= TREE_OPERAND (op
, 0);
8032 /* Keep trying to narrow, but don't assign op to win if it
8033 would turn an integral type into something else. */
8034 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8041 if (TREE_CODE (op
) == COMPONENT_REF
8042 /* Since type_for_size always gives an integer type. */
8043 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8044 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8045 /* Ensure field is laid out already. */
8046 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8047 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
8049 unsigned HOST_WIDE_INT innerprec
8050 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
8051 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8052 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8053 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8055 /* We can get this structure field in a narrower type that fits it,
8056 but the resulting extension to its nominal type (a fullword type)
8057 must satisfy the same conditions as for other extensions.
8059 Do this only for fields that are aligned (not bit-fields),
8060 because when bit-field insns will be used there is no
8061 advantage in doing this. */
8063 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8064 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8065 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8069 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8070 win
= fold_convert (type
, op
);
8074 *unsignedp_ptr
= uns
;
8078 /* Returns true if integer constant C has a value that is permissible
8079 for type TYPE (an INTEGER_TYPE). */
8082 int_fits_type_p (const_tree c
, const_tree type
)
8084 tree type_low_bound
, type_high_bound
;
8085 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
8088 dc
= tree_to_double_int (c
);
8089 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
8091 if (TREE_CODE (TREE_TYPE (c
)) == INTEGER_TYPE
8092 && TYPE_IS_SIZETYPE (TREE_TYPE (c
))
8094 /* So c is an unsigned integer whose type is sizetype and type is not.
8095 sizetype'd integers are sign extended even though they are
8096 unsigned. If the integer value fits in the lower end word of c,
8097 and if the higher end word has all its bits set to 1, that
8098 means the higher end bits are set to 1 only for sign extension.
8099 So let's convert c into an equivalent zero extended unsigned
8101 dc
= double_int_zext (dc
, TYPE_PRECISION (TREE_TYPE (c
)));
8104 type_low_bound
= TYPE_MIN_VALUE (type
);
8105 type_high_bound
= TYPE_MAX_VALUE (type
);
8107 /* If at least one bound of the type is a constant integer, we can check
8108 ourselves and maybe make a decision. If no such decision is possible, but
8109 this type is a subtype, try checking against that. Otherwise, use
8110 double_int_fits_to_tree_p, which checks against the precision.
8112 Compute the status for each possibly constant bound, and return if we see
8113 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8114 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8115 for "constant known to fit". */
8117 /* Check if c >= type_low_bound. */
8118 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8120 dd
= tree_to_double_int (type_low_bound
);
8121 if (TREE_CODE (type
) == INTEGER_TYPE
8122 && TYPE_IS_SIZETYPE (type
)
8123 && TYPE_UNSIGNED (type
))
8124 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
8125 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
8127 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
8128 int t_neg
= (unsc
&& double_int_negative_p (dd
));
8130 if (c_neg
&& !t_neg
)
8132 if ((c_neg
|| !t_neg
) && double_int_ucmp (dc
, dd
) < 0)
8135 else if (double_int_cmp (dc
, dd
, unsc
) < 0)
8137 ok_for_low_bound
= true;
8140 ok_for_low_bound
= false;
8142 /* Check if c <= type_high_bound. */
8143 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8145 dd
= tree_to_double_int (type_high_bound
);
8146 if (TREE_CODE (type
) == INTEGER_TYPE
8147 && TYPE_IS_SIZETYPE (type
)
8148 && TYPE_UNSIGNED (type
))
8149 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
8150 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
8152 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
8153 int t_neg
= (unsc
&& double_int_negative_p (dd
));
8155 if (t_neg
&& !c_neg
)
8157 if ((t_neg
|| !c_neg
) && double_int_ucmp (dc
, dd
) > 0)
8160 else if (double_int_cmp (dc
, dd
, unsc
) > 0)
8162 ok_for_high_bound
= true;
8165 ok_for_high_bound
= false;
8167 /* If the constant fits both bounds, the result is known. */
8168 if (ok_for_low_bound
&& ok_for_high_bound
)
8171 /* Perform some generic filtering which may allow making a decision
8172 even if the bounds are not constant. First, negative integers
8173 never fit in unsigned types, */
8174 if (TYPE_UNSIGNED (type
) && !unsc
&& double_int_negative_p (dc
))
8177 /* Second, narrower types always fit in wider ones. */
8178 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8181 /* Third, unsigned integers with top bit set never fit signed types. */
8182 if (! TYPE_UNSIGNED (type
) && unsc
)
8184 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
8185 if (prec
< HOST_BITS_PER_WIDE_INT
)
8187 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
8190 else if (((((unsigned HOST_WIDE_INT
) 1)
8191 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
8195 /* If we haven't been able to decide at this point, there nothing more we
8196 can check ourselves here. Look at the base type if we have one and it
8197 has the same precision. */
8198 if (TREE_CODE (type
) == INTEGER_TYPE
8199 && TREE_TYPE (type
) != 0
8200 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8202 type
= TREE_TYPE (type
);
8206 /* Or to double_int_fits_to_tree_p, if nothing else. */
8207 return double_int_fits_to_tree_p (type
, dc
);
8210 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8211 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8212 represented (assuming two's-complement arithmetic) within the bit
8213 precision of the type are returned instead. */
8216 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8218 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8219 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8220 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
8221 TYPE_UNSIGNED (type
));
8224 if (TYPE_UNSIGNED (type
))
8225 mpz_set_ui (min
, 0);
8229 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
8230 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
8231 TYPE_PRECISION (type
));
8232 mpz_set_double_int (min
, mn
, false);
8236 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8237 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8238 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
8239 TYPE_UNSIGNED (type
));
8242 if (TYPE_UNSIGNED (type
))
8243 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
8246 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
8251 /* Return true if VAR is an automatic variable defined in function FN. */
8254 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8256 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8257 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8258 || TREE_CODE (var
) == PARM_DECL
)
8259 && ! TREE_STATIC (var
))
8260 || TREE_CODE (var
) == LABEL_DECL
8261 || TREE_CODE (var
) == RESULT_DECL
));
8264 /* Subprogram of following function. Called by walk_tree.
8266 Return *TP if it is an automatic variable or parameter of the
8267 function passed in as DATA. */
8270 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8272 tree fn
= (tree
) data
;
8277 else if (DECL_P (*tp
)
8278 && auto_var_in_fn_p (*tp
, fn
))
8284 /* Returns true if T is, contains, or refers to a type with variable
8285 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8286 arguments, but not the return type. If FN is nonzero, only return
8287 true if a modifier of the type or position of FN is a variable or
8288 parameter inside FN.
8290 This concept is more general than that of C99 'variably modified types':
8291 in C99, a struct type is never variably modified because a VLA may not
8292 appear as a structure member. However, in GNU C code like:
8294 struct S { int i[f()]; };
8296 is valid, and other languages may define similar constructs. */
8299 variably_modified_type_p (tree type
, tree fn
)
8303 /* Test if T is either variable (if FN is zero) or an expression containing
8304 a variable in FN. */
8305 #define RETURN_TRUE_IF_VAR(T) \
8306 do { tree _t = (T); \
8307 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
8308 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8309 return true; } while (0)
8311 if (type
== error_mark_node
)
8314 /* If TYPE itself has variable size, it is variably modified. */
8315 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8316 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8318 switch (TREE_CODE (type
))
8321 case REFERENCE_TYPE
:
8323 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8329 /* If TYPE is a function type, it is variably modified if the
8330 return type is variably modified. */
8331 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8337 case FIXED_POINT_TYPE
:
8340 /* Scalar types are variably modified if their end points
8342 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8343 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8348 case QUAL_UNION_TYPE
:
8349 /* We can't see if any of the fields are variably-modified by the
8350 definition we normally use, since that would produce infinite
8351 recursion via pointers. */
8352 /* This is variably modified if some field's type is. */
8353 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8354 if (TREE_CODE (t
) == FIELD_DECL
)
8356 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8357 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8358 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8360 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8361 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8366 /* Do not call ourselves to avoid infinite recursion. This is
8367 variably modified if the element type is. */
8368 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8369 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8376 /* The current language may have other cases to check, but in general,
8377 all other types are not variably modified. */
8378 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8380 #undef RETURN_TRUE_IF_VAR
8383 /* Given a DECL or TYPE, return the scope in which it was declared, or
8384 NULL_TREE if there is no containing scope. */
8387 get_containing_scope (const_tree t
)
8389 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8392 /* Return the innermost context enclosing DECL that is
8393 a FUNCTION_DECL, or zero if none. */
8396 decl_function_context (const_tree decl
)
8400 if (TREE_CODE (decl
) == ERROR_MARK
)
8403 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8404 where we look up the function at runtime. Such functions always take
8405 a first argument of type 'pointer to real context'.
8407 C++ should really be fixed to use DECL_CONTEXT for the real context,
8408 and use something else for the "virtual context". */
8409 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
8412 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8414 context
= DECL_CONTEXT (decl
);
8416 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8418 if (TREE_CODE (context
) == BLOCK
)
8419 context
= BLOCK_SUPERCONTEXT (context
);
8421 context
= get_containing_scope (context
);
8427 /* Return the innermost context enclosing DECL that is
8428 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8429 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8432 decl_type_context (const_tree decl
)
8434 tree context
= DECL_CONTEXT (decl
);
8437 switch (TREE_CODE (context
))
8439 case NAMESPACE_DECL
:
8440 case TRANSLATION_UNIT_DECL
:
8445 case QUAL_UNION_TYPE
:
8450 context
= DECL_CONTEXT (context
);
8454 context
= BLOCK_SUPERCONTEXT (context
);
8464 /* CALL is a CALL_EXPR. Return the declaration for the function
8465 called, or NULL_TREE if the called function cannot be
8469 get_callee_fndecl (const_tree call
)
8473 if (call
== error_mark_node
)
8474 return error_mark_node
;
8476 /* It's invalid to call this function with anything but a
8478 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8480 /* The first operand to the CALL is the address of the function
8482 addr
= CALL_EXPR_FN (call
);
8486 /* If this is a readonly function pointer, extract its initial value. */
8487 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
8488 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
8489 && DECL_INITIAL (addr
))
8490 addr
= DECL_INITIAL (addr
);
8492 /* If the address is just `&f' for some function `f', then we know
8493 that `f' is being called. */
8494 if (TREE_CODE (addr
) == ADDR_EXPR
8495 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
8496 return TREE_OPERAND (addr
, 0);
8498 /* We couldn't figure out what was being called. */
8502 /* Print debugging information about tree nodes generated during the compile,
8503 and any language-specific information. */
8506 dump_tree_statistics (void)
8508 #ifdef GATHER_STATISTICS
8510 int total_nodes
, total_bytes
;
8513 fprintf (stderr
, "\n??? tree nodes created\n\n");
8514 #ifdef GATHER_STATISTICS
8515 fprintf (stderr
, "Kind Nodes Bytes\n");
8516 fprintf (stderr
, "---------------------------------------\n");
8517 total_nodes
= total_bytes
= 0;
8518 for (i
= 0; i
< (int) all_kinds
; i
++)
8520 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
8521 tree_node_counts
[i
], tree_node_sizes
[i
]);
8522 total_nodes
+= tree_node_counts
[i
];
8523 total_bytes
+= tree_node_sizes
[i
];
8525 fprintf (stderr
, "---------------------------------------\n");
8526 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
8527 fprintf (stderr
, "---------------------------------------\n");
8528 ssanames_print_statistics ();
8529 phinodes_print_statistics ();
8531 fprintf (stderr
, "(No per-node statistics)\n");
8533 print_type_hash_statistics ();
8534 print_debug_expr_statistics ();
8535 print_value_expr_statistics ();
8536 lang_hooks
.print_statistics ();
8539 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8541 /* Generate a crc32 of a string. */
8544 crc32_string (unsigned chksum
, const char *string
)
8548 unsigned value
= *string
<< 24;
8551 for (ix
= 8; ix
--; value
<<= 1)
8555 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
8564 /* P is a string that will be used in a symbol. Mask out any characters
8565 that are not valid in that context. */
8568 clean_symbol_name (char *p
)
8572 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8575 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8582 /* Generate a name for a special-purpose function function.
8583 The generated name may need to be unique across the whole link.
8584 TYPE is some string to identify the purpose of this function to the
8585 linker or collect2; it must start with an uppercase letter,
8587 I - for constructors
8589 N - for C++ anonymous namespaces
8590 F - for DWARF unwind frame information. */
8593 get_file_function_name (const char *type
)
8599 /* If we already have a name we know to be unique, just use that. */
8600 if (first_global_object_name
)
8601 p
= q
= ASTRDUP (first_global_object_name
);
8602 /* If the target is handling the constructors/destructors, they
8603 will be local to this file and the name is only necessary for
8605 We also assign sub_I and sub_D sufixes to constructors called from
8606 the global static constructors. These are always local. */
8607 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
8608 || (strncmp (type
, "sub_", 4) == 0
8609 && (type
[4] == 'I' || type
[4] == 'D')))
8611 const char *file
= main_input_filename
;
8613 file
= input_filename
;
8614 /* Just use the file's basename, because the full pathname
8615 might be quite long. */
8616 p
= q
= ASTRDUP (lbasename (file
));
8620 /* Otherwise, the name must be unique across the entire link.
8621 We don't have anything that we know to be unique to this translation
8622 unit, so use what we do have and throw in some randomness. */
8624 const char *name
= weak_global_object_name
;
8625 const char *file
= main_input_filename
;
8630 file
= input_filename
;
8632 len
= strlen (file
);
8633 q
= (char *) alloca (9 * 2 + len
+ 1);
8634 memcpy (q
, file
, len
+ 1);
8636 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
8637 crc32_string (0, get_random_seed (false)));
8642 clean_symbol_name (q
);
8643 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
8646 /* Set up the name of the file-level functions we may need.
8647 Use a global object (which is already required to be unique over
8648 the program) rather than the file name (which imposes extra
8650 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
8652 return get_identifier (buf
);
8655 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
8657 /* Complain that the tree code of NODE does not match the expected 0
8658 terminated list of trailing codes. The trailing code list can be
8659 empty, for a more vague error message. FILE, LINE, and FUNCTION
8660 are of the caller. */
8663 tree_check_failed (const_tree node
, const char *file
,
8664 int line
, const char *function
, ...)
8668 unsigned length
= 0;
8671 va_start (args
, function
);
8672 while ((code
= va_arg (args
, int)))
8673 length
+= 4 + strlen (tree_code_name
[code
]);
8678 va_start (args
, function
);
8679 length
+= strlen ("expected ");
8680 buffer
= tmp
= (char *) alloca (length
);
8682 while ((code
= va_arg (args
, int)))
8684 const char *prefix
= length
? " or " : "expected ";
8686 strcpy (tmp
+ length
, prefix
);
8687 length
+= strlen (prefix
);
8688 strcpy (tmp
+ length
, tree_code_name
[code
]);
8689 length
+= strlen (tree_code_name
[code
]);
8694 buffer
= "unexpected node";
8696 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8697 buffer
, tree_code_name
[TREE_CODE (node
)],
8698 function
, trim_filename (file
), line
);
8701 /* Complain that the tree code of NODE does match the expected 0
8702 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
8706 tree_not_check_failed (const_tree node
, const char *file
,
8707 int line
, const char *function
, ...)
8711 unsigned length
= 0;
8714 va_start (args
, function
);
8715 while ((code
= va_arg (args
, int)))
8716 length
+= 4 + strlen (tree_code_name
[code
]);
8718 va_start (args
, function
);
8719 buffer
= (char *) alloca (length
);
8721 while ((code
= va_arg (args
, int)))
8725 strcpy (buffer
+ length
, " or ");
8728 strcpy (buffer
+ length
, tree_code_name
[code
]);
8729 length
+= strlen (tree_code_name
[code
]);
8733 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
8734 buffer
, tree_code_name
[TREE_CODE (node
)],
8735 function
, trim_filename (file
), line
);
8738 /* Similar to tree_check_failed, except that we check for a class of tree
8739 code, given in CL. */
8742 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8743 const char *file
, int line
, const char *function
)
8746 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
8747 TREE_CODE_CLASS_STRING (cl
),
8748 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8749 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8752 /* Similar to tree_check_failed, except that instead of specifying a
8753 dozen codes, use the knowledge that they're all sequential. */
8756 tree_range_check_failed (const_tree node
, const char *file
, int line
,
8757 const char *function
, enum tree_code c1
,
8761 unsigned length
= 0;
8764 for (c
= c1
; c
<= c2
; ++c
)
8765 length
+= 4 + strlen (tree_code_name
[c
]);
8767 length
+= strlen ("expected ");
8768 buffer
= (char *) alloca (length
);
8771 for (c
= c1
; c
<= c2
; ++c
)
8773 const char *prefix
= length
? " or " : "expected ";
8775 strcpy (buffer
+ length
, prefix
);
8776 length
+= strlen (prefix
);
8777 strcpy (buffer
+ length
, tree_code_name
[c
]);
8778 length
+= strlen (tree_code_name
[c
]);
8781 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8782 buffer
, tree_code_name
[TREE_CODE (node
)],
8783 function
, trim_filename (file
), line
);
8787 /* Similar to tree_check_failed, except that we check that a tree does
8788 not have the specified code, given in CL. */
8791 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8792 const char *file
, int line
, const char *function
)
8795 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
8796 TREE_CODE_CLASS_STRING (cl
),
8797 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8798 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8802 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
8805 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
8806 const char *function
, enum omp_clause_code code
)
8808 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
8809 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
8810 function
, trim_filename (file
), line
);
8814 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
8817 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
8818 const char *function
, enum omp_clause_code c1
,
8819 enum omp_clause_code c2
)
8822 unsigned length
= 0;
8825 for (c
= c1
; c
<= c2
; ++c
)
8826 length
+= 4 + strlen (omp_clause_code_name
[c
]);
8828 length
+= strlen ("expected ");
8829 buffer
= (char *) alloca (length
);
8832 for (c
= c1
; c
<= c2
; ++c
)
8834 const char *prefix
= length
? " or " : "expected ";
8836 strcpy (buffer
+ length
, prefix
);
8837 length
+= strlen (prefix
);
8838 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
8839 length
+= strlen (omp_clause_code_name
[c
]);
8842 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8843 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
8844 function
, trim_filename (file
), line
);
8848 #undef DEFTREESTRUCT
8849 #define DEFTREESTRUCT(VAL, NAME) NAME,
8851 static const char *ts_enum_names
[] = {
8852 #include "treestruct.def"
8854 #undef DEFTREESTRUCT
8856 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
8858 /* Similar to tree_class_check_failed, except that we check for
8859 whether CODE contains the tree structure identified by EN. */
8862 tree_contains_struct_check_failed (const_tree node
,
8863 const enum tree_node_structure_enum en
,
8864 const char *file
, int line
,
8865 const char *function
)
8868 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
8870 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8874 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
8875 (dynamically sized) vector. */
8878 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
8879 const char *function
)
8882 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
8883 idx
+ 1, len
, function
, trim_filename (file
), line
);
8886 /* Similar to above, except that the check is for the bounds of the operand
8887 vector of an expression node EXP. */
8890 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
8891 int line
, const char *function
)
8893 int code
= TREE_CODE (exp
);
8895 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
8896 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
8897 function
, trim_filename (file
), line
);
8900 /* Similar to above, except that the check is for the number of
8901 operands of an OMP_CLAUSE node. */
8904 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
8905 int line
, const char *function
)
8908 ("tree check: accessed operand %d of omp_clause %s with %d operands "
8909 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
8910 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
8911 trim_filename (file
), line
);
8913 #endif /* ENABLE_TREE_CHECKING */
8915 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
8916 and mapped to the machine mode MODE. Initialize its fields and build
8917 the information necessary for debugging output. */
8920 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
8923 hashval_t hashcode
= 0;
8925 t
= make_node (VECTOR_TYPE
);
8926 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
8927 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
8928 SET_TYPE_MODE (t
, mode
);
8930 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
8931 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8932 else if (TYPE_CANONICAL (innertype
) != innertype
8933 || mode
!= VOIDmode
)
8935 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
8939 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
8940 hashcode
= iterative_hash_host_wide_int (nunits
, hashcode
);
8941 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
8942 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (t
)), hashcode
);
8943 t
= type_hash_canon (hashcode
, t
);
8945 /* We have built a main variant, based on the main variant of the
8946 inner type. Use it to build the variant we return. */
8947 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
8948 && TREE_TYPE (t
) != innertype
)
8949 return build_type_attribute_qual_variant (t
,
8950 TYPE_ATTRIBUTES (innertype
),
8951 TYPE_QUALS (innertype
));
8957 make_or_reuse_type (unsigned size
, int unsignedp
)
8959 if (size
== INT_TYPE_SIZE
)
8960 return unsignedp
? unsigned_type_node
: integer_type_node
;
8961 if (size
== CHAR_TYPE_SIZE
)
8962 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
8963 if (size
== SHORT_TYPE_SIZE
)
8964 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
8965 if (size
== LONG_TYPE_SIZE
)
8966 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
8967 if (size
== LONG_LONG_TYPE_SIZE
)
8968 return (unsignedp
? long_long_unsigned_type_node
8969 : long_long_integer_type_node
);
8970 if (size
== 128 && int128_integer_type_node
)
8971 return (unsignedp
? int128_unsigned_type_node
8972 : int128_integer_type_node
);
8975 return make_unsigned_type (size
);
8977 return make_signed_type (size
);
8980 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
8983 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
8987 if (size
== SHORT_FRACT_TYPE_SIZE
)
8988 return unsignedp
? sat_unsigned_short_fract_type_node
8989 : sat_short_fract_type_node
;
8990 if (size
== FRACT_TYPE_SIZE
)
8991 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
8992 if (size
== LONG_FRACT_TYPE_SIZE
)
8993 return unsignedp
? sat_unsigned_long_fract_type_node
8994 : sat_long_fract_type_node
;
8995 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
8996 return unsignedp
? sat_unsigned_long_long_fract_type_node
8997 : sat_long_long_fract_type_node
;
9001 if (size
== SHORT_FRACT_TYPE_SIZE
)
9002 return unsignedp
? unsigned_short_fract_type_node
9003 : short_fract_type_node
;
9004 if (size
== FRACT_TYPE_SIZE
)
9005 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9006 if (size
== LONG_FRACT_TYPE_SIZE
)
9007 return unsignedp
? unsigned_long_fract_type_node
9008 : long_fract_type_node
;
9009 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9010 return unsignedp
? unsigned_long_long_fract_type_node
9011 : long_long_fract_type_node
;
9014 return make_fract_type (size
, unsignedp
, satp
);
9017 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9020 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9024 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9025 return unsignedp
? sat_unsigned_short_accum_type_node
9026 : sat_short_accum_type_node
;
9027 if (size
== ACCUM_TYPE_SIZE
)
9028 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9029 if (size
== LONG_ACCUM_TYPE_SIZE
)
9030 return unsignedp
? sat_unsigned_long_accum_type_node
9031 : sat_long_accum_type_node
;
9032 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9033 return unsignedp
? sat_unsigned_long_long_accum_type_node
9034 : sat_long_long_accum_type_node
;
9038 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9039 return unsignedp
? unsigned_short_accum_type_node
9040 : short_accum_type_node
;
9041 if (size
== ACCUM_TYPE_SIZE
)
9042 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9043 if (size
== LONG_ACCUM_TYPE_SIZE
)
9044 return unsignedp
? unsigned_long_accum_type_node
9045 : long_accum_type_node
;
9046 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9047 return unsignedp
? unsigned_long_long_accum_type_node
9048 : long_long_accum_type_node
;
9051 return make_accum_type (size
, unsignedp
, satp
);
9054 /* Create nodes for all integer types (and error_mark_node) using the sizes
9055 of C datatypes. The caller should call set_sizetype soon after calling
9056 this function to select one of the types as sizetype. */
9059 build_common_tree_nodes (bool signed_char
)
9061 error_mark_node
= make_node (ERROR_MARK
);
9062 TREE_TYPE (error_mark_node
) = error_mark_node
;
9064 initialize_sizetypes ();
9066 /* Define both `signed char' and `unsigned char'. */
9067 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9068 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9069 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9070 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9072 /* Define `char', which is like either `signed char' or `unsigned char'
9073 but not the same as either. */
9076 ? make_signed_type (CHAR_TYPE_SIZE
)
9077 : make_unsigned_type (CHAR_TYPE_SIZE
));
9078 TYPE_STRING_FLAG (char_type_node
) = 1;
9080 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9081 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9082 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9083 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9084 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9085 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9086 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9087 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9088 #if HOST_BITS_PER_WIDE_INT >= 64
9089 /* TODO: This isn't correct, but as logic depends at the moment on
9090 host's instead of target's wide-integer.
9091 If there is a target not supporting TImode, but has an 128-bit
9092 integer-scalar register, this target check needs to be adjusted. */
9093 if (targetm
.scalar_mode_supported_p (TImode
))
9095 int128_integer_type_node
= make_signed_type (128);
9096 int128_unsigned_type_node
= make_unsigned_type (128);
9099 /* Define a boolean type. This type only represents boolean values but
9100 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9101 Front ends which want to override this size (i.e. Java) can redefine
9102 boolean_type_node before calling build_common_tree_nodes_2. */
9103 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9104 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9105 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9106 TYPE_PRECISION (boolean_type_node
) = 1;
9108 /* Fill in the rest of the sized types. Reuse existing type nodes
9110 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9111 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9112 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9113 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9114 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9116 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9117 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9118 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9119 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9120 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9122 access_public_node
= get_identifier ("public");
9123 access_protected_node
= get_identifier ("protected");
9124 access_private_node
= get_identifier ("private");
9127 /* Call this function after calling build_common_tree_nodes and set_sizetype.
9128 It will create several other common tree nodes. */
9131 build_common_tree_nodes_2 (int short_double
)
9133 /* Define these next since types below may used them. */
9134 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9135 integer_one_node
= build_int_cst (integer_type_node
, 1);
9136 integer_three_node
= build_int_cst (integer_type_node
, 3);
9137 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9139 size_zero_node
= size_int (0);
9140 size_one_node
= size_int (1);
9141 bitsize_zero_node
= bitsize_int (0);
9142 bitsize_one_node
= bitsize_int (1);
9143 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9145 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9146 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9148 void_type_node
= make_node (VOID_TYPE
);
9149 layout_type (void_type_node
);
9151 /* We are not going to have real types in C with less than byte alignment,
9152 so we might as well not have any types that claim to have it. */
9153 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
9154 TYPE_USER_ALIGN (void_type_node
) = 0;
9156 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9157 layout_type (TREE_TYPE (null_pointer_node
));
9159 ptr_type_node
= build_pointer_type (void_type_node
);
9161 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9162 fileptr_type_node
= ptr_type_node
;
9164 float_type_node
= make_node (REAL_TYPE
);
9165 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9166 layout_type (float_type_node
);
9168 double_type_node
= make_node (REAL_TYPE
);
9170 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
9172 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9173 layout_type (double_type_node
);
9175 long_double_type_node
= make_node (REAL_TYPE
);
9176 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9177 layout_type (long_double_type_node
);
9179 float_ptr_type_node
= build_pointer_type (float_type_node
);
9180 double_ptr_type_node
= build_pointer_type (double_type_node
);
9181 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9182 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9184 /* Fixed size integer types. */
9185 uint32_type_node
= build_nonstandard_integer_type (32, true);
9186 uint64_type_node
= build_nonstandard_integer_type (64, true);
9188 /* Decimal float types. */
9189 dfloat32_type_node
= make_node (REAL_TYPE
);
9190 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9191 layout_type (dfloat32_type_node
);
9192 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9193 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
9195 dfloat64_type_node
= make_node (REAL_TYPE
);
9196 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9197 layout_type (dfloat64_type_node
);
9198 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9199 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
9201 dfloat128_type_node
= make_node (REAL_TYPE
);
9202 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9203 layout_type (dfloat128_type_node
);
9204 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9205 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
9207 complex_integer_type_node
= build_complex_type (integer_type_node
);
9208 complex_float_type_node
= build_complex_type (float_type_node
);
9209 complex_double_type_node
= build_complex_type (double_type_node
);
9210 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
9212 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9213 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9214 sat_ ## KIND ## _type_node = \
9215 make_sat_signed_ ## KIND ## _type (SIZE); \
9216 sat_unsigned_ ## KIND ## _type_node = \
9217 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9218 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9219 unsigned_ ## KIND ## _type_node = \
9220 make_unsigned_ ## KIND ## _type (SIZE);
9222 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9223 sat_ ## WIDTH ## KIND ## _type_node = \
9224 make_sat_signed_ ## KIND ## _type (SIZE); \
9225 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9226 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9227 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9228 unsigned_ ## WIDTH ## KIND ## _type_node = \
9229 make_unsigned_ ## KIND ## _type (SIZE);
9231 /* Make fixed-point type nodes based on four different widths. */
9232 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9233 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9234 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9235 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9236 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9238 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9239 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9240 NAME ## _type_node = \
9241 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9242 u ## NAME ## _type_node = \
9243 make_or_reuse_unsigned_ ## KIND ## _type \
9244 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9245 sat_ ## NAME ## _type_node = \
9246 make_or_reuse_sat_signed_ ## KIND ## _type \
9247 (GET_MODE_BITSIZE (MODE ## mode)); \
9248 sat_u ## NAME ## _type_node = \
9249 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9250 (GET_MODE_BITSIZE (U ## MODE ## mode));
9252 /* Fixed-point type and mode nodes. */
9253 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9254 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9255 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9256 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9257 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9258 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9259 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9260 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9261 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9262 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9263 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9266 tree t
= targetm
.build_builtin_va_list ();
9268 /* Many back-ends define record types without setting TYPE_NAME.
9269 If we copied the record type here, we'd keep the original
9270 record type without a name. This breaks name mangling. So,
9271 don't copy record types and let c_common_nodes_and_builtins()
9272 declare the type to be __builtin_va_list. */
9273 if (TREE_CODE (t
) != RECORD_TYPE
)
9274 t
= build_variant_type_copy (t
);
9276 va_list_type_node
= t
;
9280 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9283 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9284 const char *library_name
, int ecf_flags
)
9288 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9289 library_name
, NULL_TREE
);
9290 if (ecf_flags
& ECF_CONST
)
9291 TREE_READONLY (decl
) = 1;
9292 if (ecf_flags
& ECF_PURE
)
9293 DECL_PURE_P (decl
) = 1;
9294 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
9295 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9296 if (ecf_flags
& ECF_NORETURN
)
9297 TREE_THIS_VOLATILE (decl
) = 1;
9298 if (ecf_flags
& ECF_NOTHROW
)
9299 TREE_NOTHROW (decl
) = 1;
9300 if (ecf_flags
& ECF_MALLOC
)
9301 DECL_IS_MALLOC (decl
) = 1;
9302 if (ecf_flags
& ECF_LEAF
)
9303 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9304 NULL
, DECL_ATTRIBUTES (decl
));
9306 built_in_decls
[code
] = decl
;
9307 implicit_built_in_decls
[code
] = decl
;
9310 /* Call this function after instantiating all builtins that the language
9311 front end cares about. This will build the rest of the builtins that
9312 are relied upon by the tree optimizers and the middle-end. */
9315 build_common_builtin_nodes (void)
9319 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
9320 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
9322 ftype
= build_function_type_list (ptr_type_node
,
9323 ptr_type_node
, const_ptr_type_node
,
9324 size_type_node
, NULL_TREE
);
9326 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
9327 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9328 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9329 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
9330 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9331 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9334 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
9336 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9337 const_ptr_type_node
, size_type_node
,
9339 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9340 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9343 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
9345 ftype
= build_function_type_list (ptr_type_node
,
9346 ptr_type_node
, integer_type_node
,
9347 size_type_node
, NULL_TREE
);
9348 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9349 "memset", ECF_NOTHROW
| ECF_LEAF
);
9352 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
9354 ftype
= build_function_type_list (ptr_type_node
,
9355 size_type_node
, NULL_TREE
);
9356 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
9357 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9360 /* If we're checking the stack, `alloca' can throw. */
9361 if (flag_stack_check
)
9362 TREE_NOTHROW (built_in_decls
[BUILT_IN_ALLOCA
]) = 0;
9364 ftype
= build_function_type_list (void_type_node
,
9365 ptr_type_node
, ptr_type_node
,
9366 ptr_type_node
, NULL_TREE
);
9367 local_define_builtin ("__builtin_init_trampoline", ftype
,
9368 BUILT_IN_INIT_TRAMPOLINE
,
9369 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
9371 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9372 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
9373 BUILT_IN_ADJUST_TRAMPOLINE
,
9374 "__builtin_adjust_trampoline",
9375 ECF_CONST
| ECF_NOTHROW
);
9377 ftype
= build_function_type_list (void_type_node
,
9378 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9379 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
9380 BUILT_IN_NONLOCAL_GOTO
,
9381 "__builtin_nonlocal_goto",
9382 ECF_NORETURN
| ECF_NOTHROW
);
9384 ftype
= build_function_type_list (void_type_node
,
9385 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9386 local_define_builtin ("__builtin_setjmp_setup", ftype
,
9387 BUILT_IN_SETJMP_SETUP
,
9388 "__builtin_setjmp_setup", ECF_NOTHROW
);
9390 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9391 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
9392 BUILT_IN_SETJMP_DISPATCHER
,
9393 "__builtin_setjmp_dispatcher",
9394 ECF_PURE
| ECF_NOTHROW
);
9396 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9397 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
9398 BUILT_IN_SETJMP_RECEIVER
,
9399 "__builtin_setjmp_receiver", ECF_NOTHROW
);
9401 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
9402 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
9403 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
9405 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9406 local_define_builtin ("__builtin_stack_restore", ftype
,
9407 BUILT_IN_STACK_RESTORE
,
9408 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
9410 /* If there's a possibility that we might use the ARM EABI, build the
9411 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9412 if (targetm
.arm_eabi_unwinder
)
9414 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9415 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
9416 BUILT_IN_CXA_END_CLEANUP
,
9417 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
9420 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9421 local_define_builtin ("__builtin_unwind_resume", ftype
,
9422 BUILT_IN_UNWIND_RESUME
,
9423 ((targetm
.except_unwind_info (&global_options
)
9425 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9428 /* The exception object and filter values from the runtime. The argument
9429 must be zero before exception lowering, i.e. from the front end. After
9430 exception lowering, it will be the region number for the exception
9431 landing pad. These functions are PURE instead of CONST to prevent
9432 them from being hoisted past the exception edge that will initialize
9433 its value in the landing pad. */
9434 ftype
= build_function_type_list (ptr_type_node
,
9435 integer_type_node
, NULL_TREE
);
9436 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
9437 "__builtin_eh_pointer", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9439 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
9440 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
9441 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
9442 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9444 ftype
= build_function_type_list (void_type_node
,
9445 integer_type_node
, integer_type_node
,
9447 local_define_builtin ("__builtin_eh_copy_values", ftype
,
9448 BUILT_IN_EH_COPY_VALUES
,
9449 "__builtin_eh_copy_values", ECF_NOTHROW
);
9451 /* Complex multiplication and division. These are handled as builtins
9452 rather than optabs because emit_library_call_value doesn't support
9453 complex. Further, we can do slightly better with folding these
9454 beasties if the real and complex parts of the arguments are separate. */
9458 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
9460 char mode_name_buf
[4], *q
;
9462 enum built_in_function mcode
, dcode
;
9463 tree type
, inner_type
;
9465 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
9468 inner_type
= TREE_TYPE (type
);
9470 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
9471 inner_type
, inner_type
, NULL_TREE
);
9473 mcode
= ((enum built_in_function
)
9474 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9475 dcode
= ((enum built_in_function
)
9476 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9478 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
9482 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
9483 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
9484 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
9486 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
9487 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
9488 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
9493 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
9496 If we requested a pointer to a vector, build up the pointers that
9497 we stripped off while looking for the inner type. Similarly for
9498 return values from functions.
9500 The argument TYPE is the top of the chain, and BOTTOM is the
9501 new type which we will point to. */
9504 reconstruct_complex_type (tree type
, tree bottom
)
9508 if (TREE_CODE (type
) == POINTER_TYPE
)
9510 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9511 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
9512 TYPE_REF_CAN_ALIAS_ALL (type
));
9514 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
9516 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9517 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
9518 TYPE_REF_CAN_ALIAS_ALL (type
));
9520 else if (TREE_CODE (type
) == ARRAY_TYPE
)
9522 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9523 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
9525 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9527 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9528 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
9530 else if (TREE_CODE (type
) == METHOD_TYPE
)
9532 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9533 /* The build_method_type_directly() routine prepends 'this' to argument list,
9534 so we must compensate by getting rid of it. */
9536 = build_method_type_directly
9537 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
9539 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
9541 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9543 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9544 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
9549 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
9553 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
9556 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
9560 switch (GET_MODE_CLASS (mode
))
9562 case MODE_VECTOR_INT
:
9563 case MODE_VECTOR_FLOAT
:
9564 case MODE_VECTOR_FRACT
:
9565 case MODE_VECTOR_UFRACT
:
9566 case MODE_VECTOR_ACCUM
:
9567 case MODE_VECTOR_UACCUM
:
9568 nunits
= GET_MODE_NUNITS (mode
);
9572 /* Check that there are no leftover bits. */
9573 gcc_assert (GET_MODE_BITSIZE (mode
)
9574 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
9576 nunits
= GET_MODE_BITSIZE (mode
)
9577 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
9584 return make_vector_type (innertype
, nunits
, mode
);
9587 /* Similarly, but takes the inner type and number of units, which must be
9591 build_vector_type (tree innertype
, int nunits
)
9593 return make_vector_type (innertype
, nunits
, VOIDmode
);
9596 /* Similarly, but takes the inner type and number of units, which must be
9600 build_opaque_vector_type (tree innertype
, int nunits
)
9603 innertype
= build_distinct_type_copy (innertype
);
9604 t
= make_vector_type (innertype
, nunits
, VOIDmode
);
9605 TYPE_VECTOR_OPAQUE (t
) = true;
9610 /* Given an initializer INIT, return TRUE if INIT is zero or some
9611 aggregate of zeros. Otherwise return FALSE. */
9613 initializer_zerop (const_tree init
)
9619 switch (TREE_CODE (init
))
9622 return integer_zerop (init
);
9625 /* ??? Note that this is not correct for C4X float formats. There,
9626 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
9627 negative exponent. */
9628 return real_zerop (init
)
9629 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
9632 return fixed_zerop (init
);
9635 return integer_zerop (init
)
9636 || (real_zerop (init
)
9637 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
9638 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
9641 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
9642 if (!initializer_zerop (TREE_VALUE (elt
)))
9648 unsigned HOST_WIDE_INT idx
;
9650 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
9651 if (!initializer_zerop (elt
))
9660 /* We need to loop through all elements to handle cases like
9661 "\0" and "\0foobar". */
9662 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
9663 if (TREE_STRING_POINTER (init
)[i
] != '\0')
9674 /* Build an empty statement at location LOC. */
9677 build_empty_stmt (location_t loc
)
9679 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
9680 SET_EXPR_LOCATION (t
, loc
);
9685 /* Build an OpenMP clause with code CODE. LOC is the location of the
9689 build_omp_clause (location_t loc
, enum omp_clause_code code
)
9694 length
= omp_clause_num_ops
[code
];
9695 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
9697 record_node_allocation_statistics (OMP_CLAUSE
, size
);
9699 t
= ggc_alloc_tree_node (size
);
9700 memset (t
, 0, size
);
9701 TREE_SET_CODE (t
, OMP_CLAUSE
);
9702 OMP_CLAUSE_SET_CODE (t
, code
);
9703 OMP_CLAUSE_LOCATION (t
) = loc
;
9708 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
9709 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
9710 Except for the CODE and operand count field, other storage for the
9711 object is initialized to zeros. */
9714 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
9717 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
9719 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
9720 gcc_assert (len
>= 1);
9722 record_node_allocation_statistics (code
, length
);
9724 t
= ggc_alloc_zone_cleared_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
9726 TREE_SET_CODE (t
, code
);
9728 /* Can't use TREE_OPERAND to store the length because if checking is
9729 enabled, it will try to check the length before we store it. :-P */
9730 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
9735 /* Helper function for build_call_* functions; build a CALL_EXPR with
9736 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
9737 the argument slots. */
9740 build_call_1 (tree return_type
, tree fn
, int nargs
)
9744 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
9745 TREE_TYPE (t
) = return_type
;
9746 CALL_EXPR_FN (t
) = fn
;
9747 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
9752 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9753 FN and a null static chain slot. NARGS is the number of call arguments
9754 which are specified as "..." arguments. */
9757 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
9761 va_start (args
, nargs
);
9762 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
9767 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9768 FN and a null static chain slot. NARGS is the number of call arguments
9769 which are specified as a va_list ARGS. */
9772 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
9777 t
= build_call_1 (return_type
, fn
, nargs
);
9778 for (i
= 0; i
< nargs
; i
++)
9779 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
9780 process_call_operands (t
);
9784 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9785 FN and a null static chain slot. NARGS is the number of call arguments
9786 which are specified as a tree array ARGS. */
9789 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
9790 int nargs
, const tree
*args
)
9795 t
= build_call_1 (return_type
, fn
, nargs
);
9796 for (i
= 0; i
< nargs
; i
++)
9797 CALL_EXPR_ARG (t
, i
) = args
[i
];
9798 process_call_operands (t
);
9799 SET_EXPR_LOCATION (t
, loc
);
9803 /* Like build_call_array, but takes a VEC. */
9806 build_call_vec (tree return_type
, tree fn
, VEC(tree
,gc
) *args
)
9811 ret
= build_call_1 (return_type
, fn
, VEC_length (tree
, args
));
9812 FOR_EACH_VEC_ELT (tree
, args
, ix
, t
)
9813 CALL_EXPR_ARG (ret
, ix
) = t
;
9814 process_call_operands (ret
);
9819 /* Returns true if it is possible to prove that the index of
9820 an array access REF (an ARRAY_REF expression) falls into the
9824 in_array_bounds_p (tree ref
)
9826 tree idx
= TREE_OPERAND (ref
, 1);
9829 if (TREE_CODE (idx
) != INTEGER_CST
)
9832 min
= array_ref_low_bound (ref
);
9833 max
= array_ref_up_bound (ref
);
9836 || TREE_CODE (min
) != INTEGER_CST
9837 || TREE_CODE (max
) != INTEGER_CST
)
9840 if (tree_int_cst_lt (idx
, min
)
9841 || tree_int_cst_lt (max
, idx
))
9847 /* Returns true if it is possible to prove that the range of
9848 an array access REF (an ARRAY_RANGE_REF expression) falls
9849 into the array bounds. */
9852 range_in_array_bounds_p (tree ref
)
9854 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
9855 tree range_min
, range_max
, min
, max
;
9857 range_min
= TYPE_MIN_VALUE (domain_type
);
9858 range_max
= TYPE_MAX_VALUE (domain_type
);
9861 || TREE_CODE (range_min
) != INTEGER_CST
9862 || TREE_CODE (range_max
) != INTEGER_CST
)
9865 min
= array_ref_low_bound (ref
);
9866 max
= array_ref_up_bound (ref
);
9869 || TREE_CODE (min
) != INTEGER_CST
9870 || TREE_CODE (max
) != INTEGER_CST
)
9873 if (tree_int_cst_lt (range_min
, min
)
9874 || tree_int_cst_lt (max
, range_max
))
9880 /* Return true if T (assumed to be a DECL) must be assigned a memory
9884 needs_to_live_in_memory (const_tree t
)
9886 if (TREE_CODE (t
) == SSA_NAME
)
9887 t
= SSA_NAME_VAR (t
);
9889 return (TREE_ADDRESSABLE (t
)
9890 || is_global_var (t
)
9891 || (TREE_CODE (t
) == RESULT_DECL
9892 && !DECL_BY_REFERENCE (t
)
9893 && aggregate_value_p (t
, current_function_decl
)));
9896 /* There are situations in which a language considers record types
9897 compatible which have different field lists. Decide if two fields
9898 are compatible. It is assumed that the parent records are compatible. */
9901 fields_compatible_p (const_tree f1
, const_tree f2
)
9903 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
9904 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
9907 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
9908 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
9911 if (!types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
9917 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
9920 find_compatible_field (tree record
, tree orig_field
)
9924 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
9925 if (TREE_CODE (f
) == FIELD_DECL
9926 && fields_compatible_p (f
, orig_field
))
9929 /* ??? Why isn't this on the main fields list? */
9930 f
= TYPE_VFIELD (record
);
9931 if (f
&& TREE_CODE (f
) == FIELD_DECL
9932 && fields_compatible_p (f
, orig_field
))
9935 /* ??? We should abort here, but Java appears to do Bad Things
9936 with inherited fields. */
9940 /* Return value of a constant X and sign-extend it. */
9943 int_cst_value (const_tree x
)
9945 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
9946 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
9948 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9949 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
9950 || TREE_INT_CST_HIGH (x
) == -1);
9952 if (bits
< HOST_BITS_PER_WIDE_INT
)
9954 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
9956 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
9958 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
9964 /* Return value of a constant X and sign-extend it. */
9967 widest_int_cst_value (const_tree x
)
9969 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
9970 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
9972 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
9973 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= 2 * HOST_BITS_PER_WIDE_INT
);
9974 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
9975 << HOST_BITS_PER_WIDE_INT
);
9977 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9978 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
9979 || TREE_INT_CST_HIGH (x
) == -1);
9982 if (bits
< HOST_BITS_PER_WIDEST_INT
)
9984 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
9986 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
9988 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
9994 /* If TYPE is an integral type, return an equivalent type which is
9995 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
9996 return TYPE itself. */
9999 signed_or_unsigned_type_for (int unsignedp
, tree type
)
10002 if (POINTER_TYPE_P (type
))
10004 /* If the pointer points to the normal address space, use the
10005 size_type_node. Otherwise use an appropriate size for the pointer
10006 based on the named address space it points to. */
10007 if (!TYPE_ADDR_SPACE (TREE_TYPE (t
)))
10008 t
= size_type_node
;
10010 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
10013 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
10016 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
10019 /* Returns unsigned variant of TYPE. */
10022 unsigned_type_for (tree type
)
10024 return signed_or_unsigned_type_for (1, type
);
10027 /* Returns signed variant of TYPE. */
10030 signed_type_for (tree type
)
10032 return signed_or_unsigned_type_for (0, type
);
10035 /* Returns the largest value obtainable by casting something in INNER type to
10039 upper_bound_in_type (tree outer
, tree inner
)
10041 unsigned HOST_WIDE_INT lo
, hi
;
10042 unsigned int det
= 0;
10043 unsigned oprec
= TYPE_PRECISION (outer
);
10044 unsigned iprec
= TYPE_PRECISION (inner
);
10047 /* Compute a unique number for every combination. */
10048 det
|= (oprec
> iprec
) ? 4 : 0;
10049 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10050 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10052 /* Determine the exponent to use. */
10057 /* oprec <= iprec, outer: signed, inner: don't care. */
10062 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10066 /* oprec > iprec, outer: signed, inner: signed. */
10070 /* oprec > iprec, outer: signed, inner: unsigned. */
10074 /* oprec > iprec, outer: unsigned, inner: signed. */
10078 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10082 gcc_unreachable ();
10085 /* Compute 2^^prec - 1. */
10086 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10089 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
10090 >> (HOST_BITS_PER_WIDE_INT
- prec
));
10094 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
10095 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
10096 lo
= ~(unsigned HOST_WIDE_INT
) 0;
10099 return build_int_cst_wide (outer
, lo
, hi
);
10102 /* Returns the smallest value obtainable by casting something in INNER type to
10106 lower_bound_in_type (tree outer
, tree inner
)
10108 unsigned HOST_WIDE_INT lo
, hi
;
10109 unsigned oprec
= TYPE_PRECISION (outer
);
10110 unsigned iprec
= TYPE_PRECISION (inner
);
10112 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10114 if (TYPE_UNSIGNED (outer
)
10115 /* If we are widening something of an unsigned type, OUTER type
10116 contains all values of INNER type. In particular, both INNER
10117 and OUTER types have zero in common. */
10118 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10122 /* If we are widening a signed type to another signed type, we
10123 want to obtain -2^^(iprec-1). If we are keeping the
10124 precision or narrowing to a signed type, we want to obtain
10126 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10128 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10130 hi
= ~(unsigned HOST_WIDE_INT
) 0;
10131 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
10135 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
10136 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
10141 return build_int_cst_wide (outer
, lo
, hi
);
10144 /* Return nonzero if two operands that are suitable for PHI nodes are
10145 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10146 SSA_NAME or invariant. Note that this is strictly an optimization.
10147 That is, callers of this function can directly call operand_equal_p
10148 and get the same result, only slower. */
10151 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10155 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10157 return operand_equal_p (arg0
, arg1
, 0);
10160 /* Returns number of zeros at the end of binary representation of X.
10162 ??? Use ffs if available? */
10165 num_ending_zeros (const_tree x
)
10167 unsigned HOST_WIDE_INT fr
, nfr
;
10168 unsigned num
, abits
;
10169 tree type
= TREE_TYPE (x
);
10171 if (TREE_INT_CST_LOW (x
) == 0)
10173 num
= HOST_BITS_PER_WIDE_INT
;
10174 fr
= TREE_INT_CST_HIGH (x
);
10179 fr
= TREE_INT_CST_LOW (x
);
10182 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
10185 if (nfr
<< abits
== fr
)
10192 if (num
> TYPE_PRECISION (type
))
10193 num
= TYPE_PRECISION (type
);
10195 return build_int_cst_type (type
, num
);
10199 #define WALK_SUBTREE(NODE) \
10202 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10208 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10209 be walked whenever a type is seen in the tree. Rest of operands and return
10210 value are as for walk_tree. */
10213 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10214 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10216 tree result
= NULL_TREE
;
10218 switch (TREE_CODE (type
))
10221 case REFERENCE_TYPE
:
10222 /* We have to worry about mutually recursive pointers. These can't
10223 be written in C. They can in Ada. It's pathological, but
10224 there's an ACATS test (c38102a) that checks it. Deal with this
10225 by checking if we're pointing to another pointer, that one
10226 points to another pointer, that one does too, and we have no htab.
10227 If so, get a hash table. We check three levels deep to avoid
10228 the cost of the hash table if we don't need one. */
10229 if (POINTER_TYPE_P (TREE_TYPE (type
))
10230 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10231 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10234 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10242 /* ... fall through ... */
10245 WALK_SUBTREE (TREE_TYPE (type
));
10249 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10251 /* Fall through. */
10253 case FUNCTION_TYPE
:
10254 WALK_SUBTREE (TREE_TYPE (type
));
10258 /* We never want to walk into default arguments. */
10259 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
10260 WALK_SUBTREE (TREE_VALUE (arg
));
10265 /* Don't follow this nodes's type if a pointer for fear that
10266 we'll have infinite recursion. If we have a PSET, then we
10269 || (!POINTER_TYPE_P (TREE_TYPE (type
))
10270 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
10271 WALK_SUBTREE (TREE_TYPE (type
));
10272 WALK_SUBTREE (TYPE_DOMAIN (type
));
10276 WALK_SUBTREE (TREE_TYPE (type
));
10277 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
10287 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10288 called with the DATA and the address of each sub-tree. If FUNC returns a
10289 non-NULL value, the traversal is stopped, and the value returned by FUNC
10290 is returned. If PSET is non-NULL it is used to record the nodes visited,
10291 and to avoid visiting a node more than once. */
10294 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10295 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10297 enum tree_code code
;
10301 #define WALK_SUBTREE_TAIL(NODE) \
10305 goto tail_recurse; \
10310 /* Skip empty subtrees. */
10314 /* Don't walk the same tree twice, if the user has requested
10315 that we avoid doing so. */
10316 if (pset
&& pointer_set_insert (pset
, *tp
))
10319 /* Call the function. */
10321 result
= (*func
) (tp
, &walk_subtrees
, data
);
10323 /* If we found something, return it. */
10327 code
= TREE_CODE (*tp
);
10329 /* Even if we didn't, FUNC may have decided that there was nothing
10330 interesting below this point in the tree. */
10331 if (!walk_subtrees
)
10333 /* But we still need to check our siblings. */
10334 if (code
== TREE_LIST
)
10335 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10336 else if (code
== OMP_CLAUSE
)
10337 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10344 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
10345 if (result
|| !walk_subtrees
)
10352 case IDENTIFIER_NODE
:
10359 case PLACEHOLDER_EXPR
:
10363 /* None of these have subtrees other than those already walked
10368 WALK_SUBTREE (TREE_VALUE (*tp
));
10369 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10374 int len
= TREE_VEC_LENGTH (*tp
);
10379 /* Walk all elements but the first. */
10381 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
10383 /* Now walk the first one as a tail call. */
10384 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
10388 WALK_SUBTREE (TREE_REALPART (*tp
));
10389 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
10393 unsigned HOST_WIDE_INT idx
;
10394 constructor_elt
*ce
;
10397 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
10399 WALK_SUBTREE (ce
->value
);
10404 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
10409 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
10411 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
10412 into declarations that are just mentioned, rather than
10413 declared; they don't really belong to this part of the tree.
10414 And, we can see cycles: the initializer for a declaration
10415 can refer to the declaration itself. */
10416 WALK_SUBTREE (DECL_INITIAL (decl
));
10417 WALK_SUBTREE (DECL_SIZE (decl
));
10418 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
10420 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
10423 case STATEMENT_LIST
:
10425 tree_stmt_iterator i
;
10426 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
10427 WALK_SUBTREE (*tsi_stmt_ptr (i
));
10432 switch (OMP_CLAUSE_CODE (*tp
))
10434 case OMP_CLAUSE_PRIVATE
:
10435 case OMP_CLAUSE_SHARED
:
10436 case OMP_CLAUSE_FIRSTPRIVATE
:
10437 case OMP_CLAUSE_COPYIN
:
10438 case OMP_CLAUSE_COPYPRIVATE
:
10439 case OMP_CLAUSE_IF
:
10440 case OMP_CLAUSE_NUM_THREADS
:
10441 case OMP_CLAUSE_SCHEDULE
:
10442 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
10445 case OMP_CLAUSE_NOWAIT
:
10446 case OMP_CLAUSE_ORDERED
:
10447 case OMP_CLAUSE_DEFAULT
:
10448 case OMP_CLAUSE_UNTIED
:
10449 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10451 case OMP_CLAUSE_LASTPRIVATE
:
10452 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
10453 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
10454 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10456 case OMP_CLAUSE_COLLAPSE
:
10459 for (i
= 0; i
< 3; i
++)
10460 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
10461 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10464 case OMP_CLAUSE_REDUCTION
:
10467 for (i
= 0; i
< 4; i
++)
10468 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
10469 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10473 gcc_unreachable ();
10481 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
10482 But, we only want to walk once. */
10483 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
10484 for (i
= 0; i
< len
; ++i
)
10485 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
10486 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
10490 /* If this is a TYPE_DECL, walk into the fields of the type that it's
10491 defining. We only want to walk into these fields of a type in this
10492 case and not in the general case of a mere reference to the type.
10494 The criterion is as follows: if the field can be an expression, it
10495 must be walked only here. This should be in keeping with the fields
10496 that are directly gimplified in gimplify_type_sizes in order for the
10497 mark/copy-if-shared/unmark machinery of the gimplifier to work with
10498 variable-sized types.
10500 Note that DECLs get walked as part of processing the BIND_EXPR. */
10501 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
10503 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
10504 if (TREE_CODE (*type_p
) == ERROR_MARK
)
10507 /* Call the function for the type. See if it returns anything or
10508 doesn't want us to continue. If we are to continue, walk both
10509 the normal fields and those for the declaration case. */
10510 result
= (*func
) (type_p
, &walk_subtrees
, data
);
10511 if (result
|| !walk_subtrees
)
10514 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
10518 /* If this is a record type, also walk the fields. */
10519 if (RECORD_OR_UNION_TYPE_P (*type_p
))
10523 for (field
= TYPE_FIELDS (*type_p
); field
;
10524 field
= DECL_CHAIN (field
))
10526 /* We'd like to look at the type of the field, but we can
10527 easily get infinite recursion. So assume it's pointed
10528 to elsewhere in the tree. Also, ignore things that
10530 if (TREE_CODE (field
) != FIELD_DECL
)
10533 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
10534 WALK_SUBTREE (DECL_SIZE (field
));
10535 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
10536 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
10537 WALK_SUBTREE (DECL_QUALIFIER (field
));
10541 /* Same for scalar types. */
10542 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
10543 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
10544 || TREE_CODE (*type_p
) == INTEGER_TYPE
10545 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
10546 || TREE_CODE (*type_p
) == REAL_TYPE
)
10548 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
10549 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
10552 WALK_SUBTREE (TYPE_SIZE (*type_p
));
10553 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
10558 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
10562 /* Walk over all the sub-trees of this operand. */
10563 len
= TREE_OPERAND_LENGTH (*tp
);
10565 /* Go through the subtrees. We need to do this in forward order so
10566 that the scope of a FOR_EXPR is handled properly. */
10569 for (i
= 0; i
< len
- 1; ++i
)
10570 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
10571 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
10574 /* If this is a type, walk the needed fields in the type. */
10575 else if (TYPE_P (*tp
))
10576 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
10580 /* We didn't find what we were looking for. */
10583 #undef WALK_SUBTREE_TAIL
10585 #undef WALK_SUBTREE
10587 /* Like walk_tree, but does not walk duplicate nodes more than once. */
10590 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10594 struct pointer_set_t
*pset
;
10596 pset
= pointer_set_create ();
10597 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
10598 pointer_set_destroy (pset
);
10604 tree_block (tree t
)
10606 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
10608 if (IS_EXPR_CODE_CLASS (c
))
10609 return &t
->exp
.block
;
10610 gcc_unreachable ();
10614 /* Create a nameless artificial label and put it in the current
10615 function context. The label has a location of LOC. Returns the
10616 newly created label. */
10619 create_artificial_label (location_t loc
)
10621 tree lab
= build_decl (loc
,
10622 LABEL_DECL
, NULL_TREE
, void_type_node
);
10624 DECL_ARTIFICIAL (lab
) = 1;
10625 DECL_IGNORED_P (lab
) = 1;
10626 DECL_CONTEXT (lab
) = current_function_decl
;
10630 /* Given a tree, try to return a useful variable name that we can use
10631 to prefix a temporary that is being assigned the value of the tree.
10632 I.E. given <temp> = &A, return A. */
10637 tree stripped_decl
;
10640 STRIP_NOPS (stripped_decl
);
10641 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
10642 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
10645 switch (TREE_CODE (stripped_decl
))
10648 return get_name (TREE_OPERAND (stripped_decl
, 0));
10655 /* Return true if TYPE has a variable argument list. */
10658 stdarg_p (const_tree fntype
)
10660 function_args_iterator args_iter
;
10661 tree n
= NULL_TREE
, t
;
10666 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
10671 return n
!= NULL_TREE
&& n
!= void_type_node
;
10674 /* Return true if TYPE has a prototype. */
10677 prototype_p (tree fntype
)
10681 gcc_assert (fntype
!= NULL_TREE
);
10683 t
= TYPE_ARG_TYPES (fntype
);
10684 return (t
!= NULL_TREE
);
10687 /* If BLOCK is inlined from an __attribute__((__artificial__))
10688 routine, return pointer to location from where it has been
10691 block_nonartificial_location (tree block
)
10693 location_t
*ret
= NULL
;
10695 while (block
&& TREE_CODE (block
) == BLOCK
10696 && BLOCK_ABSTRACT_ORIGIN (block
))
10698 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
10700 while (TREE_CODE (ao
) == BLOCK
10701 && BLOCK_ABSTRACT_ORIGIN (ao
)
10702 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
10703 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
10705 if (TREE_CODE (ao
) == FUNCTION_DECL
)
10707 /* If AO is an artificial inline, point RET to the
10708 call site locus at which it has been inlined and continue
10709 the loop, in case AO's caller is also an artificial
10711 if (DECL_DECLARED_INLINE_P (ao
)
10712 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
10713 ret
= &BLOCK_SOURCE_LOCATION (block
);
10717 else if (TREE_CODE (ao
) != BLOCK
)
10720 block
= BLOCK_SUPERCONTEXT (block
);
10726 /* If EXP is inlined from an __attribute__((__artificial__))
10727 function, return the location of the original call expression. */
10730 tree_nonartificial_location (tree exp
)
10732 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
10737 return EXPR_LOCATION (exp
);
10741 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
10744 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
10747 cl_option_hash_hash (const void *x
)
10749 const_tree
const t
= (const_tree
) x
;
10753 hashval_t hash
= 0;
10755 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
10757 p
= (const char *)TREE_OPTIMIZATION (t
);
10758 len
= sizeof (struct cl_optimization
);
10761 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
10763 p
= (const char *)TREE_TARGET_OPTION (t
);
10764 len
= sizeof (struct cl_target_option
);
10768 gcc_unreachable ();
10770 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
10772 for (i
= 0; i
< len
; i
++)
10774 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
10779 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
10780 TARGET_OPTION tree node) is the same as that given by *Y, which is the
10784 cl_option_hash_eq (const void *x
, const void *y
)
10786 const_tree
const xt
= (const_tree
) x
;
10787 const_tree
const yt
= (const_tree
) y
;
10792 if (TREE_CODE (xt
) != TREE_CODE (yt
))
10795 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
10797 xp
= (const char *)TREE_OPTIMIZATION (xt
);
10798 yp
= (const char *)TREE_OPTIMIZATION (yt
);
10799 len
= sizeof (struct cl_optimization
);
10802 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
10804 xp
= (const char *)TREE_TARGET_OPTION (xt
);
10805 yp
= (const char *)TREE_TARGET_OPTION (yt
);
10806 len
= sizeof (struct cl_target_option
);
10810 gcc_unreachable ();
10812 return (memcmp (xp
, yp
, len
) == 0);
10815 /* Build an OPTIMIZATION_NODE based on the current options. */
10818 build_optimization_node (void)
10823 /* Use the cache of optimization nodes. */
10825 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
10828 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
10832 /* Insert this one into the hash table. */
10833 t
= cl_optimization_node
;
10836 /* Make a new node for next time round. */
10837 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
10843 /* Build a TARGET_OPTION_NODE based on the current options. */
10846 build_target_option_node (void)
10851 /* Use the cache of optimization nodes. */
10853 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
10856 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
10860 /* Insert this one into the hash table. */
10861 t
= cl_target_option_node
;
10864 /* Make a new node for next time round. */
10865 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
10871 /* Determine the "ultimate origin" of a block. The block may be an inlined
10872 instance of an inlined instance of a block which is local to an inline
10873 function, so we have to trace all of the way back through the origin chain
10874 to find out what sort of node actually served as the original seed for the
10878 block_ultimate_origin (const_tree block
)
10880 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
10882 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
10883 nodes in the function to point to themselves; ignore that if
10884 we're trying to output the abstract instance of this function. */
10885 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
10888 if (immediate_origin
== NULL_TREE
)
10893 tree lookahead
= immediate_origin
;
10897 ret_val
= lookahead
;
10898 lookahead
= (TREE_CODE (ret_val
) == BLOCK
10899 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
10901 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
10903 /* The block's abstract origin chain may not be the *ultimate* origin of
10904 the block. It could lead to a DECL that has an abstract origin set.
10905 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
10906 will give us if it has one). Note that DECL's abstract origins are
10907 supposed to be the most distant ancestor (or so decl_ultimate_origin
10908 claims), so we don't need to loop following the DECL origins. */
10909 if (DECL_P (ret_val
))
10910 return DECL_ORIGIN (ret_val
);
10916 /* Return true if T1 and T2 are equivalent lists. */
10919 list_equal_p (const_tree t1
, const_tree t2
)
10921 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
10922 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
10927 /* Return true iff conversion in EXP generates no instruction. Mark
10928 it inline so that we fully inline into the stripping functions even
10929 though we have two uses of this function. */
10932 tree_nop_conversion (const_tree exp
)
10934 tree outer_type
, inner_type
;
10936 if (!CONVERT_EXPR_P (exp
)
10937 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
10939 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
10942 outer_type
= TREE_TYPE (exp
);
10943 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
10948 /* Use precision rather then machine mode when we can, which gives
10949 the correct answer even for submode (bit-field) types. */
10950 if ((INTEGRAL_TYPE_P (outer_type
)
10951 || POINTER_TYPE_P (outer_type
)
10952 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
10953 && (INTEGRAL_TYPE_P (inner_type
)
10954 || POINTER_TYPE_P (inner_type
)
10955 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
10956 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
10958 /* Otherwise fall back on comparing machine modes (e.g. for
10959 aggregate types, floats). */
10960 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
10963 /* Return true iff conversion in EXP generates no instruction. Don't
10964 consider conversions changing the signedness. */
10967 tree_sign_nop_conversion (const_tree exp
)
10969 tree outer_type
, inner_type
;
10971 if (!tree_nop_conversion (exp
))
10974 outer_type
= TREE_TYPE (exp
);
10975 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
10977 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
10978 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
10981 /* Strip conversions from EXP according to tree_nop_conversion and
10982 return the resulting expression. */
10985 tree_strip_nop_conversions (tree exp
)
10987 while (tree_nop_conversion (exp
))
10988 exp
= TREE_OPERAND (exp
, 0);
10992 /* Strip conversions from EXP according to tree_sign_nop_conversion
10993 and return the resulting expression. */
10996 tree_strip_sign_nop_conversions (tree exp
)
10998 while (tree_sign_nop_conversion (exp
))
10999 exp
= TREE_OPERAND (exp
, 0);
11003 static GTY(()) tree gcc_eh_personality_decl
;
11005 /* Return the GCC personality function decl. */
11008 lhd_gcc_personality (void)
11010 if (!gcc_eh_personality_decl
)
11011 gcc_eh_personality_decl
= build_personality_function ("gcc");
11012 return gcc_eh_personality_decl
;
11015 /* Try to find a base info of BINFO that would have its field decl at offset
11016 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
11017 found, return, otherwise return NULL_TREE. */
11020 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
11022 tree type
= BINFO_TYPE (binfo
);
11026 HOST_WIDE_INT pos
, size
;
11030 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (expected_type
))
11035 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
11037 if (TREE_CODE (fld
) != FIELD_DECL
)
11040 pos
= int_bit_position (fld
);
11041 size
= tree_low_cst (DECL_SIZE (fld
), 1);
11042 if (pos
<= offset
&& (pos
+ size
) > offset
)
11045 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
11048 if (!DECL_ARTIFICIAL (fld
))
11050 binfo
= TYPE_BINFO (TREE_TYPE (fld
));
11054 /* Offset 0 indicates the primary base, whose vtable contents are
11055 represented in the binfo for the derived class. */
11056 else if (offset
!= 0)
11058 tree base_binfo
, found_binfo
= NULL_TREE
;
11059 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11060 if (TREE_TYPE (base_binfo
) == TREE_TYPE (fld
))
11062 found_binfo
= base_binfo
;
11067 binfo
= found_binfo
;
11070 type
= TREE_TYPE (fld
);
11075 /* Returns true if X is a typedef decl. */
11078 is_typedef_decl (tree x
)
11080 return (x
&& TREE_CODE (x
) == TYPE_DECL
11081 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
11084 /* Returns true iff TYPE is a type variant created for a typedef. */
11087 typedef_variant_p (tree type
)
11089 return is_typedef_decl (TYPE_NAME (type
));
11092 /* Warn about a use of an identifier which was marked deprecated. */
11094 warn_deprecated_use (tree node
, tree attr
)
11098 if (node
== 0 || !warn_deprecated_decl
)
11104 attr
= DECL_ATTRIBUTES (node
);
11105 else if (TYPE_P (node
))
11107 tree decl
= TYPE_STUB_DECL (node
);
11109 attr
= lookup_attribute ("deprecated",
11110 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
11115 attr
= lookup_attribute ("deprecated", attr
);
11118 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
11124 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
11126 warning (OPT_Wdeprecated_declarations
,
11127 "%qD is deprecated (declared at %s:%d): %s",
11128 node
, xloc
.file
, xloc
.line
, msg
);
11130 warning (OPT_Wdeprecated_declarations
,
11131 "%qD is deprecated (declared at %s:%d)",
11132 node
, xloc
.file
, xloc
.line
);
11134 else if (TYPE_P (node
))
11136 tree what
= NULL_TREE
;
11137 tree decl
= TYPE_STUB_DECL (node
);
11139 if (TYPE_NAME (node
))
11141 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
11142 what
= TYPE_NAME (node
);
11143 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
11144 && DECL_NAME (TYPE_NAME (node
)))
11145 what
= DECL_NAME (TYPE_NAME (node
));
11150 expanded_location xloc
11151 = expand_location (DECL_SOURCE_LOCATION (decl
));
11155 warning (OPT_Wdeprecated_declarations
,
11156 "%qE is deprecated (declared at %s:%d): %s",
11157 what
, xloc
.file
, xloc
.line
, msg
);
11159 warning (OPT_Wdeprecated_declarations
,
11160 "%qE is deprecated (declared at %s:%d)", what
,
11161 xloc
.file
, xloc
.line
);
11166 warning (OPT_Wdeprecated_declarations
,
11167 "type is deprecated (declared at %s:%d): %s",
11168 xloc
.file
, xloc
.line
, msg
);
11170 warning (OPT_Wdeprecated_declarations
,
11171 "type is deprecated (declared at %s:%d)",
11172 xloc
.file
, xloc
.line
);
11180 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
11183 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
11188 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
11191 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
11197 #include "gt-tree.h"