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 /* Sometimes the C++ frontend doesn't manage to transform a temporary
4652 DECL_VINDEX referring to itself into a vtable slot number as it
4653 should. Happens with functions that are copied and then forgotten
4654 about. Just clear it, it won't matter anymore. */
4655 if (DECL_VINDEX (decl
) && !host_integerp (DECL_VINDEX (decl
), 0))
4656 DECL_VINDEX (decl
) = NULL_TREE
;
4658 else if (TREE_CODE (decl
) == VAR_DECL
)
4660 if ((DECL_EXTERNAL (decl
)
4661 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
4662 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
4663 DECL_INITIAL (decl
) = NULL_TREE
;
4665 else if (TREE_CODE (decl
) == TYPE_DECL
)
4666 DECL_INITIAL (decl
) = NULL_TREE
;
4667 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
4668 && DECL_INITIAL (decl
)
4669 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
4671 /* Strip builtins from the translation-unit BLOCK. We still have
4672 targets without builtin_decl support and also builtins are
4673 shared nodes and thus we can't use TREE_CHAIN in multiple
4675 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
4679 if (TREE_CODE (var
) == FUNCTION_DECL
4680 && DECL_BUILT_IN (var
))
4681 *nextp
= TREE_CHAIN (var
);
4683 nextp
= &TREE_CHAIN (var
);
4689 /* Data used when collecting DECLs and TYPEs for language data removal. */
4691 struct free_lang_data_d
4693 /* Worklist to avoid excessive recursion. */
4694 VEC(tree
,heap
) *worklist
;
4696 /* Set of traversed objects. Used to avoid duplicate visits. */
4697 struct pointer_set_t
*pset
;
4699 /* Array of symbols to process with free_lang_data_in_decl. */
4700 VEC(tree
,heap
) *decls
;
4702 /* Array of types to process with free_lang_data_in_type. */
4703 VEC(tree
,heap
) *types
;
4707 /* Save all language fields needed to generate proper debug information
4708 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4711 save_debug_info_for_decl (tree t
)
4713 /*struct saved_debug_info_d *sdi;*/
4715 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
4717 /* FIXME. Partial implementation for saving debug info removed. */
4721 /* Save all language fields needed to generate proper debug information
4722 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
4725 save_debug_info_for_type (tree t
)
4727 /*struct saved_debug_info_d *sdi;*/
4729 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
4731 /* FIXME. Partial implementation for saving debug info removed. */
4735 /* Add type or decl T to one of the list of tree nodes that need their
4736 language data removed. The lists are held inside FLD. */
4739 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
4743 VEC_safe_push (tree
, heap
, fld
->decls
, t
);
4744 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4745 save_debug_info_for_decl (t
);
4747 else if (TYPE_P (t
))
4749 VEC_safe_push (tree
, heap
, fld
->types
, t
);
4750 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4751 save_debug_info_for_type (t
);
4757 /* Push tree node T into FLD->WORKLIST. */
4760 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
4762 if (t
&& !is_lang_specific (t
) && !pointer_set_contains (fld
->pset
, t
))
4763 VEC_safe_push (tree
, heap
, fld
->worklist
, (t
));
4767 /* Operand callback helper for free_lang_data_in_node. *TP is the
4768 subtree operand being considered. */
4771 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
4774 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
4776 if (TREE_CODE (t
) == TREE_LIST
)
4779 /* Language specific nodes will be removed, so there is no need
4780 to gather anything under them. */
4781 if (is_lang_specific (t
))
4789 /* Note that walk_tree does not traverse every possible field in
4790 decls, so we have to do our own traversals here. */
4791 add_tree_to_fld_list (t
, fld
);
4793 fld_worklist_push (DECL_NAME (t
), fld
);
4794 fld_worklist_push (DECL_CONTEXT (t
), fld
);
4795 fld_worklist_push (DECL_SIZE (t
), fld
);
4796 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
4798 /* We are going to remove everything under DECL_INITIAL for
4799 TYPE_DECLs. No point walking them. */
4800 if (TREE_CODE (t
) != TYPE_DECL
)
4801 fld_worklist_push (DECL_INITIAL (t
), fld
);
4803 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
4804 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
4806 if (TREE_CODE (t
) == FUNCTION_DECL
)
4808 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
4809 fld_worklist_push (DECL_RESULT (t
), fld
);
4811 else if (TREE_CODE (t
) == TYPE_DECL
)
4813 fld_worklist_push (DECL_ARGUMENT_FLD (t
), fld
);
4814 fld_worklist_push (DECL_VINDEX (t
), fld
);
4816 else if (TREE_CODE (t
) == FIELD_DECL
)
4818 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
4819 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
4820 fld_worklist_push (DECL_QUALIFIER (t
), fld
);
4821 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
4822 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
4824 else if (TREE_CODE (t
) == VAR_DECL
)
4826 fld_worklist_push (DECL_SECTION_NAME (t
), fld
);
4827 fld_worklist_push (DECL_COMDAT_GROUP (t
), fld
);
4830 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
4831 && DECL_HAS_VALUE_EXPR_P (t
))
4832 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
4834 if (TREE_CODE (t
) != FIELD_DECL
4835 && TREE_CODE (t
) != TYPE_DECL
)
4836 fld_worklist_push (TREE_CHAIN (t
), fld
);
4839 else if (TYPE_P (t
))
4841 /* Note that walk_tree does not traverse every possible field in
4842 types, so we have to do our own traversals here. */
4843 add_tree_to_fld_list (t
, fld
);
4845 if (!RECORD_OR_UNION_TYPE_P (t
))
4846 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
4847 fld_worklist_push (TYPE_SIZE (t
), fld
);
4848 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
4849 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
4850 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
4851 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
4852 fld_worklist_push (TYPE_NAME (t
), fld
);
4853 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
4854 them and thus do not and want not to reach unused pointer types
4856 if (!POINTER_TYPE_P (t
))
4857 fld_worklist_push (TYPE_MINVAL (t
), fld
);
4858 if (!RECORD_OR_UNION_TYPE_P (t
))
4859 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
4860 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
4861 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
4862 do not and want not to reach unused variants this way. */
4863 fld_worklist_push (TYPE_CONTEXT (t
), fld
);
4864 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
4865 and want not to reach unused types this way. */
4867 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
4871 for (i
= 0; VEC_iterate (tree
, BINFO_BASE_BINFOS (TYPE_BINFO (t
)),
4873 fld_worklist_push (TREE_TYPE (tem
), fld
);
4874 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
4876 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
4877 && TREE_CODE (tem
) == TREE_LIST
)
4880 fld_worklist_push (TREE_VALUE (tem
), fld
);
4881 tem
= TREE_CHAIN (tem
);
4885 if (RECORD_OR_UNION_TYPE_P (t
))
4888 /* Push all TYPE_FIELDS - there can be interleaving interesting
4889 and non-interesting things. */
4890 tem
= TYPE_FIELDS (t
);
4893 if (TREE_CODE (tem
) == FIELD_DECL
)
4894 fld_worklist_push (tem
, fld
);
4895 tem
= TREE_CHAIN (tem
);
4899 fld_worklist_push (TREE_CHAIN (t
), fld
);
4902 else if (TREE_CODE (t
) == BLOCK
)
4905 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
4906 fld_worklist_push (tem
, fld
);
4907 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
4908 fld_worklist_push (tem
, fld
);
4909 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
4912 if (TREE_CODE (t
) != IDENTIFIER_NODE
)
4913 fld_worklist_push (TREE_TYPE (t
), fld
);
4919 /* Find decls and types in T. */
4922 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
4926 if (!pointer_set_contains (fld
->pset
, t
))
4927 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
4928 if (VEC_empty (tree
, fld
->worklist
))
4930 t
= VEC_pop (tree
, fld
->worklist
);
4934 /* Translate all the types in LIST with the corresponding runtime
4938 get_eh_types_for_runtime (tree list
)
4942 if (list
== NULL_TREE
)
4945 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
4947 list
= TREE_CHAIN (list
);
4950 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
4951 TREE_CHAIN (prev
) = n
;
4952 prev
= TREE_CHAIN (prev
);
4953 list
= TREE_CHAIN (list
);
4960 /* Find decls and types referenced in EH region R and store them in
4961 FLD->DECLS and FLD->TYPES. */
4964 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
4975 /* The types referenced in each catch must first be changed to the
4976 EH types used at runtime. This removes references to FE types
4978 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
4980 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
4981 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
4986 case ERT_ALLOWED_EXCEPTIONS
:
4987 r
->u
.allowed
.type_list
4988 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
4989 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
4992 case ERT_MUST_NOT_THROW
:
4993 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
4994 find_decls_types_r
, fld
, fld
->pset
);
5000 /* Find decls and types referenced in cgraph node N and store them in
5001 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5002 look for *every* kind of DECL and TYPE node reachable from N,
5003 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5004 NAMESPACE_DECLs, etc). */
5007 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5010 struct function
*fn
;
5014 find_decls_types (n
->decl
, fld
);
5016 if (!gimple_has_body_p (n
->decl
))
5019 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5021 fn
= DECL_STRUCT_FUNCTION (n
->decl
);
5023 /* Traverse locals. */
5024 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5025 find_decls_types (t
, fld
);
5027 /* Traverse EH regions in FN. */
5030 FOR_ALL_EH_REGION_FN (r
, fn
)
5031 find_decls_types_in_eh_region (r
, fld
);
5034 /* Traverse every statement in FN. */
5035 FOR_EACH_BB_FN (bb
, fn
)
5037 gimple_stmt_iterator si
;
5040 for (si
= gsi_start_phis (bb
); !gsi_end_p (si
); gsi_next (&si
))
5042 gimple phi
= gsi_stmt (si
);
5044 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5046 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5047 find_decls_types (*arg_p
, fld
);
5051 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5053 gimple stmt
= gsi_stmt (si
);
5055 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5057 tree arg
= gimple_op (stmt
, i
);
5058 find_decls_types (arg
, fld
);
5065 /* Find decls and types referenced in varpool node N and store them in
5066 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5067 look for *every* kind of DECL and TYPE node reachable from N,
5068 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5069 NAMESPACE_DECLs, etc). */
5072 find_decls_types_in_var (struct varpool_node
*v
, struct free_lang_data_d
*fld
)
5074 find_decls_types (v
->decl
, fld
);
5077 /* If T needs an assembler name, have one created for it. */
5080 assign_assembler_name_if_neeeded (tree t
)
5082 if (need_assembler_name_p (t
))
5084 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5085 diagnostics that use input_location to show locus
5086 information. The problem here is that, at this point,
5087 input_location is generally anchored to the end of the file
5088 (since the parser is long gone), so we don't have a good
5089 position to pin it to.
5091 To alleviate this problem, this uses the location of T's
5092 declaration. Examples of this are
5093 testsuite/g++.dg/template/cond2.C and
5094 testsuite/g++.dg/template/pr35240.C. */
5095 location_t saved_location
= input_location
;
5096 input_location
= DECL_SOURCE_LOCATION (t
);
5098 decl_assembler_name (t
);
5100 input_location
= saved_location
;
5105 /* Free language specific information for every operand and expression
5106 in every node of the call graph. This process operates in three stages:
5108 1- Every callgraph node and varpool node is traversed looking for
5109 decls and types embedded in them. This is a more exhaustive
5110 search than that done by find_referenced_vars, because it will
5111 also collect individual fields, decls embedded in types, etc.
5113 2- All the decls found are sent to free_lang_data_in_decl.
5115 3- All the types found are sent to free_lang_data_in_type.
5117 The ordering between decls and types is important because
5118 free_lang_data_in_decl sets assembler names, which includes
5119 mangling. So types cannot be freed up until assembler names have
5123 free_lang_data_in_cgraph (void)
5125 struct cgraph_node
*n
;
5126 struct varpool_node
*v
;
5127 struct free_lang_data_d fld
;
5132 /* Initialize sets and arrays to store referenced decls and types. */
5133 fld
.pset
= pointer_set_create ();
5134 fld
.worklist
= NULL
;
5135 fld
.decls
= VEC_alloc (tree
, heap
, 100);
5136 fld
.types
= VEC_alloc (tree
, heap
, 100);
5138 /* Find decls and types in the body of every function in the callgraph. */
5139 for (n
= cgraph_nodes
; n
; n
= n
->next
)
5140 find_decls_types_in_node (n
, &fld
);
5142 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
5143 find_decls_types (p
->decl
, &fld
);
5145 /* Find decls and types in every varpool symbol. */
5146 for (v
= varpool_nodes
; v
; v
= v
->next
)
5147 find_decls_types_in_var (v
, &fld
);
5149 /* Set the assembler name on every decl found. We need to do this
5150 now because free_lang_data_in_decl will invalidate data needed
5151 for mangling. This breaks mangling on interdependent decls. */
5152 FOR_EACH_VEC_ELT (tree
, fld
.decls
, i
, t
)
5153 assign_assembler_name_if_neeeded (t
);
5155 /* Traverse every decl found freeing its language data. */
5156 FOR_EACH_VEC_ELT (tree
, fld
.decls
, i
, t
)
5157 free_lang_data_in_decl (t
);
5159 /* Traverse every type found freeing its language data. */
5160 FOR_EACH_VEC_ELT (tree
, fld
.types
, i
, t
)
5161 free_lang_data_in_type (t
);
5163 pointer_set_destroy (fld
.pset
);
5164 VEC_free (tree
, heap
, fld
.worklist
);
5165 VEC_free (tree
, heap
, fld
.decls
);
5166 VEC_free (tree
, heap
, fld
.types
);
5170 /* Free resources that are used by FE but are not needed once they are done. */
5173 free_lang_data (void)
5177 /* If we are the LTO frontend we have freed lang-specific data already. */
5179 || !flag_generate_lto
)
5182 /* Allocate and assign alias sets to the standard integer types
5183 while the slots are still in the way the frontends generated them. */
5184 for (i
= 0; i
< itk_none
; ++i
)
5185 if (integer_types
[i
])
5186 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5188 /* Traverse the IL resetting language specific information for
5189 operands, expressions, etc. */
5190 free_lang_data_in_cgraph ();
5192 /* Create gimple variants for common types. */
5193 ptrdiff_type_node
= integer_type_node
;
5194 fileptr_type_node
= ptr_type_node
;
5195 if (TREE_CODE (boolean_type_node
) != BOOLEAN_TYPE
5196 || (TYPE_MODE (boolean_type_node
)
5197 != mode_for_size (BOOL_TYPE_SIZE
, MODE_INT
, 0))
5198 || TYPE_PRECISION (boolean_type_node
) != 1
5199 || !TYPE_UNSIGNED (boolean_type_node
))
5201 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
5202 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
5203 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
5204 TYPE_PRECISION (boolean_type_node
) = 1;
5205 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
5206 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
5209 /* Unify char_type_node with its properly signed variant. */
5210 if (TYPE_UNSIGNED (char_type_node
))
5211 unsigned_char_type_node
= char_type_node
;
5213 signed_char_type_node
= char_type_node
;
5215 /* Reset some langhooks. Do not reset types_compatible_p, it may
5216 still be used indirectly via the get_alias_set langhook. */
5217 lang_hooks
.callgraph
.analyze_expr
= NULL
;
5218 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5219 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5220 lang_hooks
.set_decl_assembler_name
= lhd_set_decl_assembler_name
;
5222 /* Reset diagnostic machinery. */
5223 diagnostic_starter (global_dc
) = default_tree_diagnostic_starter
;
5224 diagnostic_finalizer (global_dc
) = default_diagnostic_finalizer
;
5225 diagnostic_format_decoder (global_dc
) = default_tree_printer
;
5231 struct simple_ipa_opt_pass pass_ipa_free_lang_data
=
5235 "*free_lang_data", /* name */
5237 free_lang_data
, /* execute */
5240 0, /* static_pass_number */
5241 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5242 0, /* properties_required */
5243 0, /* properties_provided */
5244 0, /* properties_destroyed */
5245 0, /* todo_flags_start */
5246 TODO_ggc_collect
/* todo_flags_finish */
5250 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5253 We try both `text' and `__text__', ATTR may be either one. */
5254 /* ??? It might be a reasonable simplification to require ATTR to be only
5255 `text'. One might then also require attribute lists to be stored in
5256 their canonicalized form. */
5259 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
5264 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
5267 p
= IDENTIFIER_POINTER (ident
);
5268 ident_len
= IDENTIFIER_LENGTH (ident
);
5270 if (ident_len
== attr_len
5271 && strcmp (attr
, p
) == 0)
5274 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
5277 gcc_assert (attr
[1] == '_');
5278 gcc_assert (attr
[attr_len
- 2] == '_');
5279 gcc_assert (attr
[attr_len
- 1] == '_');
5280 if (ident_len
== attr_len
- 4
5281 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
5286 if (ident_len
== attr_len
+ 4
5287 && p
[0] == '_' && p
[1] == '_'
5288 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5289 && strncmp (attr
, p
+ 2, attr_len
) == 0)
5296 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5299 We try both `text' and `__text__', ATTR may be either one. */
5302 is_attribute_p (const char *attr
, const_tree ident
)
5304 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
5307 /* Given an attribute name and a list of attributes, return a pointer to the
5308 attribute's list element if the attribute is part of the list, or NULL_TREE
5309 if not found. If the attribute appears more than once, this only
5310 returns the first occurrence; the TREE_CHAIN of the return value should
5311 be passed back in if further occurrences are wanted. */
5314 lookup_attribute (const char *attr_name
, tree list
)
5317 size_t attr_len
= strlen (attr_name
);
5319 for (l
= list
; l
; l
= TREE_CHAIN (l
))
5321 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
5322 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
5328 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5332 remove_attribute (const char *attr_name
, tree list
)
5335 size_t attr_len
= strlen (attr_name
);
5337 for (p
= &list
; *p
; )
5340 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
5341 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
5342 *p
= TREE_CHAIN (l
);
5344 p
= &TREE_CHAIN (l
);
5350 /* Return an attribute list that is the union of a1 and a2. */
5353 merge_attributes (tree a1
, tree a2
)
5357 /* Either one unset? Take the set one. */
5359 if ((attributes
= a1
) == 0)
5362 /* One that completely contains the other? Take it. */
5364 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
5366 if (attribute_list_contained (a2
, a1
))
5370 /* Pick the longest list, and hang on the other list. */
5372 if (list_length (a1
) < list_length (a2
))
5373 attributes
= a2
, a2
= a1
;
5375 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
5378 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
5380 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
5381 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
5386 a1
= copy_node (a2
);
5387 TREE_CHAIN (a1
) = attributes
;
5396 /* Given types T1 and T2, merge their attributes and return
5400 merge_type_attributes (tree t1
, tree t2
)
5402 return merge_attributes (TYPE_ATTRIBUTES (t1
),
5403 TYPE_ATTRIBUTES (t2
));
5406 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5410 merge_decl_attributes (tree olddecl
, tree newdecl
)
5412 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
5413 DECL_ATTRIBUTES (newdecl
));
5416 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5418 /* Specialization of merge_decl_attributes for various Windows targets.
5420 This handles the following situation:
5422 __declspec (dllimport) int foo;
5425 The second instance of `foo' nullifies the dllimport. */
5428 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
5431 int delete_dllimport_p
= 1;
5433 /* What we need to do here is remove from `old' dllimport if it doesn't
5434 appear in `new'. dllimport behaves like extern: if a declaration is
5435 marked dllimport and a definition appears later, then the object
5436 is not dllimport'd. We also remove a `new' dllimport if the old list
5437 contains dllexport: dllexport always overrides dllimport, regardless
5438 of the order of declaration. */
5439 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
5440 delete_dllimport_p
= 0;
5441 else if (DECL_DLLIMPORT_P (new_tree
)
5442 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
5444 DECL_DLLIMPORT_P (new_tree
) = 0;
5445 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
5446 "dllimport ignored", new_tree
);
5448 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
5450 /* Warn about overriding a symbol that has already been used, e.g.:
5451 extern int __attribute__ ((dllimport)) foo;
5452 int* bar () {return &foo;}
5455 if (TREE_USED (old
))
5457 warning (0, "%q+D redeclared without dllimport attribute "
5458 "after being referenced with dll linkage", new_tree
);
5459 /* If we have used a variable's address with dllimport linkage,
5460 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5461 decl may already have had TREE_CONSTANT computed.
5462 We still remove the attribute so that assembler code refers
5463 to '&foo rather than '_imp__foo'. */
5464 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
5465 DECL_DLLIMPORT_P (new_tree
) = 1;
5468 /* Let an inline definition silently override the external reference,
5469 but otherwise warn about attribute inconsistency. */
5470 else if (TREE_CODE (new_tree
) == VAR_DECL
5471 || !DECL_DECLARED_INLINE_P (new_tree
))
5472 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
5473 "previous dllimport ignored", new_tree
);
5476 delete_dllimport_p
= 0;
5478 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
5480 if (delete_dllimport_p
)
5483 const size_t attr_len
= strlen ("dllimport");
5485 /* Scan the list for dllimport and delete it. */
5486 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
5488 if (is_attribute_with_length_p ("dllimport", attr_len
,
5491 if (prev
== NULL_TREE
)
5494 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
5503 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5504 struct attribute_spec.handler. */
5507 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
5513 /* These attributes may apply to structure and union types being created,
5514 but otherwise should pass to the declaration involved. */
5517 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
5518 | (int) ATTR_FLAG_ARRAY_NEXT
))
5520 *no_add_attrs
= true;
5521 return tree_cons (name
, args
, NULL_TREE
);
5523 if (TREE_CODE (node
) == RECORD_TYPE
5524 || TREE_CODE (node
) == UNION_TYPE
)
5526 node
= TYPE_NAME (node
);
5532 warning (OPT_Wattributes
, "%qE attribute ignored",
5534 *no_add_attrs
= true;
5539 if (TREE_CODE (node
) != FUNCTION_DECL
5540 && TREE_CODE (node
) != VAR_DECL
5541 && TREE_CODE (node
) != TYPE_DECL
)
5543 *no_add_attrs
= true;
5544 warning (OPT_Wattributes
, "%qE attribute ignored",
5549 if (TREE_CODE (node
) == TYPE_DECL
5550 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
5551 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
5553 *no_add_attrs
= true;
5554 warning (OPT_Wattributes
, "%qE attribute ignored",
5559 is_dllimport
= is_attribute_p ("dllimport", name
);
5561 /* Report error on dllimport ambiguities seen now before they cause
5565 /* Honor any target-specific overrides. */
5566 if (!targetm
.valid_dllimport_attribute_p (node
))
5567 *no_add_attrs
= true;
5569 else if (TREE_CODE (node
) == FUNCTION_DECL
5570 && DECL_DECLARED_INLINE_P (node
))
5572 warning (OPT_Wattributes
, "inline function %q+D declared as "
5573 " dllimport: attribute ignored", node
);
5574 *no_add_attrs
= true;
5576 /* Like MS, treat definition of dllimported variables and
5577 non-inlined functions on declaration as syntax errors. */
5578 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
5580 error ("function %q+D definition is marked dllimport", node
);
5581 *no_add_attrs
= true;
5584 else if (TREE_CODE (node
) == VAR_DECL
)
5586 if (DECL_INITIAL (node
))
5588 error ("variable %q+D definition is marked dllimport",
5590 *no_add_attrs
= true;
5593 /* `extern' needn't be specified with dllimport.
5594 Specify `extern' now and hope for the best. Sigh. */
5595 DECL_EXTERNAL (node
) = 1;
5596 /* Also, implicitly give dllimport'd variables declared within
5597 a function global scope, unless declared static. */
5598 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
5599 TREE_PUBLIC (node
) = 1;
5602 if (*no_add_attrs
== false)
5603 DECL_DLLIMPORT_P (node
) = 1;
5605 else if (TREE_CODE (node
) == FUNCTION_DECL
5606 && DECL_DECLARED_INLINE_P (node
)
5607 && flag_keep_inline_dllexport
)
5608 /* An exported function, even if inline, must be emitted. */
5609 DECL_EXTERNAL (node
) = 0;
5611 /* Report error if symbol is not accessible at global scope. */
5612 if (!TREE_PUBLIC (node
)
5613 && (TREE_CODE (node
) == VAR_DECL
5614 || TREE_CODE (node
) == FUNCTION_DECL
))
5616 error ("external linkage required for symbol %q+D because of "
5617 "%qE attribute", node
, name
);
5618 *no_add_attrs
= true;
5621 /* A dllexport'd entity must have default visibility so that other
5622 program units (shared libraries or the main executable) can see
5623 it. A dllimport'd entity must have default visibility so that
5624 the linker knows that undefined references within this program
5625 unit can be resolved by the dynamic linker. */
5628 if (DECL_VISIBILITY_SPECIFIED (node
)
5629 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
5630 error ("%qE implies default visibility, but %qD has already "
5631 "been declared with a different visibility",
5633 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
5634 DECL_VISIBILITY_SPECIFIED (node
) = 1;
5640 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
5642 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5643 of the various TYPE_QUAL values. */
5646 set_type_quals (tree type
, int type_quals
)
5648 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
5649 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
5650 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
5651 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
5654 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5657 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
5659 return (TYPE_QUALS (cand
) == type_quals
5660 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5661 /* Apparently this is needed for Objective-C. */
5662 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5663 /* Check alignment. */
5664 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
5665 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5666 TYPE_ATTRIBUTES (base
)));
5669 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5672 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
5674 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
5675 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5676 /* Apparently this is needed for Objective-C. */
5677 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5678 /* Check alignment. */
5679 && TYPE_ALIGN (cand
) == align
5680 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5681 TYPE_ATTRIBUTES (base
)));
5684 /* Return a version of the TYPE, qualified as indicated by the
5685 TYPE_QUALS, if one exists. If no qualified version exists yet,
5686 return NULL_TREE. */
5689 get_qualified_type (tree type
, int type_quals
)
5693 if (TYPE_QUALS (type
) == type_quals
)
5696 /* Search the chain of variants to see if there is already one there just
5697 like the one we need to have. If so, use that existing one. We must
5698 preserve the TYPE_NAME, since there is code that depends on this. */
5699 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5700 if (check_qualified_type (t
, type
, type_quals
))
5706 /* Like get_qualified_type, but creates the type if it does not
5707 exist. This function never returns NULL_TREE. */
5710 build_qualified_type (tree type
, int type_quals
)
5714 /* See if we already have the appropriate qualified variant. */
5715 t
= get_qualified_type (type
, type_quals
);
5717 /* If not, build it. */
5720 t
= build_variant_type_copy (type
);
5721 set_type_quals (t
, type_quals
);
5723 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5724 /* Propagate structural equality. */
5725 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5726 else if (TYPE_CANONICAL (type
) != type
)
5727 /* Build the underlying canonical type, since it is different
5729 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
5732 /* T is its own canonical type. */
5733 TYPE_CANONICAL (t
) = t
;
5740 /* Create a variant of type T with alignment ALIGN. */
5743 build_aligned_type (tree type
, unsigned int align
)
5747 if (TYPE_PACKED (type
)
5748 || TYPE_ALIGN (type
) == align
)
5751 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5752 if (check_aligned_type (t
, type
, align
))
5755 t
= build_variant_type_copy (type
);
5756 TYPE_ALIGN (t
) = align
;
5761 /* Create a new distinct copy of TYPE. The new type is made its own
5762 MAIN_VARIANT. If TYPE requires structural equality checks, the
5763 resulting type requires structural equality checks; otherwise, its
5764 TYPE_CANONICAL points to itself. */
5767 build_distinct_type_copy (tree type
)
5769 tree t
= copy_node (type
);
5771 TYPE_POINTER_TO (t
) = 0;
5772 TYPE_REFERENCE_TO (t
) = 0;
5774 /* Set the canonical type either to a new equivalence class, or
5775 propagate the need for structural equality checks. */
5776 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5777 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5779 TYPE_CANONICAL (t
) = t
;
5781 /* Make it its own variant. */
5782 TYPE_MAIN_VARIANT (t
) = t
;
5783 TYPE_NEXT_VARIANT (t
) = 0;
5785 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5786 whose TREE_TYPE is not t. This can also happen in the Ada
5787 frontend when using subtypes. */
5792 /* Create a new variant of TYPE, equivalent but distinct. This is so
5793 the caller can modify it. TYPE_CANONICAL for the return type will
5794 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5795 are considered equal by the language itself (or that both types
5796 require structural equality checks). */
5799 build_variant_type_copy (tree type
)
5801 tree t
, m
= TYPE_MAIN_VARIANT (type
);
5803 t
= build_distinct_type_copy (type
);
5805 /* Since we're building a variant, assume that it is a non-semantic
5806 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5807 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
5809 /* Add the new type to the chain of variants of TYPE. */
5810 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
5811 TYPE_NEXT_VARIANT (m
) = t
;
5812 TYPE_MAIN_VARIANT (t
) = m
;
5817 /* Return true if the from tree in both tree maps are equal. */
5820 tree_map_base_eq (const void *va
, const void *vb
)
5822 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
5823 *const b
= (const struct tree_map_base
*) vb
;
5824 return (a
->from
== b
->from
);
5827 /* Hash a from tree in a tree_base_map. */
5830 tree_map_base_hash (const void *item
)
5832 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
5835 /* Return true if this tree map structure is marked for garbage collection
5836 purposes. We simply return true if the from tree is marked, so that this
5837 structure goes away when the from tree goes away. */
5840 tree_map_base_marked_p (const void *p
)
5842 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
5845 /* Hash a from tree in a tree_map. */
5848 tree_map_hash (const void *item
)
5850 return (((const struct tree_map
*) item
)->hash
);
5853 /* Hash a from tree in a tree_decl_map. */
5856 tree_decl_map_hash (const void *item
)
5858 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
5861 /* Return the initialization priority for DECL. */
5864 decl_init_priority_lookup (tree decl
)
5866 struct tree_priority_map
*h
;
5867 struct tree_map_base in
;
5869 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
5871 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
5872 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
5875 /* Return the finalization priority for DECL. */
5878 decl_fini_priority_lookup (tree decl
)
5880 struct tree_priority_map
*h
;
5881 struct tree_map_base in
;
5883 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
5885 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
5886 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
5889 /* Return the initialization and finalization priority information for
5890 DECL. If there is no previous priority information, a freshly
5891 allocated structure is returned. */
5893 static struct tree_priority_map
*
5894 decl_priority_info (tree decl
)
5896 struct tree_priority_map in
;
5897 struct tree_priority_map
*h
;
5900 in
.base
.from
= decl
;
5901 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
5902 h
= (struct tree_priority_map
*) *loc
;
5905 h
= ggc_alloc_cleared_tree_priority_map ();
5907 h
->base
.from
= decl
;
5908 h
->init
= DEFAULT_INIT_PRIORITY
;
5909 h
->fini
= DEFAULT_INIT_PRIORITY
;
5915 /* Set the initialization priority for DECL to PRIORITY. */
5918 decl_init_priority_insert (tree decl
, priority_type priority
)
5920 struct tree_priority_map
*h
;
5922 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
5923 if (priority
== DEFAULT_INIT_PRIORITY
)
5925 h
= decl_priority_info (decl
);
5929 /* Set the finalization priority for DECL to PRIORITY. */
5932 decl_fini_priority_insert (tree decl
, priority_type priority
)
5934 struct tree_priority_map
*h
;
5936 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
5937 if (priority
== DEFAULT_INIT_PRIORITY
)
5939 h
= decl_priority_info (decl
);
5943 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5946 print_debug_expr_statistics (void)
5948 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
5949 (long) htab_size (debug_expr_for_decl
),
5950 (long) htab_elements (debug_expr_for_decl
),
5951 htab_collisions (debug_expr_for_decl
));
5954 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
5957 print_value_expr_statistics (void)
5959 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
5960 (long) htab_size (value_expr_for_decl
),
5961 (long) htab_elements (value_expr_for_decl
),
5962 htab_collisions (value_expr_for_decl
));
5965 /* Lookup a debug expression for FROM, and return it if we find one. */
5968 decl_debug_expr_lookup (tree from
)
5970 struct tree_decl_map
*h
, in
;
5971 in
.base
.from
= from
;
5973 h
= (struct tree_decl_map
*)
5974 htab_find_with_hash (debug_expr_for_decl
, &in
, DECL_UID (from
));
5980 /* Insert a mapping FROM->TO in the debug expression hashtable. */
5983 decl_debug_expr_insert (tree from
, tree to
)
5985 struct tree_decl_map
*h
;
5988 h
= ggc_alloc_tree_decl_map ();
5989 h
->base
.from
= from
;
5991 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, DECL_UID (from
),
5993 *(struct tree_decl_map
**) loc
= h
;
5996 /* Lookup a value expression for FROM, and return it if we find one. */
5999 decl_value_expr_lookup (tree from
)
6001 struct tree_decl_map
*h
, in
;
6002 in
.base
.from
= from
;
6004 h
= (struct tree_decl_map
*)
6005 htab_find_with_hash (value_expr_for_decl
, &in
, DECL_UID (from
));
6011 /* Insert a mapping FROM->TO in the value expression hashtable. */
6014 decl_value_expr_insert (tree from
, tree to
)
6016 struct tree_decl_map
*h
;
6019 h
= ggc_alloc_tree_decl_map ();
6020 h
->base
.from
= from
;
6022 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, DECL_UID (from
),
6024 *(struct tree_decl_map
**) loc
= h
;
6027 /* Hashing of types so that we don't make duplicates.
6028 The entry point is `type_hash_canon'. */
6030 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6031 with types in the TREE_VALUE slots), by adding the hash codes
6032 of the individual types. */
6035 type_hash_list (const_tree list
, hashval_t hashcode
)
6039 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6040 if (TREE_VALUE (tail
) != error_mark_node
)
6041 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
6047 /* These are the Hashtable callback functions. */
6049 /* Returns true iff the types are equivalent. */
6052 type_hash_eq (const void *va
, const void *vb
)
6054 const struct type_hash
*const a
= (const struct type_hash
*) va
,
6055 *const b
= (const struct type_hash
*) vb
;
6057 /* First test the things that are the same for all types. */
6058 if (a
->hash
!= b
->hash
6059 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6060 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6061 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6062 TYPE_ATTRIBUTES (b
->type
))
6063 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6064 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6067 /* Be careful about comparing arrays before and after the element type
6068 has been completed; don't compare TYPE_ALIGN unless both types are
6070 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6071 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6072 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6075 switch (TREE_CODE (a
->type
))
6080 case REFERENCE_TYPE
:
6084 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6087 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6088 && !(TYPE_VALUES (a
->type
)
6089 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6090 && TYPE_VALUES (b
->type
)
6091 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6092 && type_list_equal (TYPE_VALUES (a
->type
),
6093 TYPE_VALUES (b
->type
))))
6096 /* ... fall through ... */
6101 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6102 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6103 TYPE_MAX_VALUE (b
->type
)))
6104 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6105 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6106 TYPE_MIN_VALUE (b
->type
))));
6108 case FIXED_POINT_TYPE
:
6109 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6112 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6115 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6116 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6117 || (TYPE_ARG_TYPES (a
->type
)
6118 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6119 && TYPE_ARG_TYPES (b
->type
)
6120 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6121 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6122 TYPE_ARG_TYPES (b
->type
)))))
6126 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6130 case QUAL_UNION_TYPE
:
6131 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6132 || (TYPE_FIELDS (a
->type
)
6133 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6134 && TYPE_FIELDS (b
->type
)
6135 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6136 && type_list_equal (TYPE_FIELDS (a
->type
),
6137 TYPE_FIELDS (b
->type
))));
6140 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6141 || (TYPE_ARG_TYPES (a
->type
)
6142 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6143 && TYPE_ARG_TYPES (b
->type
)
6144 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6145 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6146 TYPE_ARG_TYPES (b
->type
))))
6154 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6155 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6160 /* Return the cached hash value. */
6163 type_hash_hash (const void *item
)
6165 return ((const struct type_hash
*) item
)->hash
;
6168 /* Look in the type hash table for a type isomorphic to TYPE.
6169 If one is found, return it. Otherwise return 0. */
6172 type_hash_lookup (hashval_t hashcode
, tree type
)
6174 struct type_hash
*h
, in
;
6176 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6177 must call that routine before comparing TYPE_ALIGNs. */
6183 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
6190 /* Add an entry to the type-hash-table
6191 for a type TYPE whose hash code is HASHCODE. */
6194 type_hash_add (hashval_t hashcode
, tree type
)
6196 struct type_hash
*h
;
6199 h
= ggc_alloc_type_hash ();
6202 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
6206 /* Given TYPE, and HASHCODE its hash code, return the canonical
6207 object for an identical type if one already exists.
6208 Otherwise, return TYPE, and record it as the canonical object.
6210 To use this function, first create a type of the sort you want.
6211 Then compute its hash code from the fields of the type that
6212 make it different from other similar types.
6213 Then call this function and use the value. */
6216 type_hash_canon (unsigned int hashcode
, tree type
)
6220 /* The hash table only contains main variants, so ensure that's what we're
6222 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6224 /* See if the type is in the hash table already. If so, return it.
6225 Otherwise, add the type. */
6226 t1
= type_hash_lookup (hashcode
, type
);
6229 #ifdef GATHER_STATISTICS
6230 tree_node_counts
[(int) t_kind
]--;
6231 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
6237 type_hash_add (hashcode
, type
);
6242 /* See if the data pointed to by the type hash table is marked. We consider
6243 it marked if the type is marked or if a debug type number or symbol
6244 table entry has been made for the type. */
6247 type_hash_marked_p (const void *p
)
6249 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
6251 return ggc_marked_p (type
);
6255 print_type_hash_statistics (void)
6257 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6258 (long) htab_size (type_hash_table
),
6259 (long) htab_elements (type_hash_table
),
6260 htab_collisions (type_hash_table
));
6263 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6264 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6265 by adding the hash codes of the individual attributes. */
6268 attribute_hash_list (const_tree list
, hashval_t hashcode
)
6272 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6273 /* ??? Do we want to add in TREE_VALUE too? */
6274 hashcode
= iterative_hash_object
6275 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
6279 /* Given two lists of attributes, return true if list l2 is
6280 equivalent to l1. */
6283 attribute_list_equal (const_tree l1
, const_tree l2
)
6285 return attribute_list_contained (l1
, l2
)
6286 && attribute_list_contained (l2
, l1
);
6289 /* Given two lists of attributes, return true if list L2 is
6290 completely contained within L1. */
6291 /* ??? This would be faster if attribute names were stored in a canonicalized
6292 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6293 must be used to show these elements are equivalent (which they are). */
6294 /* ??? It's not clear that attributes with arguments will always be handled
6298 attribute_list_contained (const_tree l1
, const_tree l2
)
6302 /* First check the obvious, maybe the lists are identical. */
6306 /* Maybe the lists are similar. */
6307 for (t1
= l1
, t2
= l2
;
6309 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
6310 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
6311 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
6313 /* Maybe the lists are equal. */
6314 if (t1
== 0 && t2
== 0)
6317 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
6320 /* This CONST_CAST is okay because lookup_attribute does not
6321 modify its argument and the return value is assigned to a
6323 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
6324 CONST_CAST_TREE(l1
));
6325 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
6326 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
6330 if (attr
== NULL_TREE
)
6337 /* Given two lists of types
6338 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6339 return 1 if the lists contain the same types in the same order.
6340 Also, the TREE_PURPOSEs must match. */
6343 type_list_equal (const_tree l1
, const_tree l2
)
6347 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6348 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6349 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6350 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6351 && (TREE_TYPE (TREE_PURPOSE (t1
))
6352 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6358 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6359 given by TYPE. If the argument list accepts variable arguments,
6360 then this function counts only the ordinary arguments. */
6363 type_num_arguments (const_tree type
)
6368 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
6369 /* If the function does not take a variable number of arguments,
6370 the last element in the list will have type `void'. */
6371 if (VOID_TYPE_P (TREE_VALUE (t
)))
6379 /* Nonzero if integer constants T1 and T2
6380 represent the same constant value. */
6383 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6388 if (t1
== 0 || t2
== 0)
6391 if (TREE_CODE (t1
) == INTEGER_CST
6392 && TREE_CODE (t2
) == INTEGER_CST
6393 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6394 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
6400 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6401 The precise way of comparison depends on their data type. */
6404 tree_int_cst_lt (const_tree t1
, const_tree t2
)
6409 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
6411 int t1_sgn
= tree_int_cst_sgn (t1
);
6412 int t2_sgn
= tree_int_cst_sgn (t2
);
6414 if (t1_sgn
< t2_sgn
)
6416 else if (t1_sgn
> t2_sgn
)
6418 /* Otherwise, both are non-negative, so we compare them as
6419 unsigned just in case one of them would overflow a signed
6422 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
6423 return INT_CST_LT (t1
, t2
);
6425 return INT_CST_LT_UNSIGNED (t1
, t2
);
6428 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6431 tree_int_cst_compare (const_tree t1
, const_tree t2
)
6433 if (tree_int_cst_lt (t1
, t2
))
6435 else if (tree_int_cst_lt (t2
, t1
))
6441 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6442 the host. If POS is zero, the value can be represented in a single
6443 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6444 be represented in a single unsigned HOST_WIDE_INT. */
6447 host_integerp (const_tree t
, int pos
)
6452 return (TREE_CODE (t
) == INTEGER_CST
6453 && ((TREE_INT_CST_HIGH (t
) == 0
6454 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
6455 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
6456 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
6457 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
6458 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
6459 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
6460 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
6463 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6464 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6465 be non-negative. We must be able to satisfy the above conditions. */
6468 tree_low_cst (const_tree t
, int pos
)
6470 gcc_assert (host_integerp (t
, pos
));
6471 return TREE_INT_CST_LOW (t
);
6474 /* Return the most significant bit of the integer constant T. */
6477 tree_int_cst_msb (const_tree t
)
6481 unsigned HOST_WIDE_INT l
;
6483 /* Note that using TYPE_PRECISION here is wrong. We care about the
6484 actual bits, not the (arbitrary) range of the type. */
6485 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
6486 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
6487 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
6488 return (l
& 1) == 1;
6491 /* Return an indication of the sign of the integer constant T.
6492 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6493 Note that -1 will never be returned if T's type is unsigned. */
6496 tree_int_cst_sgn (const_tree t
)
6498 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
6500 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6502 else if (TREE_INT_CST_HIGH (t
) < 0)
6508 /* Return the minimum number of bits needed to represent VALUE in a
6509 signed or unsigned type, UNSIGNEDP says which. */
6512 tree_int_cst_min_precision (tree value
, bool unsignedp
)
6516 /* If the value is negative, compute its negative minus 1. The latter
6517 adjustment is because the absolute value of the largest negative value
6518 is one larger than the largest positive value. This is equivalent to
6519 a bit-wise negation, so use that operation instead. */
6521 if (tree_int_cst_sgn (value
) < 0)
6522 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
6524 /* Return the number of bits needed, taking into account the fact
6525 that we need one more bit for a signed than unsigned type. */
6527 if (integer_zerop (value
))
6530 log
= tree_floor_log2 (value
);
6532 return log
+ 1 + !unsignedp
;
6535 /* Compare two constructor-element-type constants. Return 1 if the lists
6536 are known to be equal; otherwise return 0. */
6539 simple_cst_list_equal (const_tree l1
, const_tree l2
)
6541 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
6543 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
6546 l1
= TREE_CHAIN (l1
);
6547 l2
= TREE_CHAIN (l2
);
6553 /* Return truthvalue of whether T1 is the same tree structure as T2.
6554 Return 1 if they are the same.
6555 Return 0 if they are understandably different.
6556 Return -1 if either contains tree structure not understood by
6560 simple_cst_equal (const_tree t1
, const_tree t2
)
6562 enum tree_code code1
, code2
;
6568 if (t1
== 0 || t2
== 0)
6571 code1
= TREE_CODE (t1
);
6572 code2
= TREE_CODE (t2
);
6574 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
6576 if (CONVERT_EXPR_CODE_P (code2
)
6577 || code2
== NON_LVALUE_EXPR
)
6578 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6580 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
6583 else if (CONVERT_EXPR_CODE_P (code2
)
6584 || code2
== NON_LVALUE_EXPR
)
6585 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
6593 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6594 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
6597 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
6600 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
6603 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
6604 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
6605 TREE_STRING_LENGTH (t1
)));
6609 unsigned HOST_WIDE_INT idx
;
6610 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
6611 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
6613 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
6616 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
6617 /* ??? Should we handle also fields here? */
6618 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
6619 VEC_index (constructor_elt
, v2
, idx
)->value
))
6625 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6628 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
6631 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
6634 const_tree arg1
, arg2
;
6635 const_call_expr_arg_iterator iter1
, iter2
;
6636 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
6637 arg2
= first_const_call_expr_arg (t2
, &iter2
);
6639 arg1
= next_const_call_expr_arg (&iter1
),
6640 arg2
= next_const_call_expr_arg (&iter2
))
6642 cmp
= simple_cst_equal (arg1
, arg2
);
6646 return arg1
== arg2
;
6650 /* Special case: if either target is an unallocated VAR_DECL,
6651 it means that it's going to be unified with whatever the
6652 TARGET_EXPR is really supposed to initialize, so treat it
6653 as being equivalent to anything. */
6654 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
6655 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
6656 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
6657 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
6658 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
6659 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
6662 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6667 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
6669 case WITH_CLEANUP_EXPR
:
6670 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6674 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
6677 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
6678 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6692 /* This general rule works for most tree codes. All exceptions should be
6693 handled above. If this is a language-specific tree code, we can't
6694 trust what might be in the operand, so say we don't know
6696 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
6699 switch (TREE_CODE_CLASS (code1
))
6703 case tcc_comparison
:
6704 case tcc_expression
:
6708 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
6710 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
6722 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6723 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6724 than U, respectively. */
6727 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
6729 if (tree_int_cst_sgn (t
) < 0)
6731 else if (TREE_INT_CST_HIGH (t
) != 0)
6733 else if (TREE_INT_CST_LOW (t
) == u
)
6735 else if (TREE_INT_CST_LOW (t
) < u
)
6741 /* Return true if CODE represents an associative tree code. Otherwise
6744 associative_tree_code (enum tree_code code
)
6763 /* Return true if CODE represents a commutative tree code. Otherwise
6766 commutative_tree_code (enum tree_code code
)
6779 case UNORDERED_EXPR
:
6783 case TRUTH_AND_EXPR
:
6784 case TRUTH_XOR_EXPR
:
6794 /* Return true if CODE represents a ternary tree code for which the
6795 first two operands are commutative. Otherwise return false. */
6797 commutative_ternary_tree_code (enum tree_code code
)
6801 case WIDEN_MULT_PLUS_EXPR
:
6802 case WIDEN_MULT_MINUS_EXPR
:
6811 /* Generate a hash value for an expression. This can be used iteratively
6812 by passing a previous result as the VAL argument.
6814 This function is intended to produce the same hash for expressions which
6815 would compare equal using operand_equal_p. */
6818 iterative_hash_expr (const_tree t
, hashval_t val
)
6821 enum tree_code code
;
6825 return iterative_hash_hashval_t (0, val
);
6827 code
= TREE_CODE (t
);
6831 /* Alas, constants aren't shared, so we can't rely on pointer
6834 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
6835 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
6838 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
6840 return iterative_hash_hashval_t (val2
, val
);
6844 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
6846 return iterative_hash_hashval_t (val2
, val
);
6849 return iterative_hash (TREE_STRING_POINTER (t
),
6850 TREE_STRING_LENGTH (t
), val
);
6852 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
6853 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
6855 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
6857 /* We can just compare by pointer. */
6858 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
6859 case PLACEHOLDER_EXPR
:
6860 /* The node itself doesn't matter. */
6863 /* A list of expressions, for a CALL_EXPR or as the elements of a
6865 for (; t
; t
= TREE_CHAIN (t
))
6866 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
6870 unsigned HOST_WIDE_INT idx
;
6872 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
6874 val
= iterative_hash_expr (field
, val
);
6875 val
= iterative_hash_expr (value
, val
);
6881 /* The type of the second operand is relevant, except for
6882 its top-level qualifiers. */
6883 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t
, 1)));
6885 val
= iterative_hash_object (TYPE_HASH (type
), val
);
6887 /* We could use the standard hash computation from this point
6889 val
= iterative_hash_object (code
, val
);
6890 val
= iterative_hash_expr (TREE_OPERAND (t
, 1), val
);
6891 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
6895 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
6896 Otherwise nodes that compare equal according to operand_equal_p might
6897 get different hash codes. However, don't do this for machine specific
6898 or front end builtins, since the function code is overloaded in those
6900 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
6901 && built_in_decls
[DECL_FUNCTION_CODE (t
)])
6903 t
= built_in_decls
[DECL_FUNCTION_CODE (t
)];
6904 code
= TREE_CODE (t
);
6908 tclass
= TREE_CODE_CLASS (code
);
6910 if (tclass
== tcc_declaration
)
6912 /* DECL's have a unique ID */
6913 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
6917 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
6919 val
= iterative_hash_object (code
, val
);
6921 /* Don't hash the type, that can lead to having nodes which
6922 compare equal according to operand_equal_p, but which
6923 have different hash codes. */
6924 if (CONVERT_EXPR_CODE_P (code
)
6925 || code
== NON_LVALUE_EXPR
)
6927 /* Make sure to include signness in the hash computation. */
6928 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
6929 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
6932 else if (commutative_tree_code (code
))
6934 /* It's a commutative expression. We want to hash it the same
6935 however it appears. We do this by first hashing both operands
6936 and then rehashing based on the order of their independent
6938 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
6939 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
6943 t
= one
, one
= two
, two
= t
;
6945 val
= iterative_hash_hashval_t (one
, val
);
6946 val
= iterative_hash_hashval_t (two
, val
);
6949 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
6950 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
6957 /* Generate a hash value for a pair of expressions. This can be used
6958 iteratively by passing a previous result as the VAL argument.
6960 The same hash value is always returned for a given pair of expressions,
6961 regardless of the order in which they are presented. This is useful in
6962 hashing the operands of commutative functions. */
6965 iterative_hash_exprs_commutative (const_tree t1
,
6966 const_tree t2
, hashval_t val
)
6968 hashval_t one
= iterative_hash_expr (t1
, 0);
6969 hashval_t two
= iterative_hash_expr (t2
, 0);
6973 t
= one
, one
= two
, two
= t
;
6974 val
= iterative_hash_hashval_t (one
, val
);
6975 val
= iterative_hash_hashval_t (two
, val
);
6980 /* Constructors for pointer, array and function types.
6981 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
6982 constructed by language-dependent code, not here.) */
6984 /* Construct, lay out and return the type of pointers to TO_TYPE with
6985 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
6986 reference all of memory. If such a type has already been
6987 constructed, reuse it. */
6990 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
6995 if (to_type
== error_mark_node
)
6996 return error_mark_node
;
6998 /* If the pointed-to type has the may_alias attribute set, force
6999 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7000 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7001 can_alias_all
= true;
7003 /* In some cases, languages will have things that aren't a POINTER_TYPE
7004 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7005 In that case, return that type without regard to the rest of our
7008 ??? This is a kludge, but consistent with the way this function has
7009 always operated and there doesn't seem to be a good way to avoid this
7011 if (TYPE_POINTER_TO (to_type
) != 0
7012 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7013 return TYPE_POINTER_TO (to_type
);
7015 /* First, if we already have a type for pointers to TO_TYPE and it's
7016 the proper mode, use it. */
7017 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7018 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7021 t
= make_node (POINTER_TYPE
);
7023 TREE_TYPE (t
) = to_type
;
7024 SET_TYPE_MODE (t
, mode
);
7025 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7026 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7027 TYPE_POINTER_TO (to_type
) = t
;
7029 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7030 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7031 else if (TYPE_CANONICAL (to_type
) != to_type
)
7033 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7034 mode
, can_alias_all
);
7036 /* Lay out the type. This function has many callers that are concerned
7037 with expression-construction, and this simplifies them all. */
7043 /* By default build pointers in ptr_mode. */
7046 build_pointer_type (tree to_type
)
7048 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7049 : TYPE_ADDR_SPACE (to_type
);
7050 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7051 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7054 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7057 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
7062 if (to_type
== error_mark_node
)
7063 return error_mark_node
;
7065 /* If the pointed-to type has the may_alias attribute set, force
7066 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7067 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7068 can_alias_all
= true;
7070 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7071 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7072 In that case, return that type without regard to the rest of our
7075 ??? This is a kludge, but consistent with the way this function has
7076 always operated and there doesn't seem to be a good way to avoid this
7078 if (TYPE_REFERENCE_TO (to_type
) != 0
7079 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7080 return TYPE_REFERENCE_TO (to_type
);
7082 /* First, if we already have a type for pointers to TO_TYPE and it's
7083 the proper mode, use it. */
7084 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7085 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7088 t
= make_node (REFERENCE_TYPE
);
7090 TREE_TYPE (t
) = to_type
;
7091 SET_TYPE_MODE (t
, mode
);
7092 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7093 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7094 TYPE_REFERENCE_TO (to_type
) = t
;
7096 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7097 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7098 else if (TYPE_CANONICAL (to_type
) != to_type
)
7100 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7101 mode
, can_alias_all
);
7109 /* Build the node for the type of references-to-TO_TYPE by default
7113 build_reference_type (tree to_type
)
7115 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7116 : TYPE_ADDR_SPACE (to_type
);
7117 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7118 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7121 /* Build a type that is compatible with t but has no cv quals anywhere
7124 const char *const *const * -> char ***. */
7127 build_type_no_quals (tree t
)
7129 switch (TREE_CODE (t
))
7132 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7134 TYPE_REF_CAN_ALIAS_ALL (t
));
7135 case REFERENCE_TYPE
:
7137 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7139 TYPE_REF_CAN_ALIAS_ALL (t
));
7141 return TYPE_MAIN_VARIANT (t
);
7145 #define MAX_INT_CACHED_PREC \
7146 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7147 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7149 /* Builds a signed or unsigned integer type of precision PRECISION.
7150 Used for C bitfields whose precision does not match that of
7151 built-in target types. */
7153 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7159 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7161 if (precision
<= MAX_INT_CACHED_PREC
)
7163 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7168 itype
= make_node (INTEGER_TYPE
);
7169 TYPE_PRECISION (itype
) = precision
;
7172 fixup_unsigned_type (itype
);
7174 fixup_signed_type (itype
);
7177 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
7178 ret
= type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
7179 if (precision
<= MAX_INT_CACHED_PREC
)
7180 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7185 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7186 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7187 is true, reuse such a type that has already been constructed. */
7190 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7192 tree itype
= make_node (INTEGER_TYPE
);
7193 hashval_t hashcode
= 0;
7195 TREE_TYPE (itype
) = type
;
7197 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7198 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7200 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7201 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7202 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7203 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7204 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
7205 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7210 if ((TYPE_MIN_VALUE (itype
)
7211 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7212 || (TYPE_MAX_VALUE (itype
)
7213 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7215 /* Since we cannot reliably merge this type, we need to compare it using
7216 structural equality checks. */
7217 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7221 hashcode
= iterative_hash_expr (TYPE_MIN_VALUE (itype
), hashcode
);
7222 hashcode
= iterative_hash_expr (TYPE_MAX_VALUE (itype
), hashcode
);
7223 hashcode
= iterative_hash_hashval_t (TYPE_HASH (type
), hashcode
);
7224 itype
= type_hash_canon (hashcode
, itype
);
7229 /* Wrapper around build_range_type_1 with SHARED set to true. */
7232 build_range_type (tree type
, tree lowval
, tree highval
)
7234 return build_range_type_1 (type
, lowval
, highval
, true);
7237 /* Wrapper around build_range_type_1 with SHARED set to false. */
7240 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7242 return build_range_type_1 (type
, lowval
, highval
, false);
7245 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7246 MAXVAL should be the maximum value in the domain
7247 (one less than the length of the array).
7249 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7250 We don't enforce this limit, that is up to caller (e.g. language front end).
7251 The limit exists because the result is a signed type and we don't handle
7252 sizes that use more than one HOST_WIDE_INT. */
7255 build_index_type (tree maxval
)
7257 return build_range_type (sizetype
, size_zero_node
, maxval
);
7260 /* Return true if the debug information for TYPE, a subtype, should be emitted
7261 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7262 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7263 debug info and doesn't reflect the source code. */
7266 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7268 tree base_type
= TREE_TYPE (type
), low
, high
;
7270 /* Subrange types have a base type which is an integral type. */
7271 if (!INTEGRAL_TYPE_P (base_type
))
7274 /* Get the real bounds of the subtype. */
7275 if (lang_hooks
.types
.get_subrange_bounds
)
7276 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7279 low
= TYPE_MIN_VALUE (type
);
7280 high
= TYPE_MAX_VALUE (type
);
7283 /* If the type and its base type have the same representation and the same
7284 name, then the type is not a subrange but a copy of the base type. */
7285 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7286 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7287 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7288 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7289 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
7291 tree type_name
= TYPE_NAME (type
);
7292 tree base_type_name
= TYPE_NAME (base_type
);
7294 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
7295 type_name
= DECL_NAME (type_name
);
7297 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
7298 base_type_name
= DECL_NAME (base_type_name
);
7300 if (type_name
== base_type_name
)
7311 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7312 and number of elements specified by the range of values of INDEX_TYPE.
7313 If SHARED is true, reuse such a type that has already been constructed. */
7316 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
7320 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7322 error ("arrays of functions are not meaningful");
7323 elt_type
= integer_type_node
;
7326 t
= make_node (ARRAY_TYPE
);
7327 TREE_TYPE (t
) = elt_type
;
7328 TYPE_DOMAIN (t
) = index_type
;
7329 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7332 /* If the element type is incomplete at this point we get marked for
7333 structural equality. Do not record these types in the canonical
7335 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
7340 hashval_t hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), 0);
7342 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
7343 t
= type_hash_canon (hashcode
, t
);
7346 if (TYPE_CANONICAL (t
) == t
)
7348 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7349 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
7350 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7351 else if (TYPE_CANONICAL (elt_type
) != elt_type
7352 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7354 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7356 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7363 /* Wrapper around build_array_type_1 with SHARED set to true. */
7366 build_array_type (tree elt_type
, tree index_type
)
7368 return build_array_type_1 (elt_type
, index_type
, true);
7371 /* Wrapper around build_array_type_1 with SHARED set to false. */
7374 build_nonshared_array_type (tree elt_type
, tree index_type
)
7376 return build_array_type_1 (elt_type
, index_type
, false);
7379 /* Recursively examines the array elements of TYPE, until a non-array
7380 element type is found. */
7383 strip_array_types (tree type
)
7385 while (TREE_CODE (type
) == ARRAY_TYPE
)
7386 type
= TREE_TYPE (type
);
7391 /* Computes the canonical argument types from the argument type list
7394 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7395 on entry to this function, or if any of the ARGTYPES are
7398 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7399 true on entry to this function, or if any of the ARGTYPES are
7402 Returns a canonical argument list, which may be ARGTYPES when the
7403 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7404 true) or would not differ from ARGTYPES. */
7407 maybe_canonicalize_argtypes(tree argtypes
,
7408 bool *any_structural_p
,
7409 bool *any_noncanonical_p
)
7412 bool any_noncanonical_argtypes_p
= false;
7414 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7416 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7417 /* Fail gracefully by stating that the type is structural. */
7418 *any_structural_p
= true;
7419 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7420 *any_structural_p
= true;
7421 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7422 || TREE_PURPOSE (arg
))
7423 /* If the argument has a default argument, we consider it
7424 non-canonical even though the type itself is canonical.
7425 That way, different variants of function and method types
7426 with default arguments will all point to the variant with
7427 no defaults as their canonical type. */
7428 any_noncanonical_argtypes_p
= true;
7431 if (*any_structural_p
)
7434 if (any_noncanonical_argtypes_p
)
7436 /* Build the canonical list of argument types. */
7437 tree canon_argtypes
= NULL_TREE
;
7438 bool is_void
= false;
7440 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7442 if (arg
== void_list_node
)
7445 canon_argtypes
= tree_cons (NULL_TREE
,
7446 TYPE_CANONICAL (TREE_VALUE (arg
)),
7450 canon_argtypes
= nreverse (canon_argtypes
);
7452 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7454 /* There is a non-canonical type. */
7455 *any_noncanonical_p
= true;
7456 return canon_argtypes
;
7459 /* The canonical argument types are the same as ARGTYPES. */
7463 /* Construct, lay out and return
7464 the type of functions returning type VALUE_TYPE
7465 given arguments of types ARG_TYPES.
7466 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7467 are data type nodes for the arguments of the function.
7468 If such a type has already been constructed, reuse it. */
7471 build_function_type (tree value_type
, tree arg_types
)
7474 hashval_t hashcode
= 0;
7475 bool any_structural_p
, any_noncanonical_p
;
7476 tree canon_argtypes
;
7478 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
7480 error ("function return type cannot be function");
7481 value_type
= integer_type_node
;
7484 /* Make a node of the sort we want. */
7485 t
= make_node (FUNCTION_TYPE
);
7486 TREE_TYPE (t
) = value_type
;
7487 TYPE_ARG_TYPES (t
) = arg_types
;
7489 /* If we already have such a type, use the old one. */
7490 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
7491 hashcode
= type_hash_list (arg_types
, hashcode
);
7492 t
= type_hash_canon (hashcode
, t
);
7494 /* Set up the canonical type. */
7495 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
7496 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
7497 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
7499 &any_noncanonical_p
);
7500 if (any_structural_p
)
7501 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7502 else if (any_noncanonical_p
)
7503 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
7506 if (!COMPLETE_TYPE_P (t
))
7511 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
7514 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
)
7516 tree new_type
= NULL
;
7517 tree args
, new_args
= NULL
, t
;
7521 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
7522 args
= TREE_CHAIN (args
), i
++)
7523 if (!bitmap_bit_p (args_to_skip
, i
))
7524 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
7526 new_reversed
= nreverse (new_args
);
7530 TREE_CHAIN (new_args
) = void_list_node
;
7532 new_reversed
= void_list_node
;
7535 /* Use copy_node to preserve as much as possible from original type
7536 (debug info, attribute lists etc.)
7537 Exception is METHOD_TYPEs must have THIS argument.
7538 When we are asked to remove it, we need to build new FUNCTION_TYPE
7540 if (TREE_CODE (orig_type
) != METHOD_TYPE
7541 || !bitmap_bit_p (args_to_skip
, 0))
7543 new_type
= build_distinct_type_copy (orig_type
);
7544 TYPE_ARG_TYPES (new_type
) = new_reversed
;
7549 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
7551 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
7554 /* This is a new type, not a copy of an old type. Need to reassociate
7555 variants. We can handle everything except the main variant lazily. */
7556 t
= TYPE_MAIN_VARIANT (orig_type
);
7559 TYPE_MAIN_VARIANT (new_type
) = t
;
7560 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
7561 TYPE_NEXT_VARIANT (t
) = new_type
;
7565 TYPE_MAIN_VARIANT (new_type
) = new_type
;
7566 TYPE_NEXT_VARIANT (new_type
) = NULL
;
7571 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
7573 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
7574 linked by TREE_CHAIN directly. The caller is responsible for eliminating
7575 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
7578 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
)
7580 tree new_decl
= copy_node (orig_decl
);
7583 new_type
= TREE_TYPE (orig_decl
);
7584 if (prototype_p (new_type
))
7585 new_type
= build_function_type_skip_args (new_type
, args_to_skip
);
7586 TREE_TYPE (new_decl
) = new_type
;
7588 /* For declarations setting DECL_VINDEX (i.e. methods)
7589 we expect first argument to be THIS pointer. */
7590 if (bitmap_bit_p (args_to_skip
, 0))
7591 DECL_VINDEX (new_decl
) = NULL_TREE
;
7593 /* When signature changes, we need to clear builtin info. */
7594 if (DECL_BUILT_IN (new_decl
) && !bitmap_empty_p (args_to_skip
))
7596 DECL_BUILT_IN_CLASS (new_decl
) = NOT_BUILT_IN
;
7597 DECL_FUNCTION_CODE (new_decl
) = (enum built_in_function
) 0;
7602 /* Build a function type. The RETURN_TYPE is the type returned by the
7603 function. If VAARGS is set, no void_type_node is appended to the
7604 the list. ARGP must be always be terminated be a NULL_TREE. */
7607 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
7611 t
= va_arg (argp
, tree
);
7612 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
7613 args
= tree_cons (NULL_TREE
, t
, args
);
7618 if (args
!= NULL_TREE
)
7619 args
= nreverse (args
);
7620 gcc_assert (last
!= void_list_node
);
7622 else if (args
== NULL_TREE
)
7623 args
= void_list_node
;
7627 args
= nreverse (args
);
7628 TREE_CHAIN (last
) = void_list_node
;
7630 args
= build_function_type (return_type
, args
);
7635 /* Build a function type. The RETURN_TYPE is the type returned by the
7636 function. If additional arguments are provided, they are
7637 additional argument types. The list of argument types must always
7638 be terminated by NULL_TREE. */
7641 build_function_type_list (tree return_type
, ...)
7646 va_start (p
, return_type
);
7647 args
= build_function_type_list_1 (false, return_type
, p
);
7652 /* Build a variable argument function type. The RETURN_TYPE is the
7653 type returned by the function. If additional arguments are provided,
7654 they are additional argument types. The list of argument types must
7655 always be terminated by NULL_TREE. */
7658 build_varargs_function_type_list (tree return_type
, ...)
7663 va_start (p
, return_type
);
7664 args
= build_function_type_list_1 (true, return_type
, p
);
7670 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7671 and ARGTYPES (a TREE_LIST) are the return type and arguments types
7672 for the method. An implicit additional parameter (of type
7673 pointer-to-BASETYPE) is added to the ARGTYPES. */
7676 build_method_type_directly (tree basetype
,
7683 bool any_structural_p
, any_noncanonical_p
;
7684 tree canon_argtypes
;
7686 /* Make a node of the sort we want. */
7687 t
= make_node (METHOD_TYPE
);
7689 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7690 TREE_TYPE (t
) = rettype
;
7691 ptype
= build_pointer_type (basetype
);
7693 /* The actual arglist for this function includes a "hidden" argument
7694 which is "this". Put it into the list of argument types. */
7695 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
7696 TYPE_ARG_TYPES (t
) = argtypes
;
7698 /* If we already have such a type, use the old one. */
7699 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
7700 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
7701 hashcode
= type_hash_list (argtypes
, hashcode
);
7702 t
= type_hash_canon (hashcode
, t
);
7704 /* Set up the canonical type. */
7706 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7707 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
7709 = (TYPE_CANONICAL (basetype
) != basetype
7710 || TYPE_CANONICAL (rettype
) != rettype
);
7711 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
7713 &any_noncanonical_p
);
7714 if (any_structural_p
)
7715 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7716 else if (any_noncanonical_p
)
7718 = build_method_type_directly (TYPE_CANONICAL (basetype
),
7719 TYPE_CANONICAL (rettype
),
7721 if (!COMPLETE_TYPE_P (t
))
7727 /* Construct, lay out and return the type of methods belonging to class
7728 BASETYPE and whose arguments and values are described by TYPE.
7729 If that type exists already, reuse it.
7730 TYPE must be a FUNCTION_TYPE node. */
7733 build_method_type (tree basetype
, tree type
)
7735 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
7737 return build_method_type_directly (basetype
,
7739 TYPE_ARG_TYPES (type
));
7742 /* Construct, lay out and return the type of offsets to a value
7743 of type TYPE, within an object of type BASETYPE.
7744 If a suitable offset type exists already, reuse it. */
7747 build_offset_type (tree basetype
, tree type
)
7750 hashval_t hashcode
= 0;
7752 /* Make a node of the sort we want. */
7753 t
= make_node (OFFSET_TYPE
);
7755 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
7756 TREE_TYPE (t
) = type
;
7758 /* If we already have such a type, use the old one. */
7759 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
7760 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
7761 t
= type_hash_canon (hashcode
, t
);
7763 if (!COMPLETE_TYPE_P (t
))
7766 if (TYPE_CANONICAL (t
) == t
)
7768 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
7769 || TYPE_STRUCTURAL_EQUALITY_P (type
))
7770 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7771 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
7772 || TYPE_CANONICAL (type
) != type
)
7774 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
7775 TYPE_CANONICAL (type
));
7781 /* Create a complex type whose components are COMPONENT_TYPE. */
7784 build_complex_type (tree component_type
)
7789 gcc_assert (INTEGRAL_TYPE_P (component_type
)
7790 || SCALAR_FLOAT_TYPE_P (component_type
)
7791 || FIXED_POINT_TYPE_P (component_type
));
7793 /* Make a node of the sort we want. */
7794 t
= make_node (COMPLEX_TYPE
);
7796 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
7798 /* If we already have such a type, use the old one. */
7799 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
7800 t
= type_hash_canon (hashcode
, t
);
7802 if (!COMPLETE_TYPE_P (t
))
7805 if (TYPE_CANONICAL (t
) == t
)
7807 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
7808 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7809 else if (TYPE_CANONICAL (component_type
) != component_type
)
7811 = build_complex_type (TYPE_CANONICAL (component_type
));
7814 /* We need to create a name, since complex is a fundamental type. */
7815 if (! TYPE_NAME (t
))
7818 if (component_type
== char_type_node
)
7819 name
= "complex char";
7820 else if (component_type
== signed_char_type_node
)
7821 name
= "complex signed char";
7822 else if (component_type
== unsigned_char_type_node
)
7823 name
= "complex unsigned char";
7824 else if (component_type
== short_integer_type_node
)
7825 name
= "complex short int";
7826 else if (component_type
== short_unsigned_type_node
)
7827 name
= "complex short unsigned int";
7828 else if (component_type
== integer_type_node
)
7829 name
= "complex int";
7830 else if (component_type
== unsigned_type_node
)
7831 name
= "complex unsigned int";
7832 else if (component_type
== long_integer_type_node
)
7833 name
= "complex long int";
7834 else if (component_type
== long_unsigned_type_node
)
7835 name
= "complex long unsigned int";
7836 else if (component_type
== long_long_integer_type_node
)
7837 name
= "complex long long int";
7838 else if (component_type
== long_long_unsigned_type_node
)
7839 name
= "complex long long unsigned int";
7844 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
7845 get_identifier (name
), t
);
7848 return build_qualified_type (t
, TYPE_QUALS (component_type
));
7851 /* If TYPE is a real or complex floating-point type and the target
7852 does not directly support arithmetic on TYPE then return the wider
7853 type to be used for arithmetic on TYPE. Otherwise, return
7857 excess_precision_type (tree type
)
7859 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
7861 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
7862 switch (TREE_CODE (type
))
7865 switch (flt_eval_method
)
7868 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
7869 return double_type_node
;
7872 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
7873 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
7874 return long_double_type_node
;
7881 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
7883 switch (flt_eval_method
)
7886 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
7887 return complex_double_type_node
;
7890 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
7891 || (TYPE_MODE (TREE_TYPE (type
))
7892 == TYPE_MODE (double_type_node
)))
7893 return complex_long_double_type_node
;
7906 /* Return OP, stripped of any conversions to wider types as much as is safe.
7907 Converting the value back to OP's type makes a value equivalent to OP.
7909 If FOR_TYPE is nonzero, we return a value which, if converted to
7910 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
7912 OP must have integer, real or enumeral type. Pointers are not allowed!
7914 There are some cases where the obvious value we could return
7915 would regenerate to OP if converted to OP's type,
7916 but would not extend like OP to wider types.
7917 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
7918 For example, if OP is (unsigned short)(signed char)-1,
7919 we avoid returning (signed char)-1 if FOR_TYPE is int,
7920 even though extending that to an unsigned short would regenerate OP,
7921 since the result of extending (signed char)-1 to (int)
7922 is different from (int) OP. */
7925 get_unwidened (tree op
, tree for_type
)
7927 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
7928 tree type
= TREE_TYPE (op
);
7930 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
7932 = (for_type
!= 0 && for_type
!= type
7933 && final_prec
> TYPE_PRECISION (type
)
7934 && TYPE_UNSIGNED (type
));
7937 while (CONVERT_EXPR_P (op
))
7941 /* TYPE_PRECISION on vector types has different meaning
7942 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
7943 so avoid them here. */
7944 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
7947 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
7948 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
7950 /* Truncations are many-one so cannot be removed.
7951 Unless we are later going to truncate down even farther. */
7953 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
7956 /* See what's inside this conversion. If we decide to strip it,
7958 op
= TREE_OPERAND (op
, 0);
7960 /* If we have not stripped any zero-extensions (uns is 0),
7961 we can strip any kind of extension.
7962 If we have previously stripped a zero-extension,
7963 only zero-extensions can safely be stripped.
7964 Any extension can be stripped if the bits it would produce
7965 are all going to be discarded later by truncating to FOR_TYPE. */
7969 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
7971 /* TYPE_UNSIGNED says whether this is a zero-extension.
7972 Let's avoid computing it if it does not affect WIN
7973 and if UNS will not be needed again. */
7975 || CONVERT_EXPR_P (op
))
7976 && TYPE_UNSIGNED (TREE_TYPE (op
)))
7984 /* If we finally reach a constant see if it fits in for_type and
7985 in that case convert it. */
7987 && TREE_CODE (win
) == INTEGER_CST
7988 && TREE_TYPE (win
) != for_type
7989 && int_fits_type_p (win
, for_type
))
7990 win
= fold_convert (for_type
, win
);
7995 /* Return OP or a simpler expression for a narrower value
7996 which can be sign-extended or zero-extended to give back OP.
7997 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
7998 or 0 if the value should be sign-extended. */
8001 get_narrower (tree op
, int *unsignedp_ptr
)
8006 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8008 while (TREE_CODE (op
) == NOP_EXPR
)
8011 = (TYPE_PRECISION (TREE_TYPE (op
))
8012 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8014 /* Truncations are many-one so cannot be removed. */
8018 /* See what's inside this conversion. If we decide to strip it,
8023 op
= TREE_OPERAND (op
, 0);
8024 /* An extension: the outermost one can be stripped,
8025 but remember whether it is zero or sign extension. */
8027 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8028 /* Otherwise, if a sign extension has been stripped,
8029 only sign extensions can now be stripped;
8030 if a zero extension has been stripped, only zero-extensions. */
8031 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8035 else /* bitschange == 0 */
8037 /* A change in nominal type can always be stripped, but we must
8038 preserve the unsignedness. */
8040 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8042 op
= TREE_OPERAND (op
, 0);
8043 /* Keep trying to narrow, but don't assign op to win if it
8044 would turn an integral type into something else. */
8045 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8052 if (TREE_CODE (op
) == COMPONENT_REF
8053 /* Since type_for_size always gives an integer type. */
8054 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8055 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8056 /* Ensure field is laid out already. */
8057 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8058 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
8060 unsigned HOST_WIDE_INT innerprec
8061 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
8062 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8063 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8064 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8066 /* We can get this structure field in a narrower type that fits it,
8067 but the resulting extension to its nominal type (a fullword type)
8068 must satisfy the same conditions as for other extensions.
8070 Do this only for fields that are aligned (not bit-fields),
8071 because when bit-field insns will be used there is no
8072 advantage in doing this. */
8074 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8075 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8076 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8080 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8081 win
= fold_convert (type
, op
);
8085 *unsignedp_ptr
= uns
;
8089 /* Returns true if integer constant C has a value that is permissible
8090 for type TYPE (an INTEGER_TYPE). */
8093 int_fits_type_p (const_tree c
, const_tree type
)
8095 tree type_low_bound
, type_high_bound
;
8096 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
8099 dc
= tree_to_double_int (c
);
8100 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
8102 if (TREE_CODE (TREE_TYPE (c
)) == INTEGER_TYPE
8103 && TYPE_IS_SIZETYPE (TREE_TYPE (c
))
8105 /* So c is an unsigned integer whose type is sizetype and type is not.
8106 sizetype'd integers are sign extended even though they are
8107 unsigned. If the integer value fits in the lower end word of c,
8108 and if the higher end word has all its bits set to 1, that
8109 means the higher end bits are set to 1 only for sign extension.
8110 So let's convert c into an equivalent zero extended unsigned
8112 dc
= double_int_zext (dc
, TYPE_PRECISION (TREE_TYPE (c
)));
8115 type_low_bound
= TYPE_MIN_VALUE (type
);
8116 type_high_bound
= TYPE_MAX_VALUE (type
);
8118 /* If at least one bound of the type is a constant integer, we can check
8119 ourselves and maybe make a decision. If no such decision is possible, but
8120 this type is a subtype, try checking against that. Otherwise, use
8121 double_int_fits_to_tree_p, which checks against the precision.
8123 Compute the status for each possibly constant bound, and return if we see
8124 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8125 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8126 for "constant known to fit". */
8128 /* Check if c >= type_low_bound. */
8129 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8131 dd
= tree_to_double_int (type_low_bound
);
8132 if (TREE_CODE (type
) == INTEGER_TYPE
8133 && TYPE_IS_SIZETYPE (type
)
8134 && TYPE_UNSIGNED (type
))
8135 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
8136 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
8138 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
8139 int t_neg
= (unsc
&& double_int_negative_p (dd
));
8141 if (c_neg
&& !t_neg
)
8143 if ((c_neg
|| !t_neg
) && double_int_ucmp (dc
, dd
) < 0)
8146 else if (double_int_cmp (dc
, dd
, unsc
) < 0)
8148 ok_for_low_bound
= true;
8151 ok_for_low_bound
= false;
8153 /* Check if c <= type_high_bound. */
8154 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8156 dd
= tree_to_double_int (type_high_bound
);
8157 if (TREE_CODE (type
) == INTEGER_TYPE
8158 && TYPE_IS_SIZETYPE (type
)
8159 && TYPE_UNSIGNED (type
))
8160 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
8161 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
8163 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
8164 int t_neg
= (unsc
&& double_int_negative_p (dd
));
8166 if (t_neg
&& !c_neg
)
8168 if ((t_neg
|| !c_neg
) && double_int_ucmp (dc
, dd
) > 0)
8171 else if (double_int_cmp (dc
, dd
, unsc
) > 0)
8173 ok_for_high_bound
= true;
8176 ok_for_high_bound
= false;
8178 /* If the constant fits both bounds, the result is known. */
8179 if (ok_for_low_bound
&& ok_for_high_bound
)
8182 /* Perform some generic filtering which may allow making a decision
8183 even if the bounds are not constant. First, negative integers
8184 never fit in unsigned types, */
8185 if (TYPE_UNSIGNED (type
) && !unsc
&& double_int_negative_p (dc
))
8188 /* Second, narrower types always fit in wider ones. */
8189 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8192 /* Third, unsigned integers with top bit set never fit signed types. */
8193 if (! TYPE_UNSIGNED (type
) && unsc
)
8195 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
8196 if (prec
< HOST_BITS_PER_WIDE_INT
)
8198 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
8201 else if (((((unsigned HOST_WIDE_INT
) 1)
8202 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
8206 /* If we haven't been able to decide at this point, there nothing more we
8207 can check ourselves here. Look at the base type if we have one and it
8208 has the same precision. */
8209 if (TREE_CODE (type
) == INTEGER_TYPE
8210 && TREE_TYPE (type
) != 0
8211 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8213 type
= TREE_TYPE (type
);
8217 /* Or to double_int_fits_to_tree_p, if nothing else. */
8218 return double_int_fits_to_tree_p (type
, dc
);
8221 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8222 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8223 represented (assuming two's-complement arithmetic) within the bit
8224 precision of the type are returned instead. */
8227 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8229 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8230 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8231 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
8232 TYPE_UNSIGNED (type
));
8235 if (TYPE_UNSIGNED (type
))
8236 mpz_set_ui (min
, 0);
8240 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
8241 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
8242 TYPE_PRECISION (type
));
8243 mpz_set_double_int (min
, mn
, false);
8247 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8248 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8249 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
8250 TYPE_UNSIGNED (type
));
8253 if (TYPE_UNSIGNED (type
))
8254 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
8257 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
8262 /* Return true if VAR is an automatic variable defined in function FN. */
8265 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8267 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8268 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8269 || TREE_CODE (var
) == PARM_DECL
)
8270 && ! TREE_STATIC (var
))
8271 || TREE_CODE (var
) == LABEL_DECL
8272 || TREE_CODE (var
) == RESULT_DECL
));
8275 /* Subprogram of following function. Called by walk_tree.
8277 Return *TP if it is an automatic variable or parameter of the
8278 function passed in as DATA. */
8281 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8283 tree fn
= (tree
) data
;
8288 else if (DECL_P (*tp
)
8289 && auto_var_in_fn_p (*tp
, fn
))
8295 /* Returns true if T is, contains, or refers to a type with variable
8296 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8297 arguments, but not the return type. If FN is nonzero, only return
8298 true if a modifier of the type or position of FN is a variable or
8299 parameter inside FN.
8301 This concept is more general than that of C99 'variably modified types':
8302 in C99, a struct type is never variably modified because a VLA may not
8303 appear as a structure member. However, in GNU C code like:
8305 struct S { int i[f()]; };
8307 is valid, and other languages may define similar constructs. */
8310 variably_modified_type_p (tree type
, tree fn
)
8314 /* Test if T is either variable (if FN is zero) or an expression containing
8315 a variable in FN. */
8316 #define RETURN_TRUE_IF_VAR(T) \
8317 do { tree _t = (T); \
8318 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
8319 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8320 return true; } while (0)
8322 if (type
== error_mark_node
)
8325 /* If TYPE itself has variable size, it is variably modified. */
8326 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8327 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8329 switch (TREE_CODE (type
))
8332 case REFERENCE_TYPE
:
8334 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8340 /* If TYPE is a function type, it is variably modified if the
8341 return type is variably modified. */
8342 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8348 case FIXED_POINT_TYPE
:
8351 /* Scalar types are variably modified if their end points
8353 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8354 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8359 case QUAL_UNION_TYPE
:
8360 /* We can't see if any of the fields are variably-modified by the
8361 definition we normally use, since that would produce infinite
8362 recursion via pointers. */
8363 /* This is variably modified if some field's type is. */
8364 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8365 if (TREE_CODE (t
) == FIELD_DECL
)
8367 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8368 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8369 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8371 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8372 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8377 /* Do not call ourselves to avoid infinite recursion. This is
8378 variably modified if the element type is. */
8379 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8380 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8387 /* The current language may have other cases to check, but in general,
8388 all other types are not variably modified. */
8389 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8391 #undef RETURN_TRUE_IF_VAR
8394 /* Given a DECL or TYPE, return the scope in which it was declared, or
8395 NULL_TREE if there is no containing scope. */
8398 get_containing_scope (const_tree t
)
8400 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8403 /* Return the innermost context enclosing DECL that is
8404 a FUNCTION_DECL, or zero if none. */
8407 decl_function_context (const_tree decl
)
8411 if (TREE_CODE (decl
) == ERROR_MARK
)
8414 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8415 where we look up the function at runtime. Such functions always take
8416 a first argument of type 'pointer to real context'.
8418 C++ should really be fixed to use DECL_CONTEXT for the real context,
8419 and use something else for the "virtual context". */
8420 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
8423 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8425 context
= DECL_CONTEXT (decl
);
8427 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8429 if (TREE_CODE (context
) == BLOCK
)
8430 context
= BLOCK_SUPERCONTEXT (context
);
8432 context
= get_containing_scope (context
);
8438 /* Return the innermost context enclosing DECL that is
8439 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8440 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8443 decl_type_context (const_tree decl
)
8445 tree context
= DECL_CONTEXT (decl
);
8448 switch (TREE_CODE (context
))
8450 case NAMESPACE_DECL
:
8451 case TRANSLATION_UNIT_DECL
:
8456 case QUAL_UNION_TYPE
:
8461 context
= DECL_CONTEXT (context
);
8465 context
= BLOCK_SUPERCONTEXT (context
);
8475 /* CALL is a CALL_EXPR. Return the declaration for the function
8476 called, or NULL_TREE if the called function cannot be
8480 get_callee_fndecl (const_tree call
)
8484 if (call
== error_mark_node
)
8485 return error_mark_node
;
8487 /* It's invalid to call this function with anything but a
8489 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8491 /* The first operand to the CALL is the address of the function
8493 addr
= CALL_EXPR_FN (call
);
8497 /* If this is a readonly function pointer, extract its initial value. */
8498 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
8499 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
8500 && DECL_INITIAL (addr
))
8501 addr
= DECL_INITIAL (addr
);
8503 /* If the address is just `&f' for some function `f', then we know
8504 that `f' is being called. */
8505 if (TREE_CODE (addr
) == ADDR_EXPR
8506 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
8507 return TREE_OPERAND (addr
, 0);
8509 /* We couldn't figure out what was being called. */
8513 /* Print debugging information about tree nodes generated during the compile,
8514 and any language-specific information. */
8517 dump_tree_statistics (void)
8519 #ifdef GATHER_STATISTICS
8521 int total_nodes
, total_bytes
;
8524 fprintf (stderr
, "\n??? tree nodes created\n\n");
8525 #ifdef GATHER_STATISTICS
8526 fprintf (stderr
, "Kind Nodes Bytes\n");
8527 fprintf (stderr
, "---------------------------------------\n");
8528 total_nodes
= total_bytes
= 0;
8529 for (i
= 0; i
< (int) all_kinds
; i
++)
8531 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
8532 tree_node_counts
[i
], tree_node_sizes
[i
]);
8533 total_nodes
+= tree_node_counts
[i
];
8534 total_bytes
+= tree_node_sizes
[i
];
8536 fprintf (stderr
, "---------------------------------------\n");
8537 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
8538 fprintf (stderr
, "---------------------------------------\n");
8539 ssanames_print_statistics ();
8540 phinodes_print_statistics ();
8542 fprintf (stderr
, "(No per-node statistics)\n");
8544 print_type_hash_statistics ();
8545 print_debug_expr_statistics ();
8546 print_value_expr_statistics ();
8547 lang_hooks
.print_statistics ();
8550 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8552 /* Generate a crc32 of a string. */
8555 crc32_string (unsigned chksum
, const char *string
)
8559 unsigned value
= *string
<< 24;
8562 for (ix
= 8; ix
--; value
<<= 1)
8566 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
8575 /* P is a string that will be used in a symbol. Mask out any characters
8576 that are not valid in that context. */
8579 clean_symbol_name (char *p
)
8583 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8586 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8593 /* Generate a name for a special-purpose function function.
8594 The generated name may need to be unique across the whole link.
8595 TYPE is some string to identify the purpose of this function to the
8596 linker or collect2; it must start with an uppercase letter,
8598 I - for constructors
8600 N - for C++ anonymous namespaces
8601 F - for DWARF unwind frame information. */
8604 get_file_function_name (const char *type
)
8610 /* If we already have a name we know to be unique, just use that. */
8611 if (first_global_object_name
)
8612 p
= q
= ASTRDUP (first_global_object_name
);
8613 /* If the target is handling the constructors/destructors, they
8614 will be local to this file and the name is only necessary for
8616 We also assign sub_I and sub_D sufixes to constructors called from
8617 the global static constructors. These are always local. */
8618 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
8619 || (strncmp (type
, "sub_", 4) == 0
8620 && (type
[4] == 'I' || type
[4] == 'D')))
8622 const char *file
= main_input_filename
;
8624 file
= input_filename
;
8625 /* Just use the file's basename, because the full pathname
8626 might be quite long. */
8627 p
= q
= ASTRDUP (lbasename (file
));
8631 /* Otherwise, the name must be unique across the entire link.
8632 We don't have anything that we know to be unique to this translation
8633 unit, so use what we do have and throw in some randomness. */
8635 const char *name
= weak_global_object_name
;
8636 const char *file
= main_input_filename
;
8641 file
= input_filename
;
8643 len
= strlen (file
);
8644 q
= (char *) alloca (9 * 2 + len
+ 1);
8645 memcpy (q
, file
, len
+ 1);
8647 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
8648 crc32_string (0, get_random_seed (false)));
8653 clean_symbol_name (q
);
8654 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
8657 /* Set up the name of the file-level functions we may need.
8658 Use a global object (which is already required to be unique over
8659 the program) rather than the file name (which imposes extra
8661 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
8663 return get_identifier (buf
);
8666 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
8668 /* Complain that the tree code of NODE does not match the expected 0
8669 terminated list of trailing codes. The trailing code list can be
8670 empty, for a more vague error message. FILE, LINE, and FUNCTION
8671 are of the caller. */
8674 tree_check_failed (const_tree node
, const char *file
,
8675 int line
, const char *function
, ...)
8679 unsigned length
= 0;
8682 va_start (args
, function
);
8683 while ((code
= va_arg (args
, int)))
8684 length
+= 4 + strlen (tree_code_name
[code
]);
8689 va_start (args
, function
);
8690 length
+= strlen ("expected ");
8691 buffer
= tmp
= (char *) alloca (length
);
8693 while ((code
= va_arg (args
, int)))
8695 const char *prefix
= length
? " or " : "expected ";
8697 strcpy (tmp
+ length
, prefix
);
8698 length
+= strlen (prefix
);
8699 strcpy (tmp
+ length
, tree_code_name
[code
]);
8700 length
+= strlen (tree_code_name
[code
]);
8705 buffer
= "unexpected node";
8707 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8708 buffer
, tree_code_name
[TREE_CODE (node
)],
8709 function
, trim_filename (file
), line
);
8712 /* Complain that the tree code of NODE does match the expected 0
8713 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
8717 tree_not_check_failed (const_tree node
, const char *file
,
8718 int line
, const char *function
, ...)
8722 unsigned length
= 0;
8725 va_start (args
, function
);
8726 while ((code
= va_arg (args
, int)))
8727 length
+= 4 + strlen (tree_code_name
[code
]);
8729 va_start (args
, function
);
8730 buffer
= (char *) alloca (length
);
8732 while ((code
= va_arg (args
, int)))
8736 strcpy (buffer
+ length
, " or ");
8739 strcpy (buffer
+ length
, tree_code_name
[code
]);
8740 length
+= strlen (tree_code_name
[code
]);
8744 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
8745 buffer
, tree_code_name
[TREE_CODE (node
)],
8746 function
, trim_filename (file
), line
);
8749 /* Similar to tree_check_failed, except that we check for a class of tree
8750 code, given in CL. */
8753 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8754 const char *file
, int line
, const char *function
)
8757 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
8758 TREE_CODE_CLASS_STRING (cl
),
8759 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8760 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8763 /* Similar to tree_check_failed, except that instead of specifying a
8764 dozen codes, use the knowledge that they're all sequential. */
8767 tree_range_check_failed (const_tree node
, const char *file
, int line
,
8768 const char *function
, enum tree_code c1
,
8772 unsigned length
= 0;
8775 for (c
= c1
; c
<= c2
; ++c
)
8776 length
+= 4 + strlen (tree_code_name
[c
]);
8778 length
+= strlen ("expected ");
8779 buffer
= (char *) alloca (length
);
8782 for (c
= c1
; c
<= c2
; ++c
)
8784 const char *prefix
= length
? " or " : "expected ";
8786 strcpy (buffer
+ length
, prefix
);
8787 length
+= strlen (prefix
);
8788 strcpy (buffer
+ length
, tree_code_name
[c
]);
8789 length
+= strlen (tree_code_name
[c
]);
8792 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8793 buffer
, tree_code_name
[TREE_CODE (node
)],
8794 function
, trim_filename (file
), line
);
8798 /* Similar to tree_check_failed, except that we check that a tree does
8799 not have the specified code, given in CL. */
8802 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
8803 const char *file
, int line
, const char *function
)
8806 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
8807 TREE_CODE_CLASS_STRING (cl
),
8808 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
8809 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8813 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
8816 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
8817 const char *function
, enum omp_clause_code code
)
8819 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
8820 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
8821 function
, trim_filename (file
), line
);
8825 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
8828 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
8829 const char *function
, enum omp_clause_code c1
,
8830 enum omp_clause_code c2
)
8833 unsigned length
= 0;
8836 for (c
= c1
; c
<= c2
; ++c
)
8837 length
+= 4 + strlen (omp_clause_code_name
[c
]);
8839 length
+= strlen ("expected ");
8840 buffer
= (char *) alloca (length
);
8843 for (c
= c1
; c
<= c2
; ++c
)
8845 const char *prefix
= length
? " or " : "expected ";
8847 strcpy (buffer
+ length
, prefix
);
8848 length
+= strlen (prefix
);
8849 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
8850 length
+= strlen (omp_clause_code_name
[c
]);
8853 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8854 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
8855 function
, trim_filename (file
), line
);
8859 #undef DEFTREESTRUCT
8860 #define DEFTREESTRUCT(VAL, NAME) NAME,
8862 static const char *ts_enum_names
[] = {
8863 #include "treestruct.def"
8865 #undef DEFTREESTRUCT
8867 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
8869 /* Similar to tree_class_check_failed, except that we check for
8870 whether CODE contains the tree structure identified by EN. */
8873 tree_contains_struct_check_failed (const_tree node
,
8874 const enum tree_node_structure_enum en
,
8875 const char *file
, int line
,
8876 const char *function
)
8879 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
8881 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
8885 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
8886 (dynamically sized) vector. */
8889 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
8890 const char *function
)
8893 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
8894 idx
+ 1, len
, function
, trim_filename (file
), line
);
8897 /* Similar to above, except that the check is for the bounds of the operand
8898 vector of an expression node EXP. */
8901 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
8902 int line
, const char *function
)
8904 int code
= TREE_CODE (exp
);
8906 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
8907 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
8908 function
, trim_filename (file
), line
);
8911 /* Similar to above, except that the check is for the number of
8912 operands of an OMP_CLAUSE node. */
8915 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
8916 int line
, const char *function
)
8919 ("tree check: accessed operand %d of omp_clause %s with %d operands "
8920 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
8921 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
8922 trim_filename (file
), line
);
8924 #endif /* ENABLE_TREE_CHECKING */
8926 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
8927 and mapped to the machine mode MODE. Initialize its fields and build
8928 the information necessary for debugging output. */
8931 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
8934 hashval_t hashcode
= 0;
8936 t
= make_node (VECTOR_TYPE
);
8937 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
8938 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
8939 SET_TYPE_MODE (t
, mode
);
8941 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
8942 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8943 else if (TYPE_CANONICAL (innertype
) != innertype
8944 || mode
!= VOIDmode
)
8946 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
8950 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
8951 hashcode
= iterative_hash_host_wide_int (nunits
, hashcode
);
8952 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
8953 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (t
)), hashcode
);
8954 t
= type_hash_canon (hashcode
, t
);
8956 /* We have built a main variant, based on the main variant of the
8957 inner type. Use it to build the variant we return. */
8958 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
8959 && TREE_TYPE (t
) != innertype
)
8960 return build_type_attribute_qual_variant (t
,
8961 TYPE_ATTRIBUTES (innertype
),
8962 TYPE_QUALS (innertype
));
8968 make_or_reuse_type (unsigned size
, int unsignedp
)
8970 if (size
== INT_TYPE_SIZE
)
8971 return unsignedp
? unsigned_type_node
: integer_type_node
;
8972 if (size
== CHAR_TYPE_SIZE
)
8973 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
8974 if (size
== SHORT_TYPE_SIZE
)
8975 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
8976 if (size
== LONG_TYPE_SIZE
)
8977 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
8978 if (size
== LONG_LONG_TYPE_SIZE
)
8979 return (unsignedp
? long_long_unsigned_type_node
8980 : long_long_integer_type_node
);
8981 if (size
== 128 && int128_integer_type_node
)
8982 return (unsignedp
? int128_unsigned_type_node
8983 : int128_integer_type_node
);
8986 return make_unsigned_type (size
);
8988 return make_signed_type (size
);
8991 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
8994 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
8998 if (size
== SHORT_FRACT_TYPE_SIZE
)
8999 return unsignedp
? sat_unsigned_short_fract_type_node
9000 : sat_short_fract_type_node
;
9001 if (size
== FRACT_TYPE_SIZE
)
9002 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9003 if (size
== LONG_FRACT_TYPE_SIZE
)
9004 return unsignedp
? sat_unsigned_long_fract_type_node
9005 : sat_long_fract_type_node
;
9006 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9007 return unsignedp
? sat_unsigned_long_long_fract_type_node
9008 : sat_long_long_fract_type_node
;
9012 if (size
== SHORT_FRACT_TYPE_SIZE
)
9013 return unsignedp
? unsigned_short_fract_type_node
9014 : short_fract_type_node
;
9015 if (size
== FRACT_TYPE_SIZE
)
9016 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9017 if (size
== LONG_FRACT_TYPE_SIZE
)
9018 return unsignedp
? unsigned_long_fract_type_node
9019 : long_fract_type_node
;
9020 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9021 return unsignedp
? unsigned_long_long_fract_type_node
9022 : long_long_fract_type_node
;
9025 return make_fract_type (size
, unsignedp
, satp
);
9028 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9031 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9035 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9036 return unsignedp
? sat_unsigned_short_accum_type_node
9037 : sat_short_accum_type_node
;
9038 if (size
== ACCUM_TYPE_SIZE
)
9039 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9040 if (size
== LONG_ACCUM_TYPE_SIZE
)
9041 return unsignedp
? sat_unsigned_long_accum_type_node
9042 : sat_long_accum_type_node
;
9043 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9044 return unsignedp
? sat_unsigned_long_long_accum_type_node
9045 : sat_long_long_accum_type_node
;
9049 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9050 return unsignedp
? unsigned_short_accum_type_node
9051 : short_accum_type_node
;
9052 if (size
== ACCUM_TYPE_SIZE
)
9053 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9054 if (size
== LONG_ACCUM_TYPE_SIZE
)
9055 return unsignedp
? unsigned_long_accum_type_node
9056 : long_accum_type_node
;
9057 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9058 return unsignedp
? unsigned_long_long_accum_type_node
9059 : long_long_accum_type_node
;
9062 return make_accum_type (size
, unsignedp
, satp
);
9065 /* Create nodes for all integer types (and error_mark_node) using the sizes
9066 of C datatypes. The caller should call set_sizetype soon after calling
9067 this function to select one of the types as sizetype. */
9070 build_common_tree_nodes (bool signed_char
)
9072 error_mark_node
= make_node (ERROR_MARK
);
9073 TREE_TYPE (error_mark_node
) = error_mark_node
;
9075 initialize_sizetypes ();
9077 /* Define both `signed char' and `unsigned char'. */
9078 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9079 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9080 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9081 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9083 /* Define `char', which is like either `signed char' or `unsigned char'
9084 but not the same as either. */
9087 ? make_signed_type (CHAR_TYPE_SIZE
)
9088 : make_unsigned_type (CHAR_TYPE_SIZE
));
9089 TYPE_STRING_FLAG (char_type_node
) = 1;
9091 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9092 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9093 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9094 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9095 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9096 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9097 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9098 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9099 #if HOST_BITS_PER_WIDE_INT >= 64
9100 /* TODO: This isn't correct, but as logic depends at the moment on
9101 host's instead of target's wide-integer.
9102 If there is a target not supporting TImode, but has an 128-bit
9103 integer-scalar register, this target check needs to be adjusted. */
9104 if (targetm
.scalar_mode_supported_p (TImode
))
9106 int128_integer_type_node
= make_signed_type (128);
9107 int128_unsigned_type_node
= make_unsigned_type (128);
9110 /* Define a boolean type. This type only represents boolean values but
9111 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9112 Front ends which want to override this size (i.e. Java) can redefine
9113 boolean_type_node before calling build_common_tree_nodes_2. */
9114 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9115 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9116 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9117 TYPE_PRECISION (boolean_type_node
) = 1;
9119 /* Fill in the rest of the sized types. Reuse existing type nodes
9121 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9122 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9123 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9124 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9125 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9127 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9128 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9129 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9130 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9131 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9133 access_public_node
= get_identifier ("public");
9134 access_protected_node
= get_identifier ("protected");
9135 access_private_node
= get_identifier ("private");
9138 /* Call this function after calling build_common_tree_nodes and set_sizetype.
9139 It will create several other common tree nodes. */
9142 build_common_tree_nodes_2 (int short_double
)
9144 /* Define these next since types below may used them. */
9145 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9146 integer_one_node
= build_int_cst (integer_type_node
, 1);
9147 integer_three_node
= build_int_cst (integer_type_node
, 3);
9148 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9150 size_zero_node
= size_int (0);
9151 size_one_node
= size_int (1);
9152 bitsize_zero_node
= bitsize_int (0);
9153 bitsize_one_node
= bitsize_int (1);
9154 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9156 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9157 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9159 void_type_node
= make_node (VOID_TYPE
);
9160 layout_type (void_type_node
);
9162 /* We are not going to have real types in C with less than byte alignment,
9163 so we might as well not have any types that claim to have it. */
9164 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
9165 TYPE_USER_ALIGN (void_type_node
) = 0;
9167 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9168 layout_type (TREE_TYPE (null_pointer_node
));
9170 ptr_type_node
= build_pointer_type (void_type_node
);
9172 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9173 fileptr_type_node
= ptr_type_node
;
9175 float_type_node
= make_node (REAL_TYPE
);
9176 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9177 layout_type (float_type_node
);
9179 double_type_node
= make_node (REAL_TYPE
);
9181 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
9183 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9184 layout_type (double_type_node
);
9186 long_double_type_node
= make_node (REAL_TYPE
);
9187 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9188 layout_type (long_double_type_node
);
9190 float_ptr_type_node
= build_pointer_type (float_type_node
);
9191 double_ptr_type_node
= build_pointer_type (double_type_node
);
9192 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9193 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9195 /* Fixed size integer types. */
9196 uint32_type_node
= build_nonstandard_integer_type (32, true);
9197 uint64_type_node
= build_nonstandard_integer_type (64, true);
9199 /* Decimal float types. */
9200 dfloat32_type_node
= make_node (REAL_TYPE
);
9201 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9202 layout_type (dfloat32_type_node
);
9203 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9204 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
9206 dfloat64_type_node
= make_node (REAL_TYPE
);
9207 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9208 layout_type (dfloat64_type_node
);
9209 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9210 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
9212 dfloat128_type_node
= make_node (REAL_TYPE
);
9213 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9214 layout_type (dfloat128_type_node
);
9215 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9216 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
9218 complex_integer_type_node
= build_complex_type (integer_type_node
);
9219 complex_float_type_node
= build_complex_type (float_type_node
);
9220 complex_double_type_node
= build_complex_type (double_type_node
);
9221 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
9223 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9224 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9225 sat_ ## KIND ## _type_node = \
9226 make_sat_signed_ ## KIND ## _type (SIZE); \
9227 sat_unsigned_ ## KIND ## _type_node = \
9228 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9229 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9230 unsigned_ ## KIND ## _type_node = \
9231 make_unsigned_ ## KIND ## _type (SIZE);
9233 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9234 sat_ ## WIDTH ## KIND ## _type_node = \
9235 make_sat_signed_ ## KIND ## _type (SIZE); \
9236 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9237 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9238 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9239 unsigned_ ## WIDTH ## KIND ## _type_node = \
9240 make_unsigned_ ## KIND ## _type (SIZE);
9242 /* Make fixed-point type nodes based on four different widths. */
9243 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9244 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9245 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9246 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9247 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9249 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9250 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9251 NAME ## _type_node = \
9252 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9253 u ## NAME ## _type_node = \
9254 make_or_reuse_unsigned_ ## KIND ## _type \
9255 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9256 sat_ ## NAME ## _type_node = \
9257 make_or_reuse_sat_signed_ ## KIND ## _type \
9258 (GET_MODE_BITSIZE (MODE ## mode)); \
9259 sat_u ## NAME ## _type_node = \
9260 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9261 (GET_MODE_BITSIZE (U ## MODE ## mode));
9263 /* Fixed-point type and mode nodes. */
9264 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9265 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9266 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9267 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9268 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9269 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9270 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9271 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9272 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9273 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9274 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9277 tree t
= targetm
.build_builtin_va_list ();
9279 /* Many back-ends define record types without setting TYPE_NAME.
9280 If we copied the record type here, we'd keep the original
9281 record type without a name. This breaks name mangling. So,
9282 don't copy record types and let c_common_nodes_and_builtins()
9283 declare the type to be __builtin_va_list. */
9284 if (TREE_CODE (t
) != RECORD_TYPE
)
9285 t
= build_variant_type_copy (t
);
9287 va_list_type_node
= t
;
9291 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9294 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9295 const char *library_name
, int ecf_flags
)
9299 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9300 library_name
, NULL_TREE
);
9301 if (ecf_flags
& ECF_CONST
)
9302 TREE_READONLY (decl
) = 1;
9303 if (ecf_flags
& ECF_PURE
)
9304 DECL_PURE_P (decl
) = 1;
9305 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
9306 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9307 if (ecf_flags
& ECF_NORETURN
)
9308 TREE_THIS_VOLATILE (decl
) = 1;
9309 if (ecf_flags
& ECF_NOTHROW
)
9310 TREE_NOTHROW (decl
) = 1;
9311 if (ecf_flags
& ECF_MALLOC
)
9312 DECL_IS_MALLOC (decl
) = 1;
9313 if (ecf_flags
& ECF_LEAF
)
9314 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9315 NULL
, DECL_ATTRIBUTES (decl
));
9317 built_in_decls
[code
] = decl
;
9318 implicit_built_in_decls
[code
] = decl
;
9321 /* Call this function after instantiating all builtins that the language
9322 front end cares about. This will build the rest of the builtins that
9323 are relied upon by the tree optimizers and the middle-end. */
9326 build_common_builtin_nodes (void)
9330 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
9331 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
9333 ftype
= build_function_type_list (ptr_type_node
,
9334 ptr_type_node
, const_ptr_type_node
,
9335 size_type_node
, NULL_TREE
);
9337 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
9338 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9339 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9340 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
9341 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9342 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9345 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
9347 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9348 const_ptr_type_node
, size_type_node
,
9350 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9351 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9354 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
9356 ftype
= build_function_type_list (ptr_type_node
,
9357 ptr_type_node
, integer_type_node
,
9358 size_type_node
, NULL_TREE
);
9359 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9360 "memset", ECF_NOTHROW
| ECF_LEAF
);
9363 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
9365 ftype
= build_function_type_list (ptr_type_node
,
9366 size_type_node
, NULL_TREE
);
9367 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
9368 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9371 /* If we're checking the stack, `alloca' can throw. */
9372 if (flag_stack_check
)
9373 TREE_NOTHROW (built_in_decls
[BUILT_IN_ALLOCA
]) = 0;
9375 ftype
= build_function_type_list (void_type_node
,
9376 ptr_type_node
, ptr_type_node
,
9377 ptr_type_node
, NULL_TREE
);
9378 local_define_builtin ("__builtin_init_trampoline", ftype
,
9379 BUILT_IN_INIT_TRAMPOLINE
,
9380 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
9382 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9383 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
9384 BUILT_IN_ADJUST_TRAMPOLINE
,
9385 "__builtin_adjust_trampoline",
9386 ECF_CONST
| ECF_NOTHROW
);
9388 ftype
= build_function_type_list (void_type_node
,
9389 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9390 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
9391 BUILT_IN_NONLOCAL_GOTO
,
9392 "__builtin_nonlocal_goto",
9393 ECF_NORETURN
| ECF_NOTHROW
);
9395 ftype
= build_function_type_list (void_type_node
,
9396 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9397 local_define_builtin ("__builtin_setjmp_setup", ftype
,
9398 BUILT_IN_SETJMP_SETUP
,
9399 "__builtin_setjmp_setup", ECF_NOTHROW
);
9401 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9402 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
9403 BUILT_IN_SETJMP_DISPATCHER
,
9404 "__builtin_setjmp_dispatcher",
9405 ECF_PURE
| ECF_NOTHROW
);
9407 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9408 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
9409 BUILT_IN_SETJMP_RECEIVER
,
9410 "__builtin_setjmp_receiver", ECF_NOTHROW
);
9412 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
9413 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
9414 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
9416 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9417 local_define_builtin ("__builtin_stack_restore", ftype
,
9418 BUILT_IN_STACK_RESTORE
,
9419 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
9421 /* If there's a possibility that we might use the ARM EABI, build the
9422 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9423 if (targetm
.arm_eabi_unwinder
)
9425 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9426 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
9427 BUILT_IN_CXA_END_CLEANUP
,
9428 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
9431 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9432 local_define_builtin ("__builtin_unwind_resume", ftype
,
9433 BUILT_IN_UNWIND_RESUME
,
9434 ((targetm
.except_unwind_info (&global_options
)
9436 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9439 /* The exception object and filter values from the runtime. The argument
9440 must be zero before exception lowering, i.e. from the front end. After
9441 exception lowering, it will be the region number for the exception
9442 landing pad. These functions are PURE instead of CONST to prevent
9443 them from being hoisted past the exception edge that will initialize
9444 its value in the landing pad. */
9445 ftype
= build_function_type_list (ptr_type_node
,
9446 integer_type_node
, NULL_TREE
);
9447 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
9448 "__builtin_eh_pointer", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9450 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
9451 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
9452 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
9453 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9455 ftype
= build_function_type_list (void_type_node
,
9456 integer_type_node
, integer_type_node
,
9458 local_define_builtin ("__builtin_eh_copy_values", ftype
,
9459 BUILT_IN_EH_COPY_VALUES
,
9460 "__builtin_eh_copy_values", ECF_NOTHROW
);
9462 /* Complex multiplication and division. These are handled as builtins
9463 rather than optabs because emit_library_call_value doesn't support
9464 complex. Further, we can do slightly better with folding these
9465 beasties if the real and complex parts of the arguments are separate. */
9469 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
9471 char mode_name_buf
[4], *q
;
9473 enum built_in_function mcode
, dcode
;
9474 tree type
, inner_type
;
9476 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
9479 inner_type
= TREE_TYPE (type
);
9481 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
9482 inner_type
, inner_type
, NULL_TREE
);
9484 mcode
= ((enum built_in_function
)
9485 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9486 dcode
= ((enum built_in_function
)
9487 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
9489 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
9493 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
9494 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
9495 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
9497 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
9498 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
9499 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
9504 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
9507 If we requested a pointer to a vector, build up the pointers that
9508 we stripped off while looking for the inner type. Similarly for
9509 return values from functions.
9511 The argument TYPE is the top of the chain, and BOTTOM is the
9512 new type which we will point to. */
9515 reconstruct_complex_type (tree type
, tree bottom
)
9519 if (TREE_CODE (type
) == POINTER_TYPE
)
9521 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9522 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
9523 TYPE_REF_CAN_ALIAS_ALL (type
));
9525 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
9527 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9528 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
9529 TYPE_REF_CAN_ALIAS_ALL (type
));
9531 else if (TREE_CODE (type
) == ARRAY_TYPE
)
9533 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9534 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
9536 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9538 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9539 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
9541 else if (TREE_CODE (type
) == METHOD_TYPE
)
9543 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9544 /* The build_method_type_directly() routine prepends 'this' to argument list,
9545 so we must compensate by getting rid of it. */
9547 = build_method_type_directly
9548 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
9550 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
9552 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9554 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
9555 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
9560 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
9564 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
9567 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
9571 switch (GET_MODE_CLASS (mode
))
9573 case MODE_VECTOR_INT
:
9574 case MODE_VECTOR_FLOAT
:
9575 case MODE_VECTOR_FRACT
:
9576 case MODE_VECTOR_UFRACT
:
9577 case MODE_VECTOR_ACCUM
:
9578 case MODE_VECTOR_UACCUM
:
9579 nunits
= GET_MODE_NUNITS (mode
);
9583 /* Check that there are no leftover bits. */
9584 gcc_assert (GET_MODE_BITSIZE (mode
)
9585 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
9587 nunits
= GET_MODE_BITSIZE (mode
)
9588 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
9595 return make_vector_type (innertype
, nunits
, mode
);
9598 /* Similarly, but takes the inner type and number of units, which must be
9602 build_vector_type (tree innertype
, int nunits
)
9604 return make_vector_type (innertype
, nunits
, VOIDmode
);
9607 /* Similarly, but takes the inner type and number of units, which must be
9611 build_opaque_vector_type (tree innertype
, int nunits
)
9614 innertype
= build_distinct_type_copy (innertype
);
9615 t
= make_vector_type (innertype
, nunits
, VOIDmode
);
9616 TYPE_VECTOR_OPAQUE (t
) = true;
9621 /* Given an initializer INIT, return TRUE if INIT is zero or some
9622 aggregate of zeros. Otherwise return FALSE. */
9624 initializer_zerop (const_tree init
)
9630 switch (TREE_CODE (init
))
9633 return integer_zerop (init
);
9636 /* ??? Note that this is not correct for C4X float formats. There,
9637 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
9638 negative exponent. */
9639 return real_zerop (init
)
9640 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
9643 return fixed_zerop (init
);
9646 return integer_zerop (init
)
9647 || (real_zerop (init
)
9648 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
9649 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
9652 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
9653 if (!initializer_zerop (TREE_VALUE (elt
)))
9659 unsigned HOST_WIDE_INT idx
;
9661 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
9662 if (!initializer_zerop (elt
))
9671 /* We need to loop through all elements to handle cases like
9672 "\0" and "\0foobar". */
9673 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
9674 if (TREE_STRING_POINTER (init
)[i
] != '\0')
9685 /* Build an empty statement at location LOC. */
9688 build_empty_stmt (location_t loc
)
9690 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
9691 SET_EXPR_LOCATION (t
, loc
);
9696 /* Build an OpenMP clause with code CODE. LOC is the location of the
9700 build_omp_clause (location_t loc
, enum omp_clause_code code
)
9705 length
= omp_clause_num_ops
[code
];
9706 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
9708 record_node_allocation_statistics (OMP_CLAUSE
, size
);
9710 t
= ggc_alloc_tree_node (size
);
9711 memset (t
, 0, size
);
9712 TREE_SET_CODE (t
, OMP_CLAUSE
);
9713 OMP_CLAUSE_SET_CODE (t
, code
);
9714 OMP_CLAUSE_LOCATION (t
) = loc
;
9719 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
9720 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
9721 Except for the CODE and operand count field, other storage for the
9722 object is initialized to zeros. */
9725 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
9728 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
9730 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
9731 gcc_assert (len
>= 1);
9733 record_node_allocation_statistics (code
, length
);
9735 t
= ggc_alloc_zone_cleared_tree_node_stat (&tree_zone
, length PASS_MEM_STAT
);
9737 TREE_SET_CODE (t
, code
);
9739 /* Can't use TREE_OPERAND to store the length because if checking is
9740 enabled, it will try to check the length before we store it. :-P */
9741 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
9746 /* Helper function for build_call_* functions; build a CALL_EXPR with
9747 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
9748 the argument slots. */
9751 build_call_1 (tree return_type
, tree fn
, int nargs
)
9755 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
9756 TREE_TYPE (t
) = return_type
;
9757 CALL_EXPR_FN (t
) = fn
;
9758 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
9763 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9764 FN and a null static chain slot. NARGS is the number of call arguments
9765 which are specified as "..." arguments. */
9768 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
9772 va_start (args
, nargs
);
9773 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
9778 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9779 FN and a null static chain slot. NARGS is the number of call arguments
9780 which are specified as a va_list ARGS. */
9783 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
9788 t
= build_call_1 (return_type
, fn
, nargs
);
9789 for (i
= 0; i
< nargs
; i
++)
9790 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
9791 process_call_operands (t
);
9795 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9796 FN and a null static chain slot. NARGS is the number of call arguments
9797 which are specified as a tree array ARGS. */
9800 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
9801 int nargs
, const tree
*args
)
9806 t
= build_call_1 (return_type
, fn
, nargs
);
9807 for (i
= 0; i
< nargs
; i
++)
9808 CALL_EXPR_ARG (t
, i
) = args
[i
];
9809 process_call_operands (t
);
9810 SET_EXPR_LOCATION (t
, loc
);
9814 /* Like build_call_array, but takes a VEC. */
9817 build_call_vec (tree return_type
, tree fn
, VEC(tree
,gc
) *args
)
9822 ret
= build_call_1 (return_type
, fn
, VEC_length (tree
, args
));
9823 FOR_EACH_VEC_ELT (tree
, args
, ix
, t
)
9824 CALL_EXPR_ARG (ret
, ix
) = t
;
9825 process_call_operands (ret
);
9830 /* Returns true if it is possible to prove that the index of
9831 an array access REF (an ARRAY_REF expression) falls into the
9835 in_array_bounds_p (tree ref
)
9837 tree idx
= TREE_OPERAND (ref
, 1);
9840 if (TREE_CODE (idx
) != INTEGER_CST
)
9843 min
= array_ref_low_bound (ref
);
9844 max
= array_ref_up_bound (ref
);
9847 || TREE_CODE (min
) != INTEGER_CST
9848 || TREE_CODE (max
) != INTEGER_CST
)
9851 if (tree_int_cst_lt (idx
, min
)
9852 || tree_int_cst_lt (max
, idx
))
9858 /* Returns true if it is possible to prove that the range of
9859 an array access REF (an ARRAY_RANGE_REF expression) falls
9860 into the array bounds. */
9863 range_in_array_bounds_p (tree ref
)
9865 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
9866 tree range_min
, range_max
, min
, max
;
9868 range_min
= TYPE_MIN_VALUE (domain_type
);
9869 range_max
= TYPE_MAX_VALUE (domain_type
);
9872 || TREE_CODE (range_min
) != INTEGER_CST
9873 || TREE_CODE (range_max
) != INTEGER_CST
)
9876 min
= array_ref_low_bound (ref
);
9877 max
= array_ref_up_bound (ref
);
9880 || TREE_CODE (min
) != INTEGER_CST
9881 || TREE_CODE (max
) != INTEGER_CST
)
9884 if (tree_int_cst_lt (range_min
, min
)
9885 || tree_int_cst_lt (max
, range_max
))
9891 /* Return true if T (assumed to be a DECL) must be assigned a memory
9895 needs_to_live_in_memory (const_tree t
)
9897 if (TREE_CODE (t
) == SSA_NAME
)
9898 t
= SSA_NAME_VAR (t
);
9900 return (TREE_ADDRESSABLE (t
)
9901 || is_global_var (t
)
9902 || (TREE_CODE (t
) == RESULT_DECL
9903 && !DECL_BY_REFERENCE (t
)
9904 && aggregate_value_p (t
, current_function_decl
)));
9907 /* Return value of a constant X and sign-extend it. */
9910 int_cst_value (const_tree x
)
9912 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
9913 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
9915 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9916 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
9917 || TREE_INT_CST_HIGH (x
) == -1);
9919 if (bits
< HOST_BITS_PER_WIDE_INT
)
9921 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
9923 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
9925 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
9931 /* Return value of a constant X and sign-extend it. */
9934 widest_int_cst_value (const_tree x
)
9936 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
9937 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
9939 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
9940 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= 2 * HOST_BITS_PER_WIDE_INT
);
9941 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
9942 << HOST_BITS_PER_WIDE_INT
);
9944 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9945 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
9946 || TREE_INT_CST_HIGH (x
) == -1);
9949 if (bits
< HOST_BITS_PER_WIDEST_INT
)
9951 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
9953 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
9955 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
9961 /* If TYPE is an integral type, return an equivalent type which is
9962 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
9963 return TYPE itself. */
9966 signed_or_unsigned_type_for (int unsignedp
, tree type
)
9969 if (POINTER_TYPE_P (type
))
9971 /* If the pointer points to the normal address space, use the
9972 size_type_node. Otherwise use an appropriate size for the pointer
9973 based on the named address space it points to. */
9974 if (!TYPE_ADDR_SPACE (TREE_TYPE (t
)))
9977 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
9980 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
9983 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
9986 /* Returns unsigned variant of TYPE. */
9989 unsigned_type_for (tree type
)
9991 return signed_or_unsigned_type_for (1, type
);
9994 /* Returns signed variant of TYPE. */
9997 signed_type_for (tree type
)
9999 return signed_or_unsigned_type_for (0, type
);
10002 /* Returns the largest value obtainable by casting something in INNER type to
10006 upper_bound_in_type (tree outer
, tree inner
)
10008 unsigned HOST_WIDE_INT lo
, hi
;
10009 unsigned int det
= 0;
10010 unsigned oprec
= TYPE_PRECISION (outer
);
10011 unsigned iprec
= TYPE_PRECISION (inner
);
10014 /* Compute a unique number for every combination. */
10015 det
|= (oprec
> iprec
) ? 4 : 0;
10016 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10017 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10019 /* Determine the exponent to use. */
10024 /* oprec <= iprec, outer: signed, inner: don't care. */
10029 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10033 /* oprec > iprec, outer: signed, inner: signed. */
10037 /* oprec > iprec, outer: signed, inner: unsigned. */
10041 /* oprec > iprec, outer: unsigned, inner: signed. */
10045 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10049 gcc_unreachable ();
10052 /* Compute 2^^prec - 1. */
10053 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10056 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
10057 >> (HOST_BITS_PER_WIDE_INT
- prec
));
10061 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
10062 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
10063 lo
= ~(unsigned HOST_WIDE_INT
) 0;
10066 return build_int_cst_wide (outer
, lo
, hi
);
10069 /* Returns the smallest value obtainable by casting something in INNER type to
10073 lower_bound_in_type (tree outer
, tree inner
)
10075 unsigned HOST_WIDE_INT lo
, hi
;
10076 unsigned oprec
= TYPE_PRECISION (outer
);
10077 unsigned iprec
= TYPE_PRECISION (inner
);
10079 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10081 if (TYPE_UNSIGNED (outer
)
10082 /* If we are widening something of an unsigned type, OUTER type
10083 contains all values of INNER type. In particular, both INNER
10084 and OUTER types have zero in common. */
10085 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10089 /* If we are widening a signed type to another signed type, we
10090 want to obtain -2^^(iprec-1). If we are keeping the
10091 precision or narrowing to a signed type, we want to obtain
10093 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10095 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10097 hi
= ~(unsigned HOST_WIDE_INT
) 0;
10098 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
10102 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
10103 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
10108 return build_int_cst_wide (outer
, lo
, hi
);
10111 /* Return nonzero if two operands that are suitable for PHI nodes are
10112 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10113 SSA_NAME or invariant. Note that this is strictly an optimization.
10114 That is, callers of this function can directly call operand_equal_p
10115 and get the same result, only slower. */
10118 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10122 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10124 return operand_equal_p (arg0
, arg1
, 0);
10127 /* Returns number of zeros at the end of binary representation of X.
10129 ??? Use ffs if available? */
10132 num_ending_zeros (const_tree x
)
10134 unsigned HOST_WIDE_INT fr
, nfr
;
10135 unsigned num
, abits
;
10136 tree type
= TREE_TYPE (x
);
10138 if (TREE_INT_CST_LOW (x
) == 0)
10140 num
= HOST_BITS_PER_WIDE_INT
;
10141 fr
= TREE_INT_CST_HIGH (x
);
10146 fr
= TREE_INT_CST_LOW (x
);
10149 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
10152 if (nfr
<< abits
== fr
)
10159 if (num
> TYPE_PRECISION (type
))
10160 num
= TYPE_PRECISION (type
);
10162 return build_int_cst_type (type
, num
);
10166 #define WALK_SUBTREE(NODE) \
10169 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10175 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10176 be walked whenever a type is seen in the tree. Rest of operands and return
10177 value are as for walk_tree. */
10180 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10181 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10183 tree result
= NULL_TREE
;
10185 switch (TREE_CODE (type
))
10188 case REFERENCE_TYPE
:
10189 /* We have to worry about mutually recursive pointers. These can't
10190 be written in C. They can in Ada. It's pathological, but
10191 there's an ACATS test (c38102a) that checks it. Deal with this
10192 by checking if we're pointing to another pointer, that one
10193 points to another pointer, that one does too, and we have no htab.
10194 If so, get a hash table. We check three levels deep to avoid
10195 the cost of the hash table if we don't need one. */
10196 if (POINTER_TYPE_P (TREE_TYPE (type
))
10197 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10198 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10201 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10209 /* ... fall through ... */
10212 WALK_SUBTREE (TREE_TYPE (type
));
10216 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10218 /* Fall through. */
10220 case FUNCTION_TYPE
:
10221 WALK_SUBTREE (TREE_TYPE (type
));
10225 /* We never want to walk into default arguments. */
10226 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
10227 WALK_SUBTREE (TREE_VALUE (arg
));
10232 /* Don't follow this nodes's type if a pointer for fear that
10233 we'll have infinite recursion. If we have a PSET, then we
10236 || (!POINTER_TYPE_P (TREE_TYPE (type
))
10237 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
10238 WALK_SUBTREE (TREE_TYPE (type
));
10239 WALK_SUBTREE (TYPE_DOMAIN (type
));
10243 WALK_SUBTREE (TREE_TYPE (type
));
10244 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
10254 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10255 called with the DATA and the address of each sub-tree. If FUNC returns a
10256 non-NULL value, the traversal is stopped, and the value returned by FUNC
10257 is returned. If PSET is non-NULL it is used to record the nodes visited,
10258 and to avoid visiting a node more than once. */
10261 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10262 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10264 enum tree_code code
;
10268 #define WALK_SUBTREE_TAIL(NODE) \
10272 goto tail_recurse; \
10277 /* Skip empty subtrees. */
10281 /* Don't walk the same tree twice, if the user has requested
10282 that we avoid doing so. */
10283 if (pset
&& pointer_set_insert (pset
, *tp
))
10286 /* Call the function. */
10288 result
= (*func
) (tp
, &walk_subtrees
, data
);
10290 /* If we found something, return it. */
10294 code
= TREE_CODE (*tp
);
10296 /* Even if we didn't, FUNC may have decided that there was nothing
10297 interesting below this point in the tree. */
10298 if (!walk_subtrees
)
10300 /* But we still need to check our siblings. */
10301 if (code
== TREE_LIST
)
10302 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10303 else if (code
== OMP_CLAUSE
)
10304 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10311 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
10312 if (result
|| !walk_subtrees
)
10319 case IDENTIFIER_NODE
:
10326 case PLACEHOLDER_EXPR
:
10330 /* None of these have subtrees other than those already walked
10335 WALK_SUBTREE (TREE_VALUE (*tp
));
10336 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10341 int len
= TREE_VEC_LENGTH (*tp
);
10346 /* Walk all elements but the first. */
10348 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
10350 /* Now walk the first one as a tail call. */
10351 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
10355 WALK_SUBTREE (TREE_REALPART (*tp
));
10356 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
10360 unsigned HOST_WIDE_INT idx
;
10361 constructor_elt
*ce
;
10364 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
10366 WALK_SUBTREE (ce
->value
);
10371 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
10376 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
10378 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
10379 into declarations that are just mentioned, rather than
10380 declared; they don't really belong to this part of the tree.
10381 And, we can see cycles: the initializer for a declaration
10382 can refer to the declaration itself. */
10383 WALK_SUBTREE (DECL_INITIAL (decl
));
10384 WALK_SUBTREE (DECL_SIZE (decl
));
10385 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
10387 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
10390 case STATEMENT_LIST
:
10392 tree_stmt_iterator i
;
10393 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
10394 WALK_SUBTREE (*tsi_stmt_ptr (i
));
10399 switch (OMP_CLAUSE_CODE (*tp
))
10401 case OMP_CLAUSE_PRIVATE
:
10402 case OMP_CLAUSE_SHARED
:
10403 case OMP_CLAUSE_FIRSTPRIVATE
:
10404 case OMP_CLAUSE_COPYIN
:
10405 case OMP_CLAUSE_COPYPRIVATE
:
10406 case OMP_CLAUSE_IF
:
10407 case OMP_CLAUSE_NUM_THREADS
:
10408 case OMP_CLAUSE_SCHEDULE
:
10409 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
10412 case OMP_CLAUSE_NOWAIT
:
10413 case OMP_CLAUSE_ORDERED
:
10414 case OMP_CLAUSE_DEFAULT
:
10415 case OMP_CLAUSE_UNTIED
:
10416 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10418 case OMP_CLAUSE_LASTPRIVATE
:
10419 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
10420 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
10421 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10423 case OMP_CLAUSE_COLLAPSE
:
10426 for (i
= 0; i
< 3; i
++)
10427 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
10428 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10431 case OMP_CLAUSE_REDUCTION
:
10434 for (i
= 0; i
< 4; i
++)
10435 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
10436 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10440 gcc_unreachable ();
10448 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
10449 But, we only want to walk once. */
10450 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
10451 for (i
= 0; i
< len
; ++i
)
10452 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
10453 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
10457 /* If this is a TYPE_DECL, walk into the fields of the type that it's
10458 defining. We only want to walk into these fields of a type in this
10459 case and not in the general case of a mere reference to the type.
10461 The criterion is as follows: if the field can be an expression, it
10462 must be walked only here. This should be in keeping with the fields
10463 that are directly gimplified in gimplify_type_sizes in order for the
10464 mark/copy-if-shared/unmark machinery of the gimplifier to work with
10465 variable-sized types.
10467 Note that DECLs get walked as part of processing the BIND_EXPR. */
10468 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
10470 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
10471 if (TREE_CODE (*type_p
) == ERROR_MARK
)
10474 /* Call the function for the type. See if it returns anything or
10475 doesn't want us to continue. If we are to continue, walk both
10476 the normal fields and those for the declaration case. */
10477 result
= (*func
) (type_p
, &walk_subtrees
, data
);
10478 if (result
|| !walk_subtrees
)
10481 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
10485 /* If this is a record type, also walk the fields. */
10486 if (RECORD_OR_UNION_TYPE_P (*type_p
))
10490 for (field
= TYPE_FIELDS (*type_p
); field
;
10491 field
= DECL_CHAIN (field
))
10493 /* We'd like to look at the type of the field, but we can
10494 easily get infinite recursion. So assume it's pointed
10495 to elsewhere in the tree. Also, ignore things that
10497 if (TREE_CODE (field
) != FIELD_DECL
)
10500 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
10501 WALK_SUBTREE (DECL_SIZE (field
));
10502 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
10503 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
10504 WALK_SUBTREE (DECL_QUALIFIER (field
));
10508 /* Same for scalar types. */
10509 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
10510 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
10511 || TREE_CODE (*type_p
) == INTEGER_TYPE
10512 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
10513 || TREE_CODE (*type_p
) == REAL_TYPE
)
10515 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
10516 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
10519 WALK_SUBTREE (TYPE_SIZE (*type_p
));
10520 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
10525 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
10529 /* Walk over all the sub-trees of this operand. */
10530 len
= TREE_OPERAND_LENGTH (*tp
);
10532 /* Go through the subtrees. We need to do this in forward order so
10533 that the scope of a FOR_EXPR is handled properly. */
10536 for (i
= 0; i
< len
- 1; ++i
)
10537 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
10538 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
10541 /* If this is a type, walk the needed fields in the type. */
10542 else if (TYPE_P (*tp
))
10543 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
10547 /* We didn't find what we were looking for. */
10550 #undef WALK_SUBTREE_TAIL
10552 #undef WALK_SUBTREE
10554 /* Like walk_tree, but does not walk duplicate nodes more than once. */
10557 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10561 struct pointer_set_t
*pset
;
10563 pset
= pointer_set_create ();
10564 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
10565 pointer_set_destroy (pset
);
10571 tree_block (tree t
)
10573 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
10575 if (IS_EXPR_CODE_CLASS (c
))
10576 return &t
->exp
.block
;
10577 gcc_unreachable ();
10581 /* Create a nameless artificial label and put it in the current
10582 function context. The label has a location of LOC. Returns the
10583 newly created label. */
10586 create_artificial_label (location_t loc
)
10588 tree lab
= build_decl (loc
,
10589 LABEL_DECL
, NULL_TREE
, void_type_node
);
10591 DECL_ARTIFICIAL (lab
) = 1;
10592 DECL_IGNORED_P (lab
) = 1;
10593 DECL_CONTEXT (lab
) = current_function_decl
;
10597 /* Given a tree, try to return a useful variable name that we can use
10598 to prefix a temporary that is being assigned the value of the tree.
10599 I.E. given <temp> = &A, return A. */
10604 tree stripped_decl
;
10607 STRIP_NOPS (stripped_decl
);
10608 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
10609 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
10612 switch (TREE_CODE (stripped_decl
))
10615 return get_name (TREE_OPERAND (stripped_decl
, 0));
10622 /* Return true if TYPE has a variable argument list. */
10625 stdarg_p (const_tree fntype
)
10627 function_args_iterator args_iter
;
10628 tree n
= NULL_TREE
, t
;
10633 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
10638 return n
!= NULL_TREE
&& n
!= void_type_node
;
10641 /* Return true if TYPE has a prototype. */
10644 prototype_p (tree fntype
)
10648 gcc_assert (fntype
!= NULL_TREE
);
10650 t
= TYPE_ARG_TYPES (fntype
);
10651 return (t
!= NULL_TREE
);
10654 /* If BLOCK is inlined from an __attribute__((__artificial__))
10655 routine, return pointer to location from where it has been
10658 block_nonartificial_location (tree block
)
10660 location_t
*ret
= NULL
;
10662 while (block
&& TREE_CODE (block
) == BLOCK
10663 && BLOCK_ABSTRACT_ORIGIN (block
))
10665 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
10667 while (TREE_CODE (ao
) == BLOCK
10668 && BLOCK_ABSTRACT_ORIGIN (ao
)
10669 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
10670 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
10672 if (TREE_CODE (ao
) == FUNCTION_DECL
)
10674 /* If AO is an artificial inline, point RET to the
10675 call site locus at which it has been inlined and continue
10676 the loop, in case AO's caller is also an artificial
10678 if (DECL_DECLARED_INLINE_P (ao
)
10679 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
10680 ret
= &BLOCK_SOURCE_LOCATION (block
);
10684 else if (TREE_CODE (ao
) != BLOCK
)
10687 block
= BLOCK_SUPERCONTEXT (block
);
10693 /* If EXP is inlined from an __attribute__((__artificial__))
10694 function, return the location of the original call expression. */
10697 tree_nonartificial_location (tree exp
)
10699 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
10704 return EXPR_LOCATION (exp
);
10708 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
10711 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
10714 cl_option_hash_hash (const void *x
)
10716 const_tree
const t
= (const_tree
) x
;
10720 hashval_t hash
= 0;
10722 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
10724 p
= (const char *)TREE_OPTIMIZATION (t
);
10725 len
= sizeof (struct cl_optimization
);
10728 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
10730 p
= (const char *)TREE_TARGET_OPTION (t
);
10731 len
= sizeof (struct cl_target_option
);
10735 gcc_unreachable ();
10737 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
10739 for (i
= 0; i
< len
; i
++)
10741 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
10746 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
10747 TARGET_OPTION tree node) is the same as that given by *Y, which is the
10751 cl_option_hash_eq (const void *x
, const void *y
)
10753 const_tree
const xt
= (const_tree
) x
;
10754 const_tree
const yt
= (const_tree
) y
;
10759 if (TREE_CODE (xt
) != TREE_CODE (yt
))
10762 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
10764 xp
= (const char *)TREE_OPTIMIZATION (xt
);
10765 yp
= (const char *)TREE_OPTIMIZATION (yt
);
10766 len
= sizeof (struct cl_optimization
);
10769 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
10771 xp
= (const char *)TREE_TARGET_OPTION (xt
);
10772 yp
= (const char *)TREE_TARGET_OPTION (yt
);
10773 len
= sizeof (struct cl_target_option
);
10777 gcc_unreachable ();
10779 return (memcmp (xp
, yp
, len
) == 0);
10782 /* Build an OPTIMIZATION_NODE based on the current options. */
10785 build_optimization_node (void)
10790 /* Use the cache of optimization nodes. */
10792 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
10795 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
10799 /* Insert this one into the hash table. */
10800 t
= cl_optimization_node
;
10803 /* Make a new node for next time round. */
10804 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
10810 /* Build a TARGET_OPTION_NODE based on the current options. */
10813 build_target_option_node (void)
10818 /* Use the cache of optimization nodes. */
10820 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
10823 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
10827 /* Insert this one into the hash table. */
10828 t
= cl_target_option_node
;
10831 /* Make a new node for next time round. */
10832 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
10838 /* Determine the "ultimate origin" of a block. The block may be an inlined
10839 instance of an inlined instance of a block which is local to an inline
10840 function, so we have to trace all of the way back through the origin chain
10841 to find out what sort of node actually served as the original seed for the
10845 block_ultimate_origin (const_tree block
)
10847 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
10849 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
10850 nodes in the function to point to themselves; ignore that if
10851 we're trying to output the abstract instance of this function. */
10852 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
10855 if (immediate_origin
== NULL_TREE
)
10860 tree lookahead
= immediate_origin
;
10864 ret_val
= lookahead
;
10865 lookahead
= (TREE_CODE (ret_val
) == BLOCK
10866 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
10868 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
10870 /* The block's abstract origin chain may not be the *ultimate* origin of
10871 the block. It could lead to a DECL that has an abstract origin set.
10872 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
10873 will give us if it has one). Note that DECL's abstract origins are
10874 supposed to be the most distant ancestor (or so decl_ultimate_origin
10875 claims), so we don't need to loop following the DECL origins. */
10876 if (DECL_P (ret_val
))
10877 return DECL_ORIGIN (ret_val
);
10883 /* Return true if T1 and T2 are equivalent lists. */
10886 list_equal_p (const_tree t1
, const_tree t2
)
10888 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
10889 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
10894 /* Return true iff conversion in EXP generates no instruction. Mark
10895 it inline so that we fully inline into the stripping functions even
10896 though we have two uses of this function. */
10899 tree_nop_conversion (const_tree exp
)
10901 tree outer_type
, inner_type
;
10903 if (!CONVERT_EXPR_P (exp
)
10904 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
10906 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
10909 outer_type
= TREE_TYPE (exp
);
10910 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
10915 /* Use precision rather then machine mode when we can, which gives
10916 the correct answer even for submode (bit-field) types. */
10917 if ((INTEGRAL_TYPE_P (outer_type
)
10918 || POINTER_TYPE_P (outer_type
)
10919 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
10920 && (INTEGRAL_TYPE_P (inner_type
)
10921 || POINTER_TYPE_P (inner_type
)
10922 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
10923 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
10925 /* Otherwise fall back on comparing machine modes (e.g. for
10926 aggregate types, floats). */
10927 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
10930 /* Return true iff conversion in EXP generates no instruction. Don't
10931 consider conversions changing the signedness. */
10934 tree_sign_nop_conversion (const_tree exp
)
10936 tree outer_type
, inner_type
;
10938 if (!tree_nop_conversion (exp
))
10941 outer_type
= TREE_TYPE (exp
);
10942 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
10944 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
10945 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
10948 /* Strip conversions from EXP according to tree_nop_conversion and
10949 return the resulting expression. */
10952 tree_strip_nop_conversions (tree exp
)
10954 while (tree_nop_conversion (exp
))
10955 exp
= TREE_OPERAND (exp
, 0);
10959 /* Strip conversions from EXP according to tree_sign_nop_conversion
10960 and return the resulting expression. */
10963 tree_strip_sign_nop_conversions (tree exp
)
10965 while (tree_sign_nop_conversion (exp
))
10966 exp
= TREE_OPERAND (exp
, 0);
10970 static GTY(()) tree gcc_eh_personality_decl
;
10972 /* Return the GCC personality function decl. */
10975 lhd_gcc_personality (void)
10977 if (!gcc_eh_personality_decl
)
10978 gcc_eh_personality_decl
= build_personality_function ("gcc");
10979 return gcc_eh_personality_decl
;
10982 /* Try to find a base info of BINFO that would have its field decl at offset
10983 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
10984 found, return, otherwise return NULL_TREE. */
10987 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
10989 tree type
= BINFO_TYPE (binfo
);
10993 HOST_WIDE_INT pos
, size
;
10997 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (expected_type
))
11002 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
11004 if (TREE_CODE (fld
) != FIELD_DECL
)
11007 pos
= int_bit_position (fld
);
11008 size
= tree_low_cst (DECL_SIZE (fld
), 1);
11009 if (pos
<= offset
&& (pos
+ size
) > offset
)
11012 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
11015 if (!DECL_ARTIFICIAL (fld
))
11017 binfo
= TYPE_BINFO (TREE_TYPE (fld
));
11021 /* Offset 0 indicates the primary base, whose vtable contents are
11022 represented in the binfo for the derived class. */
11023 else if (offset
!= 0)
11025 tree base_binfo
, found_binfo
= NULL_TREE
;
11026 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11027 if (TREE_TYPE (base_binfo
) == TREE_TYPE (fld
))
11029 found_binfo
= base_binfo
;
11034 binfo
= found_binfo
;
11037 type
= TREE_TYPE (fld
);
11042 /* Returns true if X is a typedef decl. */
11045 is_typedef_decl (tree x
)
11047 return (x
&& TREE_CODE (x
) == TYPE_DECL
11048 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
11051 /* Returns true iff TYPE is a type variant created for a typedef. */
11054 typedef_variant_p (tree type
)
11056 return is_typedef_decl (TYPE_NAME (type
));
11059 /* Warn about a use of an identifier which was marked deprecated. */
11061 warn_deprecated_use (tree node
, tree attr
)
11065 if (node
== 0 || !warn_deprecated_decl
)
11071 attr
= DECL_ATTRIBUTES (node
);
11072 else if (TYPE_P (node
))
11074 tree decl
= TYPE_STUB_DECL (node
);
11076 attr
= lookup_attribute ("deprecated",
11077 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
11082 attr
= lookup_attribute ("deprecated", attr
);
11085 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
11091 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
11093 warning (OPT_Wdeprecated_declarations
,
11094 "%qD is deprecated (declared at %s:%d): %s",
11095 node
, xloc
.file
, xloc
.line
, msg
);
11097 warning (OPT_Wdeprecated_declarations
,
11098 "%qD is deprecated (declared at %s:%d)",
11099 node
, xloc
.file
, xloc
.line
);
11101 else if (TYPE_P (node
))
11103 tree what
= NULL_TREE
;
11104 tree decl
= TYPE_STUB_DECL (node
);
11106 if (TYPE_NAME (node
))
11108 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
11109 what
= TYPE_NAME (node
);
11110 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
11111 && DECL_NAME (TYPE_NAME (node
)))
11112 what
= DECL_NAME (TYPE_NAME (node
));
11117 expanded_location xloc
11118 = expand_location (DECL_SOURCE_LOCATION (decl
));
11122 warning (OPT_Wdeprecated_declarations
,
11123 "%qE is deprecated (declared at %s:%d): %s",
11124 what
, xloc
.file
, xloc
.line
, msg
);
11126 warning (OPT_Wdeprecated_declarations
,
11127 "%qE is deprecated (declared at %s:%d)", what
,
11128 xloc
.file
, xloc
.line
);
11133 warning (OPT_Wdeprecated_declarations
,
11134 "type is deprecated (declared at %s:%d): %s",
11135 xloc
.file
, xloc
.line
, msg
);
11137 warning (OPT_Wdeprecated_declarations
,
11138 "type is deprecated (declared at %s:%d)",
11139 xloc
.file
, xloc
.line
);
11147 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
11150 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
11155 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
11158 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
11164 #include "gt-tree.h"