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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
53 /* Each tree code class has an associated string representation.
54 These must correspond to the tree_code_class entries. */
56 const char *const tree_code_class_strings[] =
70 /* obstack.[ch] explicitly declined to prototype this. */
71 extern int _obstack_allocated_p (struct obstack *h, void *obj);
73 #ifdef GATHER_STATISTICS
74 /* Statistics-gathering stuff. */
76 int tree_node_counts[(int) all_kinds];
77 int tree_node_sizes[(int) all_kinds];
79 /* Keep in sync with tree.h:enum tree_node_kind. */
80 static const char * const tree_node_kind_names[] = {
99 #endif /* GATHER_STATISTICS */
101 /* Unique id for next decl created. */
102 static GTY(()) int next_decl_uid;
103 /* Unique id for next type created. */
104 static GTY(()) int next_type_uid = 1;
106 /* Since we cannot rehash a type after it is in the table, we have to
107 keep the hash code. */
109 struct type_hash GTY(())
115 /* Initial size of the hash table (rounded to next prime). */
116 #define TYPE_HASH_INITIAL_SIZE 1000
118 /* Now here is the hash table. When recording a type, it is added to
119 the slot whose index is the hash code. Note that the hash table is
120 used for several kinds of types (function types, array types and
121 array index range types, for now). While all these live in the
122 same table, they are completely independent, and the hash code is
123 computed differently for each of these. */
125 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
126 htab_t type_hash_table;
128 static void set_type_quals (tree, int);
129 static int type_hash_eq (const void *, const void *);
130 static hashval_t type_hash_hash (const void *);
131 static void print_type_hash_statistics (void);
132 static tree make_vector_type (tree, int, enum machine_mode);
133 static int type_hash_marked_p (const void *);
134 static unsigned int type_hash_list (tree, hashval_t);
135 static unsigned int attribute_hash_list (tree, hashval_t);
137 tree global_trees[TI_MAX];
138 tree integer_types[itk_none];
145 /* Initialize the hash table of types. */
146 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
151 /* The name of the object as the assembler will see it (but before any
152 translations made by ASM_OUTPUT_LABELREF). Often this is the same
153 as DECL_NAME. It is an IDENTIFIER_NODE. */
155 decl_assembler_name (tree decl)
157 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
158 lang_hooks.set_decl_assembler_name (decl);
159 return DECL_CHECK (decl)->decl.assembler_name;
162 /* Compute the number of bytes occupied by a tree with code CODE.
163 This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
164 codes, which are of variable length. */
166 tree_code_size (enum tree_code code)
168 switch (TREE_CODE_CLASS (code))
170 case tcc_declaration: /* A decl node */
171 return sizeof (struct tree_decl);
173 case tcc_type: /* a type node */
174 return sizeof (struct tree_type);
176 case tcc_reference: /* a reference */
177 case tcc_expression: /* an expression */
178 case tcc_statement: /* an expression with side effects */
179 case tcc_comparison: /* a comparison expression */
180 case tcc_unary: /* a unary arithmetic expression */
181 case tcc_binary: /* a binary arithmetic expression */
182 return (sizeof (struct tree_exp)
183 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
185 case tcc_constant: /* a constant */
188 case INTEGER_CST: return sizeof (struct tree_int_cst);
189 case REAL_CST: return sizeof (struct tree_real_cst);
190 case COMPLEX_CST: return sizeof (struct tree_complex);
191 case VECTOR_CST: return sizeof (struct tree_vector);
192 case STRING_CST: gcc_unreachable ();
194 return lang_hooks.tree_size (code);
197 case tcc_exceptional: /* something random, like an identifier. */
200 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
201 case TREE_LIST: return sizeof (struct tree_list);
204 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
207 case PHI_NODE: gcc_unreachable ();
209 case SSA_NAME: return sizeof (struct tree_ssa_name);
211 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
212 case BLOCK: return sizeof (struct tree_block);
213 case VALUE_HANDLE: return sizeof (struct tree_value_handle);
216 return lang_hooks.tree_size (code);
224 /* Compute the number of bytes occupied by NODE. This routine only
225 looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
227 tree_size (tree node)
229 enum tree_code code = TREE_CODE (node);
233 return (sizeof (struct tree_phi_node)
234 + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
237 return (sizeof (struct tree_vec)
238 + (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
241 return sizeof (struct tree_string) + TREE_STRING_LENGTH (node) - 1;
244 return tree_code_size (code);
248 /* Return a newly allocated node of code CODE. For decl and type
249 nodes, some other fields are initialized. The rest of the node is
250 initialized to zero. This function cannot be used for PHI_NODE or
251 TREE_VEC nodes, which is enforced by asserts in tree_code_size.
253 Achoo! I got a code in the node. */
256 make_node_stat (enum tree_code code MEM_STAT_DECL)
259 enum tree_code_class type = TREE_CODE_CLASS (code);
260 size_t length = tree_code_size (code);
261 #ifdef GATHER_STATISTICS
266 case tcc_declaration: /* A decl node */
270 case tcc_type: /* a type node */
274 case tcc_statement: /* an expression with side effects */
278 case tcc_reference: /* a reference */
282 case tcc_expression: /* an expression */
283 case tcc_comparison: /* a comparison expression */
284 case tcc_unary: /* a unary arithmetic expression */
285 case tcc_binary: /* a binary arithmetic expression */
289 case tcc_constant: /* a constant */
293 case tcc_exceptional: /* something random, like an identifier. */
296 case IDENTIFIER_NODE:
313 kind = ssa_name_kind;
330 tree_node_counts[(int) kind]++;
331 tree_node_sizes[(int) kind] += length;
334 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
336 memset (t, 0, length);
338 TREE_SET_CODE (t, code);
343 TREE_SIDE_EFFECTS (t) = 1;
346 case tcc_declaration:
347 if (code != FUNCTION_DECL)
349 DECL_USER_ALIGN (t) = 0;
350 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
351 DECL_SOURCE_LOCATION (t) = input_location;
352 DECL_UID (t) = next_decl_uid++;
354 /* We have not yet computed the alias set for this declaration. */
355 DECL_POINTER_ALIAS_SET (t) = -1;
359 TYPE_UID (t) = next_type_uid++;
360 TYPE_ALIGN (t) = char_type_node ? TYPE_ALIGN (char_type_node) : 0;
361 TYPE_USER_ALIGN (t) = 0;
362 TYPE_MAIN_VARIANT (t) = t;
364 /* Default to no attributes for type, but let target change that. */
365 TYPE_ATTRIBUTES (t) = NULL_TREE;
366 targetm.set_default_type_attributes (t);
368 /* We have not yet computed the alias set for this type. */
369 TYPE_ALIAS_SET (t) = -1;
373 TREE_CONSTANT (t) = 1;
374 TREE_INVARIANT (t) = 1;
383 case PREDECREMENT_EXPR:
384 case PREINCREMENT_EXPR:
385 case POSTDECREMENT_EXPR:
386 case POSTINCREMENT_EXPR:
387 /* All of these have side-effects, no matter what their
389 TREE_SIDE_EFFECTS (t) = 1;
398 /* Other classes need no special treatment. */
405 /* Return a new node with the same contents as NODE except that its
406 TREE_CHAIN is zero and it has a fresh uid. */
409 copy_node_stat (tree node MEM_STAT_DECL)
412 enum tree_code code = TREE_CODE (node);
415 gcc_assert (code != STATEMENT_LIST);
417 length = tree_size (node);
418 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
419 memcpy (t, node, length);
422 TREE_ASM_WRITTEN (t) = 0;
423 TREE_VISITED (t) = 0;
426 if (TREE_CODE_CLASS (code) == tcc_declaration)
427 DECL_UID (t) = next_decl_uid++;
428 else if (TREE_CODE_CLASS (code) == tcc_type)
430 TYPE_UID (t) = next_type_uid++;
431 /* The following is so that the debug code for
432 the copy is different from the original type.
433 The two statements usually duplicate each other
434 (because they clear fields of the same union),
435 but the optimizer should catch that. */
436 TYPE_SYMTAB_POINTER (t) = 0;
437 TYPE_SYMTAB_ADDRESS (t) = 0;
439 /* Do not copy the values cache. */
440 if (TYPE_CACHED_VALUES_P(t))
442 TYPE_CACHED_VALUES_P (t) = 0;
443 TYPE_CACHED_VALUES (t) = NULL_TREE;
450 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
451 For example, this can copy a list made of TREE_LIST nodes. */
454 copy_list (tree list)
462 head = prev = copy_node (list);
463 next = TREE_CHAIN (list);
466 TREE_CHAIN (prev) = copy_node (next);
467 prev = TREE_CHAIN (prev);
468 next = TREE_CHAIN (next);
474 /* Create an INT_CST node with a LOW value sign extended. */
477 build_int_cst (tree type, HOST_WIDE_INT low)
479 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
482 /* Create an INT_CST node with a LOW value zero extended. */
485 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
487 return build_int_cst_wide (type, low, 0);
490 /* Create an INT_CST node with a LOW value zero or sign extended depending
494 build_int_cst_type (tree type, HOST_WIDE_INT low)
496 unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
503 type = integer_type_node;
505 bits = TYPE_PRECISION (type);
506 signed_p = !TYPE_UNSIGNED (type);
507 negative = ((val >> (bits - 1)) & 1) != 0;
509 if (signed_p && negative)
511 if (bits < HOST_BITS_PER_WIDE_INT)
512 val = val | ((~(unsigned HOST_WIDE_INT) 0) << bits);
513 ret = build_int_cst_wide (type, val, ~(unsigned HOST_WIDE_INT) 0);
517 if (bits < HOST_BITS_PER_WIDE_INT)
518 val = val & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
519 ret = build_int_cst_wide (type, val, 0);
525 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
526 integer_type_node is used. */
529 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
536 type = integer_type_node;
538 switch (TREE_CODE (type))
542 /* Cache NULL pointer. */
551 /* Cache false or true. */
560 if (TYPE_UNSIGNED (type))
563 limit = INTEGER_SHARE_LIMIT;
564 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
570 limit = INTEGER_SHARE_LIMIT + 1;
571 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
573 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
583 if (!TYPE_CACHED_VALUES_P (type))
585 TYPE_CACHED_VALUES_P (type) = 1;
586 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
589 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
592 /* Make sure no one is clobbering the shared constant. */
593 gcc_assert (TREE_TYPE (t) == type);
594 gcc_assert (TREE_INT_CST_LOW (t) == low);
595 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
600 t = make_node (INTEGER_CST);
602 TREE_INT_CST_LOW (t) = low;
603 TREE_INT_CST_HIGH (t) = hi;
604 TREE_TYPE (t) = type;
607 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
612 /* Checks that X is integer constant that can be expressed in (unsigned)
613 HOST_WIDE_INT without loss of precision. */
616 cst_and_fits_in_hwi (tree x)
618 if (TREE_CODE (x) != INTEGER_CST)
621 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
624 return (TREE_INT_CST_HIGH (x) == 0
625 || TREE_INT_CST_HIGH (x) == -1);
628 /* Return a new VECTOR_CST node whose type is TYPE and whose values
629 are in a list pointed by VALS. */
632 build_vector (tree type, tree vals)
634 tree v = make_node (VECTOR_CST);
635 int over1 = 0, over2 = 0;
638 TREE_VECTOR_CST_ELTS (v) = vals;
639 TREE_TYPE (v) = type;
641 /* Iterate through elements and check for overflow. */
642 for (link = vals; link; link = TREE_CHAIN (link))
644 tree value = TREE_VALUE (link);
646 over1 |= TREE_OVERFLOW (value);
647 over2 |= TREE_CONSTANT_OVERFLOW (value);
650 TREE_OVERFLOW (v) = over1;
651 TREE_CONSTANT_OVERFLOW (v) = over2;
656 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
657 are in a list pointed to by VALS. */
659 build_constructor (tree type, tree vals)
661 tree c = make_node (CONSTRUCTOR);
662 TREE_TYPE (c) = type;
663 CONSTRUCTOR_ELTS (c) = vals;
665 /* ??? May not be necessary. Mirrors what build does. */
668 TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (vals);
669 TREE_READONLY (c) = TREE_READONLY (vals);
670 TREE_CONSTANT (c) = TREE_CONSTANT (vals);
671 TREE_INVARIANT (c) = TREE_INVARIANT (vals);
677 /* Return a new REAL_CST node whose type is TYPE and value is D. */
680 build_real (tree type, REAL_VALUE_TYPE d)
686 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
687 Consider doing it via real_convert now. */
689 v = make_node (REAL_CST);
690 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
691 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
693 TREE_TYPE (v) = type;
694 TREE_REAL_CST_PTR (v) = dp;
695 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
699 /* Return a new REAL_CST node whose type is TYPE
700 and whose value is the integer value of the INTEGER_CST node I. */
703 real_value_from_int_cst (tree type, tree i)
707 /* Clear all bits of the real value type so that we can later do
708 bitwise comparisons to see if two values are the same. */
709 memset (&d, 0, sizeof d);
711 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
712 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
713 TYPE_UNSIGNED (TREE_TYPE (i)));
717 /* Given a tree representing an integer constant I, return a tree
718 representing the same value as a floating-point constant of type TYPE. */
721 build_real_from_int_cst (tree type, tree i)
724 int overflow = TREE_OVERFLOW (i);
726 v = build_real (type, real_value_from_int_cst (type, i));
728 TREE_OVERFLOW (v) |= overflow;
729 TREE_CONSTANT_OVERFLOW (v) |= overflow;
733 /* Return a newly constructed STRING_CST node whose value is
734 the LEN characters at STR.
735 The TREE_TYPE is not initialized. */
738 build_string (int len, const char *str)
743 length = len + sizeof (struct tree_string);
745 #ifdef GATHER_STATISTICS
746 tree_node_counts[(int) c_kind]++;
747 tree_node_sizes[(int) c_kind] += length;
750 s = ggc_alloc_tree (length);
752 memset (s, 0, sizeof (struct tree_common));
753 TREE_SET_CODE (s, STRING_CST);
754 TREE_STRING_LENGTH (s) = len;
755 memcpy ((char *) TREE_STRING_POINTER (s), str, len);
756 ((char *) TREE_STRING_POINTER (s))[len] = '\0';
761 /* Return a newly constructed COMPLEX_CST node whose value is
762 specified by the real and imaginary parts REAL and IMAG.
763 Both REAL and IMAG should be constant nodes. TYPE, if specified,
764 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
767 build_complex (tree type, tree real, tree imag)
769 tree t = make_node (COMPLEX_CST);
771 TREE_REALPART (t) = real;
772 TREE_IMAGPART (t) = imag;
773 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
774 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
775 TREE_CONSTANT_OVERFLOW (t)
776 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
780 /* Build a BINFO with LEN language slots. */
783 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
786 size_t length = (offsetof (struct tree_binfo, base_binfos)
787 + VEC_embedded_size (tree, base_binfos));
789 #ifdef GATHER_STATISTICS
790 tree_node_counts[(int) binfo_kind]++;
791 tree_node_sizes[(int) binfo_kind] += length;
794 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
796 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
798 TREE_SET_CODE (t, TREE_BINFO);
800 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
806 /* Build a newly constructed TREE_VEC node of length LEN. */
809 make_tree_vec_stat (int len MEM_STAT_DECL)
812 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
814 #ifdef GATHER_STATISTICS
815 tree_node_counts[(int) vec_kind]++;
816 tree_node_sizes[(int) vec_kind] += length;
819 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
821 memset (t, 0, length);
823 TREE_SET_CODE (t, TREE_VEC);
824 TREE_VEC_LENGTH (t) = len;
829 /* Return 1 if EXPR is the integer constant zero or a complex constant
833 integer_zerop (tree expr)
837 return ((TREE_CODE (expr) == INTEGER_CST
838 && ! TREE_CONSTANT_OVERFLOW (expr)
839 && TREE_INT_CST_LOW (expr) == 0
840 && TREE_INT_CST_HIGH (expr) == 0)
841 || (TREE_CODE (expr) == COMPLEX_CST
842 && integer_zerop (TREE_REALPART (expr))
843 && integer_zerop (TREE_IMAGPART (expr))));
846 /* Return 1 if EXPR is the integer constant one or the corresponding
850 integer_onep (tree expr)
854 return ((TREE_CODE (expr) == INTEGER_CST
855 && ! TREE_CONSTANT_OVERFLOW (expr)
856 && TREE_INT_CST_LOW (expr) == 1
857 && TREE_INT_CST_HIGH (expr) == 0)
858 || (TREE_CODE (expr) == COMPLEX_CST
859 && integer_onep (TREE_REALPART (expr))
860 && integer_zerop (TREE_IMAGPART (expr))));
863 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
864 it contains. Likewise for the corresponding complex constant. */
867 integer_all_onesp (tree expr)
874 if (TREE_CODE (expr) == COMPLEX_CST
875 && integer_all_onesp (TREE_REALPART (expr))
876 && integer_zerop (TREE_IMAGPART (expr)))
879 else if (TREE_CODE (expr) != INTEGER_CST
880 || TREE_CONSTANT_OVERFLOW (expr))
883 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
885 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
886 && TREE_INT_CST_HIGH (expr) == -1);
888 /* Note that using TYPE_PRECISION here is wrong. We care about the
889 actual bits, not the (arbitrary) range of the type. */
890 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
891 if (prec >= HOST_BITS_PER_WIDE_INT)
893 HOST_WIDE_INT high_value;
896 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
898 /* Can not handle precisions greater than twice the host int size. */
899 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
900 if (shift_amount == HOST_BITS_PER_WIDE_INT)
901 /* Shifting by the host word size is undefined according to the ANSI
902 standard, so we must handle this as a special case. */
905 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
907 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
908 && TREE_INT_CST_HIGH (expr) == high_value);
911 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
914 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
918 integer_pow2p (tree expr)
921 HOST_WIDE_INT high, low;
925 if (TREE_CODE (expr) == COMPLEX_CST
926 && integer_pow2p (TREE_REALPART (expr))
927 && integer_zerop (TREE_IMAGPART (expr)))
930 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
933 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
934 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
935 high = TREE_INT_CST_HIGH (expr);
936 low = TREE_INT_CST_LOW (expr);
938 /* First clear all bits that are beyond the type's precision in case
939 we've been sign extended. */
941 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
943 else if (prec > HOST_BITS_PER_WIDE_INT)
944 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
948 if (prec < HOST_BITS_PER_WIDE_INT)
949 low &= ~((HOST_WIDE_INT) (-1) << prec);
952 if (high == 0 && low == 0)
955 return ((high == 0 && (low & (low - 1)) == 0)
956 || (low == 0 && (high & (high - 1)) == 0));
959 /* Return 1 if EXPR is an integer constant other than zero or a
960 complex constant other than zero. */
963 integer_nonzerop (tree expr)
967 return ((TREE_CODE (expr) == INTEGER_CST
968 && ! TREE_CONSTANT_OVERFLOW (expr)
969 && (TREE_INT_CST_LOW (expr) != 0
970 || TREE_INT_CST_HIGH (expr) != 0))
971 || (TREE_CODE (expr) == COMPLEX_CST
972 && (integer_nonzerop (TREE_REALPART (expr))
973 || integer_nonzerop (TREE_IMAGPART (expr)))));
976 /* Return the power of two represented by a tree node known to be a
980 tree_log2 (tree expr)
983 HOST_WIDE_INT high, low;
987 if (TREE_CODE (expr) == COMPLEX_CST)
988 return tree_log2 (TREE_REALPART (expr));
990 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
991 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
993 high = TREE_INT_CST_HIGH (expr);
994 low = TREE_INT_CST_LOW (expr);
996 /* First clear all bits that are beyond the type's precision in case
997 we've been sign extended. */
999 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1001 else if (prec > HOST_BITS_PER_WIDE_INT)
1002 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1006 if (prec < HOST_BITS_PER_WIDE_INT)
1007 low &= ~((HOST_WIDE_INT) (-1) << prec);
1010 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1011 : exact_log2 (low));
1014 /* Similar, but return the largest integer Y such that 2 ** Y is less
1015 than or equal to EXPR. */
1018 tree_floor_log2 (tree expr)
1021 HOST_WIDE_INT high, low;
1025 if (TREE_CODE (expr) == COMPLEX_CST)
1026 return tree_log2 (TREE_REALPART (expr));
1028 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1029 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1031 high = TREE_INT_CST_HIGH (expr);
1032 low = TREE_INT_CST_LOW (expr);
1034 /* First clear all bits that are beyond the type's precision in case
1035 we've been sign extended. Ignore if type's precision hasn't been set
1036 since what we are doing is setting it. */
1038 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1040 else if (prec > HOST_BITS_PER_WIDE_INT)
1041 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1045 if (prec < HOST_BITS_PER_WIDE_INT)
1046 low &= ~((HOST_WIDE_INT) (-1) << prec);
1049 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1050 : floor_log2 (low));
1053 /* Return 1 if EXPR is the real constant zero. */
1056 real_zerop (tree expr)
1060 return ((TREE_CODE (expr) == REAL_CST
1061 && ! TREE_CONSTANT_OVERFLOW (expr)
1062 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1063 || (TREE_CODE (expr) == COMPLEX_CST
1064 && real_zerop (TREE_REALPART (expr))
1065 && real_zerop (TREE_IMAGPART (expr))));
1068 /* Return 1 if EXPR is the real constant one in real or complex form. */
1071 real_onep (tree expr)
1075 return ((TREE_CODE (expr) == REAL_CST
1076 && ! TREE_CONSTANT_OVERFLOW (expr)
1077 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1078 || (TREE_CODE (expr) == COMPLEX_CST
1079 && real_onep (TREE_REALPART (expr))
1080 && real_zerop (TREE_IMAGPART (expr))));
1083 /* Return 1 if EXPR is the real constant two. */
1086 real_twop (tree expr)
1090 return ((TREE_CODE (expr) == REAL_CST
1091 && ! TREE_CONSTANT_OVERFLOW (expr)
1092 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1093 || (TREE_CODE (expr) == COMPLEX_CST
1094 && real_twop (TREE_REALPART (expr))
1095 && real_zerop (TREE_IMAGPART (expr))));
1098 /* Return 1 if EXPR is the real constant minus one. */
1101 real_minus_onep (tree expr)
1105 return ((TREE_CODE (expr) == REAL_CST
1106 && ! TREE_CONSTANT_OVERFLOW (expr)
1107 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1108 || (TREE_CODE (expr) == COMPLEX_CST
1109 && real_minus_onep (TREE_REALPART (expr))
1110 && real_zerop (TREE_IMAGPART (expr))));
1113 /* Nonzero if EXP is a constant or a cast of a constant. */
1116 really_constant_p (tree exp)
1118 /* This is not quite the same as STRIP_NOPS. It does more. */
1119 while (TREE_CODE (exp) == NOP_EXPR
1120 || TREE_CODE (exp) == CONVERT_EXPR
1121 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1122 exp = TREE_OPERAND (exp, 0);
1123 return TREE_CONSTANT (exp);
1126 /* Return first list element whose TREE_VALUE is ELEM.
1127 Return 0 if ELEM is not in LIST. */
1130 value_member (tree elem, tree list)
1134 if (elem == TREE_VALUE (list))
1136 list = TREE_CHAIN (list);
1141 /* Return first list element whose TREE_PURPOSE is ELEM.
1142 Return 0 if ELEM is not in LIST. */
1145 purpose_member (tree elem, tree list)
1149 if (elem == TREE_PURPOSE (list))
1151 list = TREE_CHAIN (list);
1156 /* Return nonzero if ELEM is part of the chain CHAIN. */
1159 chain_member (tree elem, tree chain)
1165 chain = TREE_CHAIN (chain);
1171 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1172 We expect a null pointer to mark the end of the chain.
1173 This is the Lisp primitive `length'. */
1176 list_length (tree t)
1179 #ifdef ENABLE_TREE_CHECKING
1187 #ifdef ENABLE_TREE_CHECKING
1190 gcc_assert (p != q);
1198 /* Returns the number of FIELD_DECLs in TYPE. */
1201 fields_length (tree type)
1203 tree t = TYPE_FIELDS (type);
1206 for (; t; t = TREE_CHAIN (t))
1207 if (TREE_CODE (t) == FIELD_DECL)
1213 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1214 by modifying the last node in chain 1 to point to chain 2.
1215 This is the Lisp primitive `nconc'. */
1218 chainon (tree op1, tree op2)
1227 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1229 TREE_CHAIN (t1) = op2;
1231 #ifdef ENABLE_TREE_CHECKING
1234 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1235 gcc_assert (t2 != t1);
1242 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1245 tree_last (tree chain)
1249 while ((next = TREE_CHAIN (chain)))
1254 /* Reverse the order of elements in the chain T,
1255 and return the new head of the chain (old last element). */
1260 tree prev = 0, decl, next;
1261 for (decl = t; decl; decl = next)
1263 next = TREE_CHAIN (decl);
1264 TREE_CHAIN (decl) = prev;
1270 /* Return a newly created TREE_LIST node whose
1271 purpose and value fields are PARM and VALUE. */
1274 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1276 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1277 TREE_PURPOSE (t) = parm;
1278 TREE_VALUE (t) = value;
1282 /* Return a newly created TREE_LIST node whose
1283 purpose and value fields are PURPOSE and VALUE
1284 and whose TREE_CHAIN is CHAIN. */
1287 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1291 node = ggc_alloc_zone_stat (sizeof (struct tree_list),
1292 tree_zone PASS_MEM_STAT);
1294 memset (node, 0, sizeof (struct tree_common));
1296 #ifdef GATHER_STATISTICS
1297 tree_node_counts[(int) x_kind]++;
1298 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1301 TREE_SET_CODE (node, TREE_LIST);
1302 TREE_CHAIN (node) = chain;
1303 TREE_PURPOSE (node) = purpose;
1304 TREE_VALUE (node) = value;
1309 /* Return the size nominally occupied by an object of type TYPE
1310 when it resides in memory. The value is measured in units of bytes,
1311 and its data type is that normally used for type sizes
1312 (which is the first type created by make_signed_type or
1313 make_unsigned_type). */
1316 size_in_bytes (tree type)
1320 if (type == error_mark_node)
1321 return integer_zero_node;
1323 type = TYPE_MAIN_VARIANT (type);
1324 t = TYPE_SIZE_UNIT (type);
1328 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1329 return size_zero_node;
1332 if (TREE_CODE (t) == INTEGER_CST)
1333 t = force_fit_type (t, 0, false, false);
1338 /* Return the size of TYPE (in bytes) as a wide integer
1339 or return -1 if the size can vary or is larger than an integer. */
1342 int_size_in_bytes (tree type)
1346 if (type == error_mark_node)
1349 type = TYPE_MAIN_VARIANT (type);
1350 t = TYPE_SIZE_UNIT (type);
1352 || TREE_CODE (t) != INTEGER_CST
1353 || TREE_OVERFLOW (t)
1354 || TREE_INT_CST_HIGH (t) != 0
1355 /* If the result would appear negative, it's too big to represent. */
1356 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1359 return TREE_INT_CST_LOW (t);
1362 /* Return the bit position of FIELD, in bits from the start of the record.
1363 This is a tree of type bitsizetype. */
1366 bit_position (tree field)
1368 return bit_from_pos (DECL_FIELD_OFFSET (field),
1369 DECL_FIELD_BIT_OFFSET (field));
1372 /* Likewise, but return as an integer. Abort if it cannot be represented
1373 in that way (since it could be a signed value, we don't have the option
1374 of returning -1 like int_size_in_byte can. */
1377 int_bit_position (tree field)
1379 return tree_low_cst (bit_position (field), 0);
1382 /* Return the byte position of FIELD, in bytes from the start of the record.
1383 This is a tree of type sizetype. */
1386 byte_position (tree field)
1388 return byte_from_pos (DECL_FIELD_OFFSET (field),
1389 DECL_FIELD_BIT_OFFSET (field));
1392 /* Likewise, but return as an integer. Abort if it cannot be represented
1393 in that way (since it could be a signed value, we don't have the option
1394 of returning -1 like int_size_in_byte can. */
1397 int_byte_position (tree field)
1399 return tree_low_cst (byte_position (field), 0);
1402 /* Return the strictest alignment, in bits, that T is known to have. */
1407 unsigned int align0, align1;
1409 switch (TREE_CODE (t))
1411 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1412 /* If we have conversions, we know that the alignment of the
1413 object must meet each of the alignments of the types. */
1414 align0 = expr_align (TREE_OPERAND (t, 0));
1415 align1 = TYPE_ALIGN (TREE_TYPE (t));
1416 return MAX (align0, align1);
1418 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1419 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1420 case CLEANUP_POINT_EXPR:
1421 /* These don't change the alignment of an object. */
1422 return expr_align (TREE_OPERAND (t, 0));
1425 /* The best we can do is say that the alignment is the least aligned
1427 align0 = expr_align (TREE_OPERAND (t, 1));
1428 align1 = expr_align (TREE_OPERAND (t, 2));
1429 return MIN (align0, align1);
1431 case LABEL_DECL: case CONST_DECL:
1432 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1433 if (DECL_ALIGN (t) != 0)
1434 return DECL_ALIGN (t);
1438 return FUNCTION_BOUNDARY;
1444 /* Otherwise take the alignment from that of the type. */
1445 return TYPE_ALIGN (TREE_TYPE (t));
1448 /* Return, as a tree node, the number of elements for TYPE (which is an
1449 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1452 array_type_nelts (tree type)
1454 tree index_type, min, max;
1456 /* If they did it with unspecified bounds, then we should have already
1457 given an error about it before we got here. */
1458 if (! TYPE_DOMAIN (type))
1459 return error_mark_node;
1461 index_type = TYPE_DOMAIN (type);
1462 min = TYPE_MIN_VALUE (index_type);
1463 max = TYPE_MAX_VALUE (index_type);
1465 return (integer_zerop (min)
1467 : fold (build2 (MINUS_EXPR, TREE_TYPE (max), max, min)));
1470 /* If arg is static -- a reference to an object in static storage -- then
1471 return the object. This is not the same as the C meaning of `static'.
1472 If arg isn't static, return NULL. */
1477 switch (TREE_CODE (arg))
1480 /* Nested functions aren't static, since taking their address
1481 involves a trampoline. */
1482 return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
1483 && ! DECL_NON_ADDR_CONST_P (arg)
1487 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1488 && ! DECL_THREAD_LOCAL (arg)
1489 && ! DECL_NON_ADDR_CONST_P (arg)
1493 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1497 return TREE_STATIC (arg) ? arg : NULL;
1504 /* If the thing being referenced is not a field, then it is
1505 something language specific. */
1506 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
1507 return (*lang_hooks.staticp) (arg);
1509 /* If we are referencing a bitfield, we can't evaluate an
1510 ADDR_EXPR at compile time and so it isn't a constant. */
1511 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
1514 return staticp (TREE_OPERAND (arg, 0));
1519 case MISALIGNED_INDIRECT_REF:
1520 case ALIGN_INDIRECT_REF:
1522 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
1525 case ARRAY_RANGE_REF:
1526 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1527 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1528 return staticp (TREE_OPERAND (arg, 0));
1533 if ((unsigned int) TREE_CODE (arg)
1534 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1535 return lang_hooks.staticp (arg);
1541 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1542 Do this to any expression which may be used in more than one place,
1543 but must be evaluated only once.
1545 Normally, expand_expr would reevaluate the expression each time.
1546 Calling save_expr produces something that is evaluated and recorded
1547 the first time expand_expr is called on it. Subsequent calls to
1548 expand_expr just reuse the recorded value.
1550 The call to expand_expr that generates code that actually computes
1551 the value is the first call *at compile time*. Subsequent calls
1552 *at compile time* generate code to use the saved value.
1553 This produces correct result provided that *at run time* control
1554 always flows through the insns made by the first expand_expr
1555 before reaching the other places where the save_expr was evaluated.
1556 You, the caller of save_expr, must make sure this is so.
1558 Constants, and certain read-only nodes, are returned with no
1559 SAVE_EXPR because that is safe. Expressions containing placeholders
1560 are not touched; see tree.def for an explanation of what these
1564 save_expr (tree expr)
1566 tree t = fold (expr);
1569 /* If the tree evaluates to a constant, then we don't want to hide that
1570 fact (i.e. this allows further folding, and direct checks for constants).
1571 However, a read-only object that has side effects cannot be bypassed.
1572 Since it is no problem to reevaluate literals, we just return the
1574 inner = skip_simple_arithmetic (t);
1576 if (TREE_INVARIANT (inner)
1577 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1578 || TREE_CODE (inner) == SAVE_EXPR
1579 || TREE_CODE (inner) == ERROR_MARK)
1582 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1583 it means that the size or offset of some field of an object depends on
1584 the value within another field.
1586 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1587 and some variable since it would then need to be both evaluated once and
1588 evaluated more than once. Front-ends must assure this case cannot
1589 happen by surrounding any such subexpressions in their own SAVE_EXPR
1590 and forcing evaluation at the proper time. */
1591 if (contains_placeholder_p (inner))
1594 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
1596 /* This expression might be placed ahead of a jump to ensure that the
1597 value was computed on both sides of the jump. So make sure it isn't
1598 eliminated as dead. */
1599 TREE_SIDE_EFFECTS (t) = 1;
1600 TREE_INVARIANT (t) = 1;
1604 /* Look inside EXPR and into any simple arithmetic operations. Return
1605 the innermost non-arithmetic node. */
1608 skip_simple_arithmetic (tree expr)
1612 /* We don't care about whether this can be used as an lvalue in this
1614 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1615 expr = TREE_OPERAND (expr, 0);
1617 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1618 a constant, it will be more efficient to not make another SAVE_EXPR since
1619 it will allow better simplification and GCSE will be able to merge the
1620 computations if they actually occur. */
1624 if (UNARY_CLASS_P (inner))
1625 inner = TREE_OPERAND (inner, 0);
1626 else if (BINARY_CLASS_P (inner))
1628 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
1629 inner = TREE_OPERAND (inner, 0);
1630 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
1631 inner = TREE_OPERAND (inner, 1);
1642 /* Returns the index of the first non-tree operand for CODE, or the number
1643 of operands if all are trees. */
1646 first_rtl_op (enum tree_code code)
1651 return TREE_CODE_LENGTH (code);
1655 /* Return which tree structure is used by T. */
1657 enum tree_node_structure_enum
1658 tree_node_structure (tree t)
1660 enum tree_code code = TREE_CODE (t);
1662 switch (TREE_CODE_CLASS (code))
1664 case tcc_declaration:
1669 case tcc_comparison:
1672 case tcc_expression:
1675 default: /* tcc_constant and tcc_exceptional */
1680 /* tcc_constant cases. */
1681 case INTEGER_CST: return TS_INT_CST;
1682 case REAL_CST: return TS_REAL_CST;
1683 case COMPLEX_CST: return TS_COMPLEX;
1684 case VECTOR_CST: return TS_VECTOR;
1685 case STRING_CST: return TS_STRING;
1686 /* tcc_exceptional cases. */
1687 case ERROR_MARK: return TS_COMMON;
1688 case IDENTIFIER_NODE: return TS_IDENTIFIER;
1689 case TREE_LIST: return TS_LIST;
1690 case TREE_VEC: return TS_VEC;
1691 case PHI_NODE: return TS_PHI_NODE;
1692 case SSA_NAME: return TS_SSA_NAME;
1693 case PLACEHOLDER_EXPR: return TS_COMMON;
1694 case STATEMENT_LIST: return TS_STATEMENT_LIST;
1695 case BLOCK: return TS_BLOCK;
1696 case TREE_BINFO: return TS_BINFO;
1697 case VALUE_HANDLE: return TS_VALUE_HANDLE;
1704 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1705 or offset that depends on a field within a record. */
1708 contains_placeholder_p (tree exp)
1710 enum tree_code code;
1715 code = TREE_CODE (exp);
1716 if (code == PLACEHOLDER_EXPR)
1719 switch (TREE_CODE_CLASS (code))
1722 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1723 position computations since they will be converted into a
1724 WITH_RECORD_EXPR involving the reference, which will assume
1725 here will be valid. */
1726 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1728 case tcc_exceptional:
1729 if (code == TREE_LIST)
1730 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
1731 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
1736 case tcc_comparison:
1737 case tcc_expression:
1741 /* Ignoring the first operand isn't quite right, but works best. */
1742 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1745 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1746 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
1747 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
1753 switch (first_rtl_op (code))
1756 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1758 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1759 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
1770 /* Return true if any part of the computation of TYPE involves a
1771 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
1772 (for QUAL_UNION_TYPE) and field positions. */
1775 type_contains_placeholder_1 (tree type)
1777 /* If the size contains a placeholder or the parent type (component type in
1778 the case of arrays) type involves a placeholder, this type does. */
1779 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1780 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
1781 || (TREE_TYPE (type) != 0
1782 && type_contains_placeholder_p (TREE_TYPE (type))))
1785 /* Now do type-specific checks. Note that the last part of the check above
1786 greatly limits what we have to do below. */
1787 switch (TREE_CODE (type))
1796 case REFERENCE_TYPE:
1804 /* Here we just check the bounds. */
1805 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
1806 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
1811 /* We're already checked the component type (TREE_TYPE), so just check
1813 return type_contains_placeholder_p (TYPE_DOMAIN (type));
1817 case QUAL_UNION_TYPE:
1821 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1822 if (TREE_CODE (field) == FIELD_DECL
1823 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
1824 || (TREE_CODE (type) == QUAL_UNION_TYPE
1825 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
1826 || type_contains_placeholder_p (TREE_TYPE (field))))
1838 type_contains_placeholder_p (tree type)
1842 /* If the contains_placeholder_bits field has been initialized,
1843 then we know the answer. */
1844 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
1845 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
1847 /* Indicate that we've seen this type node, and the answer is false.
1848 This is what we want to return if we run into recursion via fields. */
1849 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
1851 /* Compute the real value. */
1852 result = type_contains_placeholder_1 (type);
1854 /* Store the real value. */
1855 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
1860 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1861 return a tree with all occurrences of references to F in a
1862 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1863 contains only arithmetic expressions or a CALL_EXPR with a
1864 PLACEHOLDER_EXPR occurring only in its arglist. */
1867 substitute_in_expr (tree exp, tree f, tree r)
1869 enum tree_code code = TREE_CODE (exp);
1874 /* We handle TREE_LIST and COMPONENT_REF separately. */
1875 if (code == TREE_LIST)
1877 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
1878 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
1879 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1882 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1884 else if (code == COMPONENT_REF)
1886 /* If this expression is getting a value from a PLACEHOLDER_EXPR
1887 and it is the right field, replace it with R. */
1888 for (inner = TREE_OPERAND (exp, 0);
1889 REFERENCE_CLASS_P (inner);
1890 inner = TREE_OPERAND (inner, 0))
1892 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
1893 && TREE_OPERAND (exp, 1) == f)
1896 /* If this expression hasn't been completed let, leave it alone. */
1897 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
1900 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1901 if (op0 == TREE_OPERAND (exp, 0))
1904 new = fold (build3 (COMPONENT_REF, TREE_TYPE (exp),
1905 op0, TREE_OPERAND (exp, 1), NULL_TREE));
1908 switch (TREE_CODE_CLASS (code))
1911 case tcc_declaration:
1914 case tcc_exceptional:
1917 case tcc_comparison:
1918 case tcc_expression:
1920 switch (first_rtl_op (code))
1926 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1927 if (op0 == TREE_OPERAND (exp, 0))
1930 new = fold (build1 (code, TREE_TYPE (exp), op0));
1934 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1935 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1937 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
1940 new = fold (build2 (code, TREE_TYPE (exp), op0, op1));
1944 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1945 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1946 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
1948 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
1949 && op2 == TREE_OPERAND (exp, 2))
1952 new = fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
1964 TREE_READONLY (new) = TREE_READONLY (exp);
1968 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
1969 for it within OBJ, a tree that is an object or a chain of references. */
1972 substitute_placeholder_in_expr (tree exp, tree obj)
1974 enum tree_code code = TREE_CODE (exp);
1975 tree op0, op1, op2, op3;
1977 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
1978 in the chain of OBJ. */
1979 if (code == PLACEHOLDER_EXPR)
1981 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
1984 for (elt = obj; elt != 0;
1985 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
1986 || TREE_CODE (elt) == COND_EXPR)
1987 ? TREE_OPERAND (elt, 1)
1988 : (REFERENCE_CLASS_P (elt)
1989 || UNARY_CLASS_P (elt)
1990 || BINARY_CLASS_P (elt)
1991 || EXPRESSION_CLASS_P (elt))
1992 ? TREE_OPERAND (elt, 0) : 0))
1993 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
1996 for (elt = obj; elt != 0;
1997 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
1998 || TREE_CODE (elt) == COND_EXPR)
1999 ? TREE_OPERAND (elt, 1)
2000 : (REFERENCE_CLASS_P (elt)
2001 || UNARY_CLASS_P (elt)
2002 || BINARY_CLASS_P (elt)
2003 || EXPRESSION_CLASS_P (elt))
2004 ? TREE_OPERAND (elt, 0) : 0))
2005 if (POINTER_TYPE_P (TREE_TYPE (elt))
2006 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2008 return fold (build1 (INDIRECT_REF, need_type, elt));
2010 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2011 survives until RTL generation, there will be an error. */
2015 /* TREE_LIST is special because we need to look at TREE_VALUE
2016 and TREE_CHAIN, not TREE_OPERANDS. */
2017 else if (code == TREE_LIST)
2019 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2020 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2021 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2024 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2027 switch (TREE_CODE_CLASS (code))
2030 case tcc_declaration:
2033 case tcc_exceptional:
2036 case tcc_comparison:
2037 case tcc_expression:
2040 switch (first_rtl_op (code))
2046 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2047 if (op0 == TREE_OPERAND (exp, 0))
2050 return fold (build1 (code, TREE_TYPE (exp), op0));
2053 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2054 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2056 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2059 return fold (build2 (code, TREE_TYPE (exp), op0, op1));
2062 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2063 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2064 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2066 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2067 && op2 == TREE_OPERAND (exp, 2))
2070 return fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
2073 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2074 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2075 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2076 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2078 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2079 && op2 == TREE_OPERAND (exp, 2)
2080 && op3 == TREE_OPERAND (exp, 3))
2083 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2095 /* Stabilize a reference so that we can use it any number of times
2096 without causing its operands to be evaluated more than once.
2097 Returns the stabilized reference. This works by means of save_expr,
2098 so see the caveats in the comments about save_expr.
2100 Also allows conversion expressions whose operands are references.
2101 Any other kind of expression is returned unchanged. */
2104 stabilize_reference (tree ref)
2107 enum tree_code code = TREE_CODE (ref);
2114 /* No action is needed in this case. */
2120 case FIX_TRUNC_EXPR:
2121 case FIX_FLOOR_EXPR:
2122 case FIX_ROUND_EXPR:
2124 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2128 result = build_nt (INDIRECT_REF,
2129 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2133 result = build_nt (COMPONENT_REF,
2134 stabilize_reference (TREE_OPERAND (ref, 0)),
2135 TREE_OPERAND (ref, 1), NULL_TREE);
2139 result = build_nt (BIT_FIELD_REF,
2140 stabilize_reference (TREE_OPERAND (ref, 0)),
2141 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2142 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2146 result = build_nt (ARRAY_REF,
2147 stabilize_reference (TREE_OPERAND (ref, 0)),
2148 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2149 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2152 case ARRAY_RANGE_REF:
2153 result = build_nt (ARRAY_RANGE_REF,
2154 stabilize_reference (TREE_OPERAND (ref, 0)),
2155 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2156 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2160 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2161 it wouldn't be ignored. This matters when dealing with
2163 return stabilize_reference_1 (ref);
2165 /* If arg isn't a kind of lvalue we recognize, make no change.
2166 Caller should recognize the error for an invalid lvalue. */
2171 return error_mark_node;
2174 TREE_TYPE (result) = TREE_TYPE (ref);
2175 TREE_READONLY (result) = TREE_READONLY (ref);
2176 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2177 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2182 /* Subroutine of stabilize_reference; this is called for subtrees of
2183 references. Any expression with side-effects must be put in a SAVE_EXPR
2184 to ensure that it is only evaluated once.
2186 We don't put SAVE_EXPR nodes around everything, because assigning very
2187 simple expressions to temporaries causes us to miss good opportunities
2188 for optimizations. Among other things, the opportunity to fold in the
2189 addition of a constant into an addressing mode often gets lost, e.g.
2190 "y[i+1] += x;". In general, we take the approach that we should not make
2191 an assignment unless we are forced into it - i.e., that any non-side effect
2192 operator should be allowed, and that cse should take care of coalescing
2193 multiple utterances of the same expression should that prove fruitful. */
2196 stabilize_reference_1 (tree e)
2199 enum tree_code code = TREE_CODE (e);
2201 /* We cannot ignore const expressions because it might be a reference
2202 to a const array but whose index contains side-effects. But we can
2203 ignore things that are actual constant or that already have been
2204 handled by this function. */
2206 if (TREE_INVARIANT (e))
2209 switch (TREE_CODE_CLASS (code))
2211 case tcc_exceptional:
2213 case tcc_declaration:
2214 case tcc_comparison:
2216 case tcc_expression:
2218 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2219 so that it will only be evaluated once. */
2220 /* The reference (r) and comparison (<) classes could be handled as
2221 below, but it is generally faster to only evaluate them once. */
2222 if (TREE_SIDE_EFFECTS (e))
2223 return save_expr (e);
2227 /* Constants need no processing. In fact, we should never reach
2232 /* Division is slow and tends to be compiled with jumps,
2233 especially the division by powers of 2 that is often
2234 found inside of an array reference. So do it just once. */
2235 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2236 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2237 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2238 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2239 return save_expr (e);
2240 /* Recursively stabilize each operand. */
2241 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2242 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2246 /* Recursively stabilize each operand. */
2247 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2254 TREE_TYPE (result) = TREE_TYPE (e);
2255 TREE_READONLY (result) = TREE_READONLY (e);
2256 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2257 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2258 TREE_INVARIANT (result) = 1;
2263 /* Low-level constructors for expressions. */
2265 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2266 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2269 recompute_tree_invarant_for_addr_expr (tree t)
2272 bool tc = true, ti = true, se = false;
2274 /* We started out assuming this address is both invariant and constant, but
2275 does not have side effects. Now go down any handled components and see if
2276 any of them involve offsets that are either non-constant or non-invariant.
2277 Also check for side-effects.
2279 ??? Note that this code makes no attempt to deal with the case where
2280 taking the address of something causes a copy due to misalignment. */
2282 #define UPDATE_TITCSE(NODE) \
2283 do { tree _node = (NODE); \
2284 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2285 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2286 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2288 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2289 node = TREE_OPERAND (node, 0))
2291 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2292 array reference (probably made temporarily by the G++ front end),
2293 so ignore all the operands. */
2294 if ((TREE_CODE (node) == ARRAY_REF
2295 || TREE_CODE (node) == ARRAY_RANGE_REF)
2296 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2298 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2299 if (TREE_OPERAND (node, 2))
2300 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2301 if (TREE_OPERAND (node, 3))
2302 UPDATE_TITCSE (TREE_OPERAND (node, 3));
2304 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2305 FIELD_DECL, apparently. The G++ front end can put something else
2306 there, at least temporarily. */
2307 else if (TREE_CODE (node) == COMPONENT_REF
2308 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2310 if (TREE_OPERAND (node, 2))
2311 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2313 else if (TREE_CODE (node) == BIT_FIELD_REF)
2314 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2317 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2318 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2319 invariant and constant if the decl is static. It's also invariant if it's
2320 a decl in the current function. Taking the address of a volatile variable
2321 is not volatile. If it's a constant, the address is both invariant and
2322 constant. Otherwise it's neither. */
2323 if (TREE_CODE (node) == INDIRECT_REF)
2324 UPDATE_TITCSE (TREE_OPERAND (node, 0));
2325 else if (DECL_P (node))
2329 else if (decl_function_context (node) == current_function_decl)
2334 else if (CONSTANT_CLASS_P (node))
2339 se |= TREE_SIDE_EFFECTS (node);
2342 TREE_CONSTANT (t) = tc;
2343 TREE_INVARIANT (t) = ti;
2344 TREE_SIDE_EFFECTS (t) = se;
2345 #undef UPDATE_TITCSE
2348 /* Build an expression of code CODE, data type TYPE, and operands as
2349 specified. Expressions and reference nodes can be created this way.
2350 Constants, decls, types and misc nodes cannot be.
2352 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2353 enough for all extant tree codes. These functions can be called
2354 directly (preferably!), but can also be obtained via GCC preprocessor
2355 magic within the build macro. */
2358 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2362 gcc_assert (TREE_CODE_LENGTH (code) == 0);
2364 t = make_node_stat (code PASS_MEM_STAT);
2371 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2373 int length = sizeof (struct tree_exp);
2374 #ifdef GATHER_STATISTICS
2375 tree_node_kind kind;
2379 #ifdef GATHER_STATISTICS
2380 switch (TREE_CODE_CLASS (code))
2382 case tcc_statement: /* an expression with side effects */
2385 case tcc_reference: /* a reference */
2393 tree_node_counts[(int) kind]++;
2394 tree_node_sizes[(int) kind] += length;
2397 gcc_assert (TREE_CODE_LENGTH (code) == 1);
2399 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
2401 memset (t, 0, sizeof (struct tree_common));
2403 TREE_SET_CODE (t, code);
2405 TREE_TYPE (t) = type;
2406 #ifdef USE_MAPPED_LOCATION
2407 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
2409 SET_EXPR_LOCUS (t, NULL);
2411 TREE_COMPLEXITY (t) = 0;
2412 TREE_OPERAND (t, 0) = node;
2413 TREE_BLOCK (t) = NULL_TREE;
2414 if (node && !TYPE_P (node) && first_rtl_op (code) != 0)
2416 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2417 TREE_READONLY (t) = TREE_READONLY (node);
2420 if (TREE_CODE_CLASS (code) == tcc_statement)
2421 TREE_SIDE_EFFECTS (t) = 1;
2427 case PREDECREMENT_EXPR:
2428 case PREINCREMENT_EXPR:
2429 case POSTDECREMENT_EXPR:
2430 case POSTINCREMENT_EXPR:
2431 /* All of these have side-effects, no matter what their
2433 TREE_SIDE_EFFECTS (t) = 1;
2434 TREE_READONLY (t) = 0;
2437 case MISALIGNED_INDIRECT_REF:
2438 case ALIGN_INDIRECT_REF:
2440 /* Whether a dereference is readonly has nothing to do with whether
2441 its operand is readonly. */
2442 TREE_READONLY (t) = 0;
2447 recompute_tree_invarant_for_addr_expr (t);
2451 if (TREE_CODE_CLASS (code) == tcc_unary
2452 && node && !TYPE_P (node)
2453 && TREE_CONSTANT (node))
2454 TREE_CONSTANT (t) = 1;
2455 if (TREE_CODE_CLASS (code) == tcc_unary
2456 && node && TREE_INVARIANT (node))
2457 TREE_INVARIANT (t) = 1;
2458 if (TREE_CODE_CLASS (code) == tcc_reference
2459 && node && TREE_THIS_VOLATILE (node))
2460 TREE_THIS_VOLATILE (t) = 1;
2467 #define PROCESS_ARG(N) \
2469 TREE_OPERAND (t, N) = arg##N; \
2470 if (arg##N &&!TYPE_P (arg##N) && fro > N) \
2472 if (TREE_SIDE_EFFECTS (arg##N)) \
2474 if (!TREE_READONLY (arg##N)) \
2476 if (!TREE_CONSTANT (arg##N)) \
2478 if (!TREE_INVARIANT (arg##N)) \
2484 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
2486 bool constant, read_only, side_effects, invariant;
2490 gcc_assert (TREE_CODE_LENGTH (code) == 2);
2492 t = make_node_stat (code PASS_MEM_STAT);
2495 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2496 result based on those same flags for the arguments. But if the
2497 arguments aren't really even `tree' expressions, we shouldn't be trying
2499 fro = first_rtl_op (code);
2501 /* Expressions without side effects may be constant if their
2502 arguments are as well. */
2503 constant = (TREE_CODE_CLASS (code) == tcc_comparison
2504 || TREE_CODE_CLASS (code) == tcc_binary);
2506 side_effects = TREE_SIDE_EFFECTS (t);
2507 invariant = constant;
2512 TREE_READONLY (t) = read_only;
2513 TREE_CONSTANT (t) = constant;
2514 TREE_INVARIANT (t) = invariant;
2515 TREE_SIDE_EFFECTS (t) = side_effects;
2516 TREE_THIS_VOLATILE (t)
2517 = (TREE_CODE_CLASS (code) == tcc_reference
2518 && arg0 && TREE_THIS_VOLATILE (arg0));
2524 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2525 tree arg2 MEM_STAT_DECL)
2527 bool constant, read_only, side_effects, invariant;
2531 gcc_assert (TREE_CODE_LENGTH (code) == 3);
2533 t = make_node_stat (code PASS_MEM_STAT);
2536 fro = first_rtl_op (code);
2538 side_effects = TREE_SIDE_EFFECTS (t);
2544 if (code == CALL_EXPR && !side_effects)
2549 /* Calls have side-effects, except those to const or
2551 i = call_expr_flags (t);
2552 if (!(i & (ECF_CONST | ECF_PURE)))
2555 /* And even those have side-effects if their arguments do. */
2556 else for (node = arg1; node; node = TREE_CHAIN (node))
2557 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2564 TREE_SIDE_EFFECTS (t) = side_effects;
2565 TREE_THIS_VOLATILE (t)
2566 = (TREE_CODE_CLASS (code) == tcc_reference
2567 && arg0 && TREE_THIS_VOLATILE (arg0));
2573 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2574 tree arg2, tree arg3 MEM_STAT_DECL)
2576 bool constant, read_only, side_effects, invariant;
2580 gcc_assert (TREE_CODE_LENGTH (code) == 4);
2582 t = make_node_stat (code PASS_MEM_STAT);
2585 fro = first_rtl_op (code);
2587 side_effects = TREE_SIDE_EFFECTS (t);
2594 TREE_SIDE_EFFECTS (t) = side_effects;
2595 TREE_THIS_VOLATILE (t)
2596 = (TREE_CODE_CLASS (code) == tcc_reference
2597 && arg0 && TREE_THIS_VOLATILE (arg0));
2602 /* Backup definition for non-gcc build compilers. */
2605 (build) (enum tree_code code, tree tt, ...)
2607 tree t, arg0, arg1, arg2, arg3;
2608 int length = TREE_CODE_LENGTH (code);
2615 t = build0 (code, tt);
2618 arg0 = va_arg (p, tree);
2619 t = build1 (code, tt, arg0);
2622 arg0 = va_arg (p, tree);
2623 arg1 = va_arg (p, tree);
2624 t = build2 (code, tt, arg0, arg1);
2627 arg0 = va_arg (p, tree);
2628 arg1 = va_arg (p, tree);
2629 arg2 = va_arg (p, tree);
2630 t = build3 (code, tt, arg0, arg1, arg2);
2633 arg0 = va_arg (p, tree);
2634 arg1 = va_arg (p, tree);
2635 arg2 = va_arg (p, tree);
2636 arg3 = va_arg (p, tree);
2637 t = build4 (code, tt, arg0, arg1, arg2, arg3);
2647 /* Similar except don't specify the TREE_TYPE
2648 and leave the TREE_SIDE_EFFECTS as 0.
2649 It is permissible for arguments to be null,
2650 or even garbage if their values do not matter. */
2653 build_nt (enum tree_code code, ...)
2662 t = make_node (code);
2663 length = TREE_CODE_LENGTH (code);
2665 for (i = 0; i < length; i++)
2666 TREE_OPERAND (t, i) = va_arg (p, tree);
2672 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2673 We do NOT enter this node in any sort of symbol table.
2675 layout_decl is used to set up the decl's storage layout.
2676 Other slots are initialized to 0 or null pointers. */
2679 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
2683 t = make_node_stat (code PASS_MEM_STAT);
2685 /* if (type == error_mark_node)
2686 type = integer_type_node; */
2687 /* That is not done, deliberately, so that having error_mark_node
2688 as the type can suppress useless errors in the use of this variable. */
2690 DECL_NAME (t) = name;
2691 TREE_TYPE (t) = type;
2693 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2695 else if (code == FUNCTION_DECL)
2696 DECL_MODE (t) = FUNCTION_MODE;
2698 /* Set default visibility to whatever the user supplied with
2699 visibility_specified depending on #pragma GCC visibility. */
2700 DECL_VISIBILITY (t) = default_visibility;
2701 DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
2706 /* BLOCK nodes are used to represent the structure of binding contours
2707 and declarations, once those contours have been exited and their contents
2708 compiled. This information is used for outputting debugging info. */
2711 build_block (tree vars, tree tags ATTRIBUTE_UNUSED, tree subblocks,
2712 tree supercontext, tree chain)
2714 tree block = make_node (BLOCK);
2716 BLOCK_VARS (block) = vars;
2717 BLOCK_SUBBLOCKS (block) = subblocks;
2718 BLOCK_SUPERCONTEXT (block) = supercontext;
2719 BLOCK_CHAIN (block) = chain;
2723 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
2724 /* ??? gengtype doesn't handle conditionals */
2725 static GTY(()) tree last_annotated_node;
2728 #ifdef USE_MAPPED_LOCATION
2731 expand_location (source_location loc)
2733 expanded_location xloc;
2734 if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; }
2737 const struct line_map *map = linemap_lookup (&line_table, loc);
2738 xloc.file = map->to_file;
2739 xloc.line = SOURCE_LINE (map, loc);
2740 xloc.column = SOURCE_COLUMN (map, loc);
2747 /* Record the exact location where an expression or an identifier were
2751 annotate_with_file_line (tree node, const char *file, int line)
2753 /* Roughly one percent of the calls to this function are to annotate
2754 a node with the same information already attached to that node!
2755 Just return instead of wasting memory. */
2756 if (EXPR_LOCUS (node)
2757 && (EXPR_FILENAME (node) == file
2758 || ! strcmp (EXPR_FILENAME (node), file))
2759 && EXPR_LINENO (node) == line)
2761 last_annotated_node = node;
2765 /* In heavily macroized code (such as GCC itself) this single
2766 entry cache can reduce the number of allocations by more
2768 if (last_annotated_node
2769 && EXPR_LOCUS (last_annotated_node)
2770 && (EXPR_FILENAME (last_annotated_node) == file
2771 || ! strcmp (EXPR_FILENAME (last_annotated_node), file))
2772 && EXPR_LINENO (last_annotated_node) == line)
2774 SET_EXPR_LOCUS (node, EXPR_LOCUS (last_annotated_node));
2778 SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
2779 EXPR_LINENO (node) = line;
2780 EXPR_FILENAME (node) = file;
2781 last_annotated_node = node;
2785 annotate_with_locus (tree node, location_t locus)
2787 annotate_with_file_line (node, locus.file, locus.line);
2791 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2795 build_decl_attribute_variant (tree ddecl, tree attribute)
2797 DECL_ATTRIBUTES (ddecl) = attribute;
2801 /* Borrowed from hashtab.c iterative_hash implementation. */
2802 #define mix(a,b,c) \
2804 a -= b; a -= c; a ^= (c>>13); \
2805 b -= c; b -= a; b ^= (a<< 8); \
2806 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
2807 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
2808 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
2809 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
2810 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
2811 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
2812 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
2816 /* Produce good hash value combining VAL and VAL2. */
2817 static inline hashval_t
2818 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
2820 /* the golden ratio; an arbitrary value. */
2821 hashval_t a = 0x9e3779b9;
2827 /* Produce good hash value combining PTR and VAL2. */
2828 static inline hashval_t
2829 iterative_hash_pointer (void *ptr, hashval_t val2)
2831 if (sizeof (ptr) == sizeof (hashval_t))
2832 return iterative_hash_hashval_t ((size_t) ptr, val2);
2835 hashval_t a = (hashval_t) (size_t) ptr;
2836 /* Avoid warnings about shifting of more than the width of the type on
2837 hosts that won't execute this path. */
2839 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
2845 /* Produce good hash value combining VAL and VAL2. */
2846 static inline hashval_t
2847 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
2849 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
2850 return iterative_hash_hashval_t (val, val2);
2853 hashval_t a = (hashval_t) val;
2854 /* Avoid warnings about shifting of more than the width of the type on
2855 hosts that won't execute this path. */
2857 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
2859 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
2861 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
2862 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
2869 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2872 Record such modified types already made so we don't make duplicates. */
2875 build_type_attribute_variant (tree ttype, tree attribute)
2877 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2879 hashval_t hashcode = 0;
2881 enum tree_code code = TREE_CODE (ttype);
2883 ntype = copy_node (ttype);
2885 TYPE_POINTER_TO (ntype) = 0;
2886 TYPE_REFERENCE_TO (ntype) = 0;
2887 TYPE_ATTRIBUTES (ntype) = attribute;
2889 /* Create a new main variant of TYPE. */
2890 TYPE_MAIN_VARIANT (ntype) = ntype;
2891 TYPE_NEXT_VARIANT (ntype) = 0;
2892 set_type_quals (ntype, TYPE_UNQUALIFIED);
2894 hashcode = iterative_hash_object (code, hashcode);
2895 if (TREE_TYPE (ntype))
2896 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
2898 hashcode = attribute_hash_list (attribute, hashcode);
2900 switch (TREE_CODE (ntype))
2903 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
2906 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
2910 hashcode = iterative_hash_object
2911 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
2912 hashcode = iterative_hash_object
2913 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
2917 unsigned int precision = TYPE_PRECISION (ntype);
2918 hashcode = iterative_hash_object (precision, hashcode);
2925 ntype = type_hash_canon (hashcode, ntype);
2926 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2932 /* Return nonzero if IDENT is a valid name for attribute ATTR,
2935 We try both `text' and `__text__', ATTR may be either one. */
2936 /* ??? It might be a reasonable simplification to require ATTR to be only
2937 `text'. One might then also require attribute lists to be stored in
2938 their canonicalized form. */
2941 is_attribute_p (const char *attr, tree ident)
2943 int ident_len, attr_len;
2946 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2949 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2952 p = IDENTIFIER_POINTER (ident);
2953 ident_len = strlen (p);
2954 attr_len = strlen (attr);
2956 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2959 gcc_assert (attr[1] == '_');
2960 gcc_assert (attr[attr_len - 2] == '_');
2961 gcc_assert (attr[attr_len - 1] == '_');
2962 gcc_assert (attr[1] == '_');
2963 if (ident_len == attr_len - 4
2964 && strncmp (attr + 2, p, attr_len - 4) == 0)
2969 if (ident_len == attr_len + 4
2970 && p[0] == '_' && p[1] == '_'
2971 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2972 && strncmp (attr, p + 2, attr_len) == 0)
2979 /* Given an attribute name and a list of attributes, return a pointer to the
2980 attribute's list element if the attribute is part of the list, or NULL_TREE
2981 if not found. If the attribute appears more than once, this only
2982 returns the first occurrence; the TREE_CHAIN of the return value should
2983 be passed back in if further occurrences are wanted. */
2986 lookup_attribute (const char *attr_name, tree list)
2990 for (l = list; l; l = TREE_CHAIN (l))
2992 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
2993 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
3000 /* Return an attribute list that is the union of a1 and a2. */
3003 merge_attributes (tree a1, tree a2)
3007 /* Either one unset? Take the set one. */
3009 if ((attributes = a1) == 0)
3012 /* One that completely contains the other? Take it. */
3014 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3016 if (attribute_list_contained (a2, a1))
3020 /* Pick the longest list, and hang on the other list. */
3022 if (list_length (a1) < list_length (a2))
3023 attributes = a2, a2 = a1;
3025 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3028 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3031 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3034 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
3039 a1 = copy_node (a2);
3040 TREE_CHAIN (a1) = attributes;
3049 /* Given types T1 and T2, merge their attributes and return
3053 merge_type_attributes (tree t1, tree t2)
3055 return merge_attributes (TYPE_ATTRIBUTES (t1),
3056 TYPE_ATTRIBUTES (t2));
3059 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3063 merge_decl_attributes (tree olddecl, tree newdecl)
3065 return merge_attributes (DECL_ATTRIBUTES (olddecl),
3066 DECL_ATTRIBUTES (newdecl));
3069 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3071 /* Specialization of merge_decl_attributes for various Windows targets.
3073 This handles the following situation:
3075 __declspec (dllimport) int foo;
3078 The second instance of `foo' nullifies the dllimport. */
3081 merge_dllimport_decl_attributes (tree old, tree new)
3084 int delete_dllimport_p;
3086 old = DECL_ATTRIBUTES (old);
3087 new = DECL_ATTRIBUTES (new);
3089 /* What we need to do here is remove from `old' dllimport if it doesn't
3090 appear in `new'. dllimport behaves like extern: if a declaration is
3091 marked dllimport and a definition appears later, then the object
3092 is not dllimport'd. */
3093 if (lookup_attribute ("dllimport", old) != NULL_TREE
3094 && lookup_attribute ("dllimport", new) == NULL_TREE)
3095 delete_dllimport_p = 1;
3097 delete_dllimport_p = 0;
3099 a = merge_attributes (old, new);
3101 if (delete_dllimport_p)
3105 /* Scan the list for dllimport and delete it. */
3106 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
3108 if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
3110 if (prev == NULL_TREE)
3113 TREE_CHAIN (prev) = TREE_CHAIN (t);
3122 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3123 struct attribute_spec.handler. */
3126 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
3131 /* These attributes may apply to structure and union types being created,
3132 but otherwise should pass to the declaration involved. */
3135 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
3136 | (int) ATTR_FLAG_ARRAY_NEXT))
3138 *no_add_attrs = true;
3139 return tree_cons (name, args, NULL_TREE);
3141 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
3143 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
3144 *no_add_attrs = true;
3150 /* Report error on dllimport ambiguities seen now before they cause
3152 if (is_attribute_p ("dllimport", name))
3154 /* Like MS, treat definition of dllimported variables and
3155 non-inlined functions on declaration as syntax errors. We
3156 allow the attribute for function definitions if declared
3158 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
3159 && !DECL_DECLARED_INLINE_P (node))
3161 error ("%Jfunction %qD definition is marked dllimport.", node, node);
3162 *no_add_attrs = true;
3165 else if (TREE_CODE (node) == VAR_DECL)
3167 if (DECL_INITIAL (node))
3169 error ("%Jvariable %qD definition is marked dllimport.",
3171 *no_add_attrs = true;
3174 /* `extern' needn't be specified with dllimport.
3175 Specify `extern' now and hope for the best. Sigh. */
3176 DECL_EXTERNAL (node) = 1;
3177 /* Also, implicitly give dllimport'd variables declared within
3178 a function global scope, unless declared static. */
3179 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
3180 TREE_PUBLIC (node) = 1;
3184 /* Report error if symbol is not accessible at global scope. */
3185 if (!TREE_PUBLIC (node)
3186 && (TREE_CODE (node) == VAR_DECL
3187 || TREE_CODE (node) == FUNCTION_DECL))
3189 error ("%Jexternal linkage required for symbol %qD because of "
3190 "%qs attribute.", node, node, IDENTIFIER_POINTER (name));
3191 *no_add_attrs = true;
3197 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3199 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3200 of the various TYPE_QUAL values. */
3203 set_type_quals (tree type, int type_quals)
3205 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3206 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3207 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3210 /* Returns true iff cand is equivalent to base with type_quals. */
3213 check_qualified_type (tree cand, tree base, int type_quals)
3215 return (TYPE_QUALS (cand) == type_quals
3216 && TYPE_NAME (cand) == TYPE_NAME (base)
3217 /* Apparently this is needed for Objective-C. */
3218 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
3219 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
3220 TYPE_ATTRIBUTES (base)));
3223 /* Return a version of the TYPE, qualified as indicated by the
3224 TYPE_QUALS, if one exists. If no qualified version exists yet,
3225 return NULL_TREE. */
3228 get_qualified_type (tree type, int type_quals)
3232 if (TYPE_QUALS (type) == type_quals)
3235 /* Search the chain of variants to see if there is already one there just
3236 like the one we need to have. If so, use that existing one. We must
3237 preserve the TYPE_NAME, since there is code that depends on this. */
3238 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3239 if (check_qualified_type (t, type, type_quals))
3245 /* Like get_qualified_type, but creates the type if it does not
3246 exist. This function never returns NULL_TREE. */
3249 build_qualified_type (tree type, int type_quals)
3253 /* See if we already have the appropriate qualified variant. */
3254 t = get_qualified_type (type, type_quals);
3256 /* If not, build it. */
3259 t = build_variant_type_copy (type);
3260 set_type_quals (t, type_quals);
3266 /* Create a new distinct copy of TYPE. The new type is made its own
3270 build_distinct_type_copy (tree type)
3272 tree t = copy_node (type);
3274 TYPE_POINTER_TO (t) = 0;
3275 TYPE_REFERENCE_TO (t) = 0;
3277 /* Make it its own variant. */
3278 TYPE_MAIN_VARIANT (t) = t;
3279 TYPE_NEXT_VARIANT (t) = 0;
3284 /* Create a new variant of TYPE, equivalent but distinct.
3285 This is so the caller can modify it. */
3288 build_variant_type_copy (tree type)
3290 tree t, m = TYPE_MAIN_VARIANT (type);
3292 t = build_distinct_type_copy (type);
3294 /* Add the new type to the chain of variants of TYPE. */
3295 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3296 TYPE_NEXT_VARIANT (m) = t;
3297 TYPE_MAIN_VARIANT (t) = m;
3302 /* Hashing of types so that we don't make duplicates.
3303 The entry point is `type_hash_canon'. */
3305 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3306 with types in the TREE_VALUE slots), by adding the hash codes
3307 of the individual types. */
3310 type_hash_list (tree list, hashval_t hashcode)
3314 for (tail = list; tail; tail = TREE_CHAIN (tail))
3315 if (TREE_VALUE (tail) != error_mark_node)
3316 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
3322 /* These are the Hashtable callback functions. */
3324 /* Returns true iff the types are equivalent. */
3327 type_hash_eq (const void *va, const void *vb)
3329 const struct type_hash *a = va, *b = vb;
3331 /* First test the things that are the same for all types. */
3332 if (a->hash != b->hash
3333 || TREE_CODE (a->type) != TREE_CODE (b->type)
3334 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
3335 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3336 TYPE_ATTRIBUTES (b->type))
3337 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
3338 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
3341 switch (TREE_CODE (a->type))
3347 case REFERENCE_TYPE:
3351 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
3352 && !(TYPE_VALUES (a->type)
3353 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
3354 && TYPE_VALUES (b->type)
3355 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
3356 && type_list_equal (TYPE_VALUES (a->type),
3357 TYPE_VALUES (b->type))))
3360 /* ... fall through ... */
3366 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
3367 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
3368 TYPE_MAX_VALUE (b->type)))
3369 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
3370 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
3371 TYPE_MIN_VALUE (b->type))));
3374 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
3377 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
3378 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3379 || (TYPE_ARG_TYPES (a->type)
3380 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3381 && TYPE_ARG_TYPES (b->type)
3382 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3383 && type_list_equal (TYPE_ARG_TYPES (a->type),
3384 TYPE_ARG_TYPES (b->type)))));
3388 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
3392 case QUAL_UNION_TYPE:
3393 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
3394 || (TYPE_FIELDS (a->type)
3395 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
3396 && TYPE_FIELDS (b->type)
3397 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
3398 && type_list_equal (TYPE_FIELDS (a->type),
3399 TYPE_FIELDS (b->type))));
3402 return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3403 || (TYPE_ARG_TYPES (a->type)
3404 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3405 && TYPE_ARG_TYPES (b->type)
3406 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3407 && type_list_equal (TYPE_ARG_TYPES (a->type),
3408 TYPE_ARG_TYPES (b->type))));
3415 /* Return the cached hash value. */
3418 type_hash_hash (const void *item)
3420 return ((const struct type_hash *) item)->hash;
3423 /* Look in the type hash table for a type isomorphic to TYPE.
3424 If one is found, return it. Otherwise return 0. */
3427 type_hash_lookup (hashval_t hashcode, tree type)
3429 struct type_hash *h, in;
3431 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3432 must call that routine before comparing TYPE_ALIGNs. */
3438 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3444 /* Add an entry to the type-hash-table
3445 for a type TYPE whose hash code is HASHCODE. */
3448 type_hash_add (hashval_t hashcode, tree type)
3450 struct type_hash *h;
3453 h = ggc_alloc (sizeof (struct type_hash));
3456 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3457 *(struct type_hash **) loc = h;
3460 /* Given TYPE, and HASHCODE its hash code, return the canonical
3461 object for an identical type if one already exists.
3462 Otherwise, return TYPE, and record it as the canonical object.
3464 To use this function, first create a type of the sort you want.
3465 Then compute its hash code from the fields of the type that
3466 make it different from other similar types.
3467 Then call this function and use the value. */
3470 type_hash_canon (unsigned int hashcode, tree type)
3474 /* The hash table only contains main variants, so ensure that's what we're
3476 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
3478 if (!lang_hooks.types.hash_types)
3481 /* See if the type is in the hash table already. If so, return it.
3482 Otherwise, add the type. */
3483 t1 = type_hash_lookup (hashcode, type);
3486 #ifdef GATHER_STATISTICS
3487 tree_node_counts[(int) t_kind]--;
3488 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3494 type_hash_add (hashcode, type);
3499 /* See if the data pointed to by the type hash table is marked. We consider
3500 it marked if the type is marked or if a debug type number or symbol
3501 table entry has been made for the type. This reduces the amount of
3502 debugging output and eliminates that dependency of the debug output on
3503 the number of garbage collections. */
3506 type_hash_marked_p (const void *p)
3508 tree type = ((struct type_hash *) p)->type;
3510 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3514 print_type_hash_statistics (void)
3516 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3517 (long) htab_size (type_hash_table),
3518 (long) htab_elements (type_hash_table),
3519 htab_collisions (type_hash_table));
3522 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3523 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3524 by adding the hash codes of the individual attributes. */
3527 attribute_hash_list (tree list, hashval_t hashcode)
3531 for (tail = list; tail; tail = TREE_CHAIN (tail))
3532 /* ??? Do we want to add in TREE_VALUE too? */
3533 hashcode = iterative_hash_object
3534 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
3538 /* Given two lists of attributes, return true if list l2 is
3539 equivalent to l1. */
3542 attribute_list_equal (tree l1, tree l2)
3544 return attribute_list_contained (l1, l2)
3545 && attribute_list_contained (l2, l1);
3548 /* Given two lists of attributes, return true if list L2 is
3549 completely contained within L1. */
3550 /* ??? This would be faster if attribute names were stored in a canonicalized
3551 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3552 must be used to show these elements are equivalent (which they are). */
3553 /* ??? It's not clear that attributes with arguments will always be handled
3557 attribute_list_contained (tree l1, tree l2)
3561 /* First check the obvious, maybe the lists are identical. */
3565 /* Maybe the lists are similar. */
3566 for (t1 = l1, t2 = l2;
3568 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3569 && TREE_VALUE (t1) == TREE_VALUE (t2);
3570 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3572 /* Maybe the lists are equal. */
3573 if (t1 == 0 && t2 == 0)
3576 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3579 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3581 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3584 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3591 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3598 /* Given two lists of types
3599 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3600 return 1 if the lists contain the same types in the same order.
3601 Also, the TREE_PURPOSEs must match. */
3604 type_list_equal (tree l1, tree l2)
3608 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3609 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3610 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3611 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3612 && (TREE_TYPE (TREE_PURPOSE (t1))
3613 == TREE_TYPE (TREE_PURPOSE (t2))))))
3619 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3620 given by TYPE. If the argument list accepts variable arguments,
3621 then this function counts only the ordinary arguments. */
3624 type_num_arguments (tree type)
3629 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3630 /* If the function does not take a variable number of arguments,
3631 the last element in the list will have type `void'. */
3632 if (VOID_TYPE_P (TREE_VALUE (t)))
3640 /* Nonzero if integer constants T1 and T2
3641 represent the same constant value. */
3644 tree_int_cst_equal (tree t1, tree t2)
3649 if (t1 == 0 || t2 == 0)
3652 if (TREE_CODE (t1) == INTEGER_CST
3653 && TREE_CODE (t2) == INTEGER_CST
3654 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3655 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3661 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3662 The precise way of comparison depends on their data type. */
3665 tree_int_cst_lt (tree t1, tree t2)
3670 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
3672 int t1_sgn = tree_int_cst_sgn (t1);
3673 int t2_sgn = tree_int_cst_sgn (t2);
3675 if (t1_sgn < t2_sgn)
3677 else if (t1_sgn > t2_sgn)
3679 /* Otherwise, both are non-negative, so we compare them as
3680 unsigned just in case one of them would overflow a signed
3683 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
3684 return INT_CST_LT (t1, t2);
3686 return INT_CST_LT_UNSIGNED (t1, t2);
3689 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3692 tree_int_cst_compare (tree t1, tree t2)
3694 if (tree_int_cst_lt (t1, t2))
3696 else if (tree_int_cst_lt (t2, t1))
3702 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3703 the host. If POS is zero, the value can be represented in a single
3704 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3705 be represented in a single unsigned HOST_WIDE_INT. */
3708 host_integerp (tree t, int pos)
3710 return (TREE_CODE (t) == INTEGER_CST
3711 && ! TREE_OVERFLOW (t)
3712 && ((TREE_INT_CST_HIGH (t) == 0
3713 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3714 || (! pos && TREE_INT_CST_HIGH (t) == -1
3715 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3716 && !TYPE_UNSIGNED (TREE_TYPE (t)))
3717 || (pos && TREE_INT_CST_HIGH (t) == 0)));
3720 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3721 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3722 be positive. Abort if we cannot satisfy the above conditions. */
3725 tree_low_cst (tree t, int pos)
3727 gcc_assert (host_integerp (t, pos));
3728 return TREE_INT_CST_LOW (t);
3731 /* Return the most significant bit of the integer constant T. */
3734 tree_int_cst_msb (tree t)
3738 unsigned HOST_WIDE_INT l;
3740 /* Note that using TYPE_PRECISION here is wrong. We care about the
3741 actual bits, not the (arbitrary) range of the type. */
3742 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3743 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3744 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3745 return (l & 1) == 1;
3748 /* Return an indication of the sign of the integer constant T.
3749 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3750 Note that -1 will never be returned it T's type is unsigned. */
3753 tree_int_cst_sgn (tree t)
3755 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3757 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
3759 else if (TREE_INT_CST_HIGH (t) < 0)
3765 /* Compare two constructor-element-type constants. Return 1 if the lists
3766 are known to be equal; otherwise return 0. */
3769 simple_cst_list_equal (tree l1, tree l2)
3771 while (l1 != NULL_TREE && l2 != NULL_TREE)
3773 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3776 l1 = TREE_CHAIN (l1);
3777 l2 = TREE_CHAIN (l2);
3783 /* Return truthvalue of whether T1 is the same tree structure as T2.
3784 Return 1 if they are the same.
3785 Return 0 if they are understandably different.
3786 Return -1 if either contains tree structure not understood by
3790 simple_cst_equal (tree t1, tree t2)
3792 enum tree_code code1, code2;
3798 if (t1 == 0 || t2 == 0)
3801 code1 = TREE_CODE (t1);
3802 code2 = TREE_CODE (t2);
3804 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3806 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3807 || code2 == NON_LVALUE_EXPR)
3808 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3810 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3813 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3814 || code2 == NON_LVALUE_EXPR)
3815 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3823 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3824 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3827 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3830 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3831 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3832 TREE_STRING_LENGTH (t1)));
3835 return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1),
3836 CONSTRUCTOR_ELTS (t2));
3839 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3842 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3846 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3849 /* Special case: if either target is an unallocated VAR_DECL,
3850 it means that it's going to be unified with whatever the
3851 TARGET_EXPR is really supposed to initialize, so treat it
3852 as being equivalent to anything. */
3853 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3854 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3855 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3856 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3857 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3858 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3861 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3866 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3868 case WITH_CLEANUP_EXPR:
3869 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3873 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3876 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3877 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3891 /* This general rule works for most tree codes. All exceptions should be
3892 handled above. If this is a language-specific tree code, we can't
3893 trust what might be in the operand, so say we don't know
3895 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3898 switch (TREE_CODE_CLASS (code1))
3902 case tcc_comparison:
3903 case tcc_expression:
3907 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3909 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3921 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3922 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3923 than U, respectively. */
3926 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
3928 if (tree_int_cst_sgn (t) < 0)
3930 else if (TREE_INT_CST_HIGH (t) != 0)
3932 else if (TREE_INT_CST_LOW (t) == u)
3934 else if (TREE_INT_CST_LOW (t) < u)
3940 /* Return true if CODE represents an associative tree code. Otherwise
3943 associative_tree_code (enum tree_code code)
3962 /* Return true if CODE represents an commutative tree code. Otherwise
3965 commutative_tree_code (enum tree_code code)
3978 case UNORDERED_EXPR:
3982 case TRUTH_AND_EXPR:
3983 case TRUTH_XOR_EXPR:
3993 /* Generate a hash value for an expression. This can be used iteratively
3994 by passing a previous result as the "val" argument.
3996 This function is intended to produce the same hash for expressions which
3997 would compare equal using operand_equal_p. */
4000 iterative_hash_expr (tree t, hashval_t val)
4003 enum tree_code code;
4007 return iterative_hash_pointer (t, val);
4009 code = TREE_CODE (t);
4013 /* Alas, constants aren't shared, so we can't rely on pointer
4016 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
4017 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
4020 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
4022 return iterative_hash_hashval_t (val2, val);
4025 return iterative_hash (TREE_STRING_POINTER (t),
4026 TREE_STRING_LENGTH (t), val);
4028 val = iterative_hash_expr (TREE_REALPART (t), val);
4029 return iterative_hash_expr (TREE_IMAGPART (t), val);
4031 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
4035 /* we can just compare by pointer. */
4036 return iterative_hash_pointer (t, val);
4039 /* A list of expressions, for a CALL_EXPR or as the elements of a
4041 for (; t; t = TREE_CHAIN (t))
4042 val = iterative_hash_expr (TREE_VALUE (t), val);
4045 class = TREE_CODE_CLASS (code);
4047 if (class == tcc_declaration)
4049 /* Decls we can just compare by pointer. */
4050 val = iterative_hash_pointer (t, val);
4054 gcc_assert (IS_EXPR_CODE_CLASS (class));
4056 val = iterative_hash_object (code, val);
4058 /* Don't hash the type, that can lead to having nodes which
4059 compare equal according to operand_equal_p, but which
4060 have different hash codes. */
4061 if (code == NOP_EXPR
4062 || code == CONVERT_EXPR
4063 || code == NON_LVALUE_EXPR)
4065 /* Make sure to include signness in the hash computation. */
4066 val += TYPE_UNSIGNED (TREE_TYPE (t));
4067 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
4070 else if (commutative_tree_code (code))
4072 /* It's a commutative expression. We want to hash it the same
4073 however it appears. We do this by first hashing both operands
4074 and then rehashing based on the order of their independent
4076 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
4077 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
4081 t = one, one = two, two = t;
4083 val = iterative_hash_hashval_t (one, val);
4084 val = iterative_hash_hashval_t (two, val);
4087 for (i = first_rtl_op (code) - 1; i >= 0; --i)
4088 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
4095 /* Constructors for pointer, array and function types.
4096 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4097 constructed by language-dependent code, not here.) */
4099 /* Construct, lay out and return the type of pointers to TO_TYPE with
4100 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
4101 reference all of memory. If such a type has already been
4102 constructed, reuse it. */
4105 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
4110 /* In some cases, languages will have things that aren't a POINTER_TYPE
4111 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
4112 In that case, return that type without regard to the rest of our
4115 ??? This is a kludge, but consistent with the way this function has
4116 always operated and there doesn't seem to be a good way to avoid this
4118 if (TYPE_POINTER_TO (to_type) != 0
4119 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
4120 return TYPE_POINTER_TO (to_type);
4122 /* First, if we already have a type for pointers to TO_TYPE and it's
4123 the proper mode, use it. */
4124 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
4125 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4128 t = make_node (POINTER_TYPE);
4130 TREE_TYPE (t) = to_type;
4131 TYPE_MODE (t) = mode;
4132 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4133 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
4134 TYPE_POINTER_TO (to_type) = t;
4136 /* Lay out the type. This function has many callers that are concerned
4137 with expression-construction, and this simplifies them all. */
4143 /* By default build pointers in ptr_mode. */
4146 build_pointer_type (tree to_type)
4148 return build_pointer_type_for_mode (to_type, ptr_mode, false);
4151 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4154 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
4159 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4160 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4161 In that case, return that type without regard to the rest of our
4164 ??? This is a kludge, but consistent with the way this function has
4165 always operated and there doesn't seem to be a good way to avoid this
4167 if (TYPE_REFERENCE_TO (to_type) != 0
4168 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
4169 return TYPE_REFERENCE_TO (to_type);
4171 /* First, if we already have a type for pointers to TO_TYPE and it's
4172 the proper mode, use it. */
4173 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
4174 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4177 t = make_node (REFERENCE_TYPE);
4179 TREE_TYPE (t) = to_type;
4180 TYPE_MODE (t) = mode;
4181 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4182 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
4183 TYPE_REFERENCE_TO (to_type) = t;
4191 /* Build the node for the type of references-to-TO_TYPE by default
4195 build_reference_type (tree to_type)
4197 return build_reference_type_for_mode (to_type, ptr_mode, false);
4200 /* Build a type that is compatible with t but has no cv quals anywhere
4203 const char *const *const * -> char ***. */
4206 build_type_no_quals (tree t)
4208 switch (TREE_CODE (t))
4211 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4213 TYPE_REF_CAN_ALIAS_ALL (t));
4214 case REFERENCE_TYPE:
4216 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4218 TYPE_REF_CAN_ALIAS_ALL (t));
4220 return TYPE_MAIN_VARIANT (t);
4224 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4225 MAXVAL should be the maximum value in the domain
4226 (one less than the length of the array).
4228 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4229 We don't enforce this limit, that is up to caller (e.g. language front end).
4230 The limit exists because the result is a signed type and we don't handle
4231 sizes that use more than one HOST_WIDE_INT. */
4234 build_index_type (tree maxval)
4236 tree itype = make_node (INTEGER_TYPE);
4238 TREE_TYPE (itype) = sizetype;
4239 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4240 TYPE_MIN_VALUE (itype) = size_zero_node;
4241 TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
4242 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4243 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4244 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4245 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4246 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
4248 if (host_integerp (maxval, 1))
4249 return type_hash_canon (tree_low_cst (maxval, 1), itype);
4254 /* Builds a signed or unsigned integer type of precision PRECISION.
4255 Used for C bitfields whose precision does not match that of
4256 built-in target types. */
4258 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
4261 tree itype = make_node (INTEGER_TYPE);
4263 TYPE_PRECISION (itype) = precision;
4266 fixup_unsigned_type (itype);
4268 fixup_signed_type (itype);
4270 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
4271 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
4276 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4277 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4278 low bound LOWVAL and high bound HIGHVAL.
4279 if TYPE==NULL_TREE, sizetype is used. */
4282 build_range_type (tree type, tree lowval, tree highval)
4284 tree itype = make_node (INTEGER_TYPE);
4286 TREE_TYPE (itype) = type;
4287 if (type == NULL_TREE)
4290 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4291 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4293 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4294 TYPE_MODE (itype) = TYPE_MODE (type);
4295 TYPE_SIZE (itype) = TYPE_SIZE (type);
4296 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4297 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4298 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
4300 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
4301 return type_hash_canon (tree_low_cst (highval, 0)
4302 - tree_low_cst (lowval, 0),
4308 /* Just like build_index_type, but takes lowval and highval instead
4309 of just highval (maxval). */
4312 build_index_2_type (tree lowval, tree highval)
4314 return build_range_type (sizetype, lowval, highval);
4317 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4318 and number of elements specified by the range of values of INDEX_TYPE.
4319 If such a type has already been constructed, reuse it. */
4322 build_array_type (tree elt_type, tree index_type)
4325 hashval_t hashcode = 0;
4327 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
4329 error ("arrays of functions are not meaningful");
4330 elt_type = integer_type_node;
4333 t = make_node (ARRAY_TYPE);
4334 TREE_TYPE (t) = elt_type;
4335 TYPE_DOMAIN (t) = index_type;
4337 if (index_type == 0)
4340 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
4341 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
4342 t = type_hash_canon (hashcode, t);
4344 if (!COMPLETE_TYPE_P (t))
4349 /* Return the TYPE of the elements comprising
4350 the innermost dimension of ARRAY. */
4353 get_inner_array_type (tree array)
4355 tree type = TREE_TYPE (array);
4357 while (TREE_CODE (type) == ARRAY_TYPE)
4358 type = TREE_TYPE (type);
4363 /* Construct, lay out and return
4364 the type of functions returning type VALUE_TYPE
4365 given arguments of types ARG_TYPES.
4366 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4367 are data type nodes for the arguments of the function.
4368 If such a type has already been constructed, reuse it. */
4371 build_function_type (tree value_type, tree arg_types)
4374 hashval_t hashcode = 0;
4376 if (TREE_CODE (value_type) == FUNCTION_TYPE)
4378 error ("function return type cannot be function");
4379 value_type = integer_type_node;
4382 /* Make a node of the sort we want. */
4383 t = make_node (FUNCTION_TYPE);
4384 TREE_TYPE (t) = value_type;
4385 TYPE_ARG_TYPES (t) = arg_types;
4387 /* If we already have such a type, use the old one. */
4388 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
4389 hashcode = type_hash_list (arg_types, hashcode);
4390 t = type_hash_canon (hashcode, t);
4392 if (!COMPLETE_TYPE_P (t))
4397 /* Build a function type. The RETURN_TYPE is the type returned by the
4398 function. If additional arguments are provided, they are
4399 additional argument types. The list of argument types must always
4400 be terminated by NULL_TREE. */
4403 build_function_type_list (tree return_type, ...)
4408 va_start (p, return_type);
4410 t = va_arg (p, tree);
4411 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
4412 args = tree_cons (NULL_TREE, t, args);
4415 args = nreverse (args);
4416 TREE_CHAIN (last) = void_list_node;
4417 args = build_function_type (return_type, args);
4423 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
4424 and ARGTYPES (a TREE_LIST) are the return type and arguments types
4425 for the method. An implicit additional parameter (of type
4426 pointer-to-BASETYPE) is added to the ARGTYPES. */
4429 build_method_type_directly (tree basetype,
4437 /* Make a node of the sort we want. */
4438 t = make_node (METHOD_TYPE);
4440 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4441 TREE_TYPE (t) = rettype;
4442 ptype = build_pointer_type (basetype);
4444 /* The actual arglist for this function includes a "hidden" argument
4445 which is "this". Put it into the list of argument types. */
4446 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
4447 TYPE_ARG_TYPES (t) = argtypes;
4449 /* If we already have such a type, use the old one. */
4450 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4451 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
4452 hashcode = type_hash_list (argtypes, hashcode);
4453 t = type_hash_canon (hashcode, t);
4455 if (!COMPLETE_TYPE_P (t))
4461 /* Construct, lay out and return the type of methods belonging to class
4462 BASETYPE and whose arguments and values are described by TYPE.
4463 If that type exists already, reuse it.
4464 TYPE must be a FUNCTION_TYPE node. */
4467 build_method_type (tree basetype, tree type)
4469 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
4471 return build_method_type_directly (basetype,
4473 TYPE_ARG_TYPES (type));
4476 /* Construct, lay out and return the type of offsets to a value
4477 of type TYPE, within an object of type BASETYPE.
4478 If a suitable offset type exists already, reuse it. */
4481 build_offset_type (tree basetype, tree type)
4484 hashval_t hashcode = 0;
4486 /* Make a node of the sort we want. */
4487 t = make_node (OFFSET_TYPE);
4489 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4490 TREE_TYPE (t) = type;
4492 /* If we already have such a type, use the old one. */
4493 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4494 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
4495 t = type_hash_canon (hashcode, t);
4497 if (!COMPLETE_TYPE_P (t))
4503 /* Create a complex type whose components are COMPONENT_TYPE. */
4506 build_complex_type (tree component_type)
4511 /* Make a node of the sort we want. */
4512 t = make_node (COMPLEX_TYPE);
4514 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4516 /* If we already have such a type, use the old one. */
4517 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
4518 t = type_hash_canon (hashcode, t);
4520 if (!COMPLETE_TYPE_P (t))
4523 /* If we are writing Dwarf2 output we need to create a name,
4524 since complex is a fundamental type. */
4525 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4529 if (component_type == char_type_node)
4530 name = "complex char";
4531 else if (component_type == signed_char_type_node)
4532 name = "complex signed char";
4533 else if (component_type == unsigned_char_type_node)
4534 name = "complex unsigned char";
4535 else if (component_type == short_integer_type_node)
4536 name = "complex short int";
4537 else if (component_type == short_unsigned_type_node)
4538 name = "complex short unsigned int";
4539 else if (component_type == integer_type_node)
4540 name = "complex int";
4541 else if (component_type == unsigned_type_node)
4542 name = "complex unsigned int";
4543 else if (component_type == long_integer_type_node)
4544 name = "complex long int";
4545 else if (component_type == long_unsigned_type_node)
4546 name = "complex long unsigned int";
4547 else if (component_type == long_long_integer_type_node)
4548 name = "complex long long int";
4549 else if (component_type == long_long_unsigned_type_node)
4550 name = "complex long long unsigned int";
4555 TYPE_NAME (t) = get_identifier (name);
4558 return build_qualified_type (t, TYPE_QUALS (component_type));
4561 /* Return OP, stripped of any conversions to wider types as much as is safe.
4562 Converting the value back to OP's type makes a value equivalent to OP.
4564 If FOR_TYPE is nonzero, we return a value which, if converted to
4565 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4567 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4568 narrowest type that can hold the value, even if they don't exactly fit.
4569 Otherwise, bit-field references are changed to a narrower type
4570 only if they can be fetched directly from memory in that type.
4572 OP must have integer, real or enumeral type. Pointers are not allowed!
4574 There are some cases where the obvious value we could return
4575 would regenerate to OP if converted to OP's type,
4576 but would not extend like OP to wider types.
4577 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4578 For example, if OP is (unsigned short)(signed char)-1,
4579 we avoid returning (signed char)-1 if FOR_TYPE is int,
4580 even though extending that to an unsigned short would regenerate OP,
4581 since the result of extending (signed char)-1 to (int)
4582 is different from (int) OP. */
4585 get_unwidened (tree op, tree for_type)
4587 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4588 tree type = TREE_TYPE (op);
4590 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4592 = (for_type != 0 && for_type != type
4593 && final_prec > TYPE_PRECISION (type)
4594 && TYPE_UNSIGNED (type));
4597 while (TREE_CODE (op) == NOP_EXPR)
4600 = TYPE_PRECISION (TREE_TYPE (op))
4601 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4603 /* Truncations are many-one so cannot be removed.
4604 Unless we are later going to truncate down even farther. */
4606 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4609 /* See what's inside this conversion. If we decide to strip it,
4611 op = TREE_OPERAND (op, 0);
4613 /* If we have not stripped any zero-extensions (uns is 0),
4614 we can strip any kind of extension.
4615 If we have previously stripped a zero-extension,
4616 only zero-extensions can safely be stripped.
4617 Any extension can be stripped if the bits it would produce
4618 are all going to be discarded later by truncating to FOR_TYPE. */
4622 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4624 /* TYPE_UNSIGNED says whether this is a zero-extension.
4625 Let's avoid computing it if it does not affect WIN
4626 and if UNS will not be needed again. */
4627 if ((uns || TREE_CODE (op) == NOP_EXPR)
4628 && TYPE_UNSIGNED (TREE_TYPE (op)))
4636 if (TREE_CODE (op) == COMPONENT_REF
4637 /* Since type_for_size always gives an integer type. */
4638 && TREE_CODE (type) != REAL_TYPE
4639 /* Don't crash if field not laid out yet. */
4640 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4641 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4643 unsigned int innerprec
4644 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4645 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4646 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4647 type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4649 /* We can get this structure field in the narrowest type it fits in.
4650 If FOR_TYPE is 0, do this only for a field that matches the
4651 narrower type exactly and is aligned for it
4652 The resulting extension to its nominal type (a fullword type)
4653 must fit the same conditions as for other extensions. */
4656 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
4657 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4658 && (! uns || final_prec <= innerprec || unsignedp))
4660 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4661 TREE_OPERAND (op, 1), NULL_TREE);
4662 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4663 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4670 /* Return OP or a simpler expression for a narrower value
4671 which can be sign-extended or zero-extended to give back OP.
4672 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4673 or 0 if the value should be sign-extended. */
4676 get_narrower (tree op, int *unsignedp_ptr)
4681 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
4683 while (TREE_CODE (op) == NOP_EXPR)
4686 = (TYPE_PRECISION (TREE_TYPE (op))
4687 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4689 /* Truncations are many-one so cannot be removed. */
4693 /* See what's inside this conversion. If we decide to strip it,
4698 op = TREE_OPERAND (op, 0);
4699 /* An extension: the outermost one can be stripped,
4700 but remember whether it is zero or sign extension. */
4702 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4703 /* Otherwise, if a sign extension has been stripped,
4704 only sign extensions can now be stripped;
4705 if a zero extension has been stripped, only zero-extensions. */
4706 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
4710 else /* bitschange == 0 */
4712 /* A change in nominal type can always be stripped, but we must
4713 preserve the unsignedness. */
4715 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4717 op = TREE_OPERAND (op, 0);
4718 /* Keep trying to narrow, but don't assign op to win if it
4719 would turn an integral type into something else. */
4720 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
4727 if (TREE_CODE (op) == COMPONENT_REF
4728 /* Since type_for_size always gives an integer type. */
4729 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4730 /* Ensure field is laid out already. */
4731 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4732 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4734 unsigned HOST_WIDE_INT innerprec
4735 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4736 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4737 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4738 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4740 /* We can get this structure field in a narrower type that fits it,
4741 but the resulting extension to its nominal type (a fullword type)
4742 must satisfy the same conditions as for other extensions.
4744 Do this only for fields that are aligned (not bit-fields),
4745 because when bit-field insns will be used there is no
4746 advantage in doing this. */
4748 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4749 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4750 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
4754 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
4755 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4756 TREE_OPERAND (op, 1), NULL_TREE);
4757 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4758 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4761 *unsignedp_ptr = uns;
4765 /* Nonzero if integer constant C has a value that is permissible
4766 for type TYPE (an INTEGER_TYPE). */
4769 int_fits_type_p (tree c, tree type)
4771 tree type_low_bound = TYPE_MIN_VALUE (type);
4772 tree type_high_bound = TYPE_MAX_VALUE (type);
4773 int ok_for_low_bound, ok_for_high_bound;
4775 /* Perform some generic filtering first, which may allow making a decision
4776 even if the bounds are not constant. First, negative integers never fit
4777 in unsigned types, */
4778 if ((TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
4779 /* Also, unsigned integers with top bit set never fit signed types. */
4780 || (! TYPE_UNSIGNED (type)
4781 && TYPE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c)))
4784 /* If at least one bound of the type is a constant integer, we can check
4785 ourselves and maybe make a decision. If no such decision is possible, but
4786 this type is a subtype, try checking against that. Otherwise, use
4787 force_fit_type, which checks against the precision.
4789 Compute the status for each possibly constant bound, and return if we see
4790 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
4791 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
4792 for "constant known to fit". */
4794 ok_for_low_bound = -1;
4795 ok_for_high_bound = -1;
4797 /* Check if C >= type_low_bound. */
4798 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
4800 ok_for_low_bound = ! tree_int_cst_lt (c, type_low_bound);
4801 if (! ok_for_low_bound)
4805 /* Check if c <= type_high_bound. */
4806 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
4808 ok_for_high_bound = ! tree_int_cst_lt (type_high_bound, c);
4809 if (! ok_for_high_bound)
4813 /* If the constant fits both bounds, the result is known. */
4814 if (ok_for_low_bound == 1 && ok_for_high_bound == 1)
4817 /* If we haven't been able to decide at this point, there nothing more we
4818 can check ourselves here. Look at the base type if we have one. */
4819 else if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4820 return int_fits_type_p (c, TREE_TYPE (type));
4822 /* Or to force_fit_type, if nothing else. */
4826 TREE_TYPE (c) = type;
4827 c = force_fit_type (c, -1, false, false);
4828 return !TREE_OVERFLOW (c);
4832 /* Subprogram of following function. Called by walk_tree.
4834 Return *TP if it is an automatic variable or parameter of the
4835 function passed in as DATA. */
4838 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
4840 tree fn = (tree) data;
4845 else if (DECL_P (*tp)
4846 && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
4852 /* Returns true if T is, contains, or refers to a type with variable
4853 size. If FN is nonzero, only return true if a modifier of the type
4854 or position of FN is a variable or parameter inside FN.
4856 This concept is more general than that of C99 'variably modified types':
4857 in C99, a struct type is never variably modified because a VLA may not
4858 appear as a structure member. However, in GNU C code like:
4860 struct S { int i[f()]; };
4862 is valid, and other languages may define similar constructs. */
4865 variably_modified_type_p (tree type, tree fn)
4869 /* Test if T is either variable (if FN is zero) or an expression containing
4870 a variable in FN. */
4871 #define RETURN_TRUE_IF_VAR(T) \
4872 do { tree _t = (T); \
4873 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
4874 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
4875 return true; } while (0)
4877 if (type == error_mark_node)
4880 /* If TYPE itself has variable size, it is variably modified.
4882 We do not yet have a representation of the C99 '[*]' syntax.
4883 When a representation is chosen, this function should be modified
4884 to test for that case as well. */
4885 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
4886 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
4888 switch (TREE_CODE (type))
4891 case REFERENCE_TYPE:
4895 if (variably_modified_type_p (TREE_TYPE (type), fn))
4901 /* If TYPE is a function type, it is variably modified if any of the
4902 parameters or the return type are variably modified. */
4903 if (variably_modified_type_p (TREE_TYPE (type), fn))
4906 for (t = TYPE_ARG_TYPES (type);
4907 t && t != void_list_node;
4909 if (variably_modified_type_p (TREE_VALUE (t), fn))
4918 /* Scalar types are variably modified if their end points
4920 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
4921 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
4926 case QUAL_UNION_TYPE:
4927 /* We can't see if any of the field are variably-modified by the
4928 definition we normally use, since that would produce infinite
4929 recursion via pointers. */
4930 /* This is variably modified if some field's type is. */
4931 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
4932 if (TREE_CODE (t) == FIELD_DECL)
4934 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
4935 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
4936 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
4938 if (TREE_CODE (type) == QUAL_UNION_TYPE)
4939 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
4947 /* The current language may have other cases to check, but in general,
4948 all other types are not variably modified. */
4949 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
4951 #undef RETURN_TRUE_IF_VAR
4954 /* Given a DECL or TYPE, return the scope in which it was declared, or
4955 NULL_TREE if there is no containing scope. */
4958 get_containing_scope (tree t)
4960 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4963 /* Return the innermost context enclosing DECL that is
4964 a FUNCTION_DECL, or zero if none. */
4967 decl_function_context (tree decl)
4971 if (TREE_CODE (decl) == ERROR_MARK)
4974 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4975 where we look up the function at runtime. Such functions always take
4976 a first argument of type 'pointer to real context'.
4978 C++ should really be fixed to use DECL_CONTEXT for the real context,
4979 and use something else for the "virtual context". */
4980 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4983 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4985 context = DECL_CONTEXT (decl);
4987 while (context && TREE_CODE (context) != FUNCTION_DECL)
4989 if (TREE_CODE (context) == BLOCK)
4990 context = BLOCK_SUPERCONTEXT (context);
4992 context = get_containing_scope (context);
4998 /* Return the innermost context enclosing DECL that is
4999 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
5000 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
5003 decl_type_context (tree decl)
5005 tree context = DECL_CONTEXT (decl);
5008 switch (TREE_CODE (context))
5010 case NAMESPACE_DECL:
5011 case TRANSLATION_UNIT_DECL:
5016 case QUAL_UNION_TYPE:
5021 context = DECL_CONTEXT (context);
5025 context = BLOCK_SUPERCONTEXT (context);
5035 /* CALL is a CALL_EXPR. Return the declaration for the function
5036 called, or NULL_TREE if the called function cannot be
5040 get_callee_fndecl (tree call)
5044 /* It's invalid to call this function with anything but a
5046 gcc_assert (TREE_CODE (call) == CALL_EXPR);
5048 /* The first operand to the CALL is the address of the function
5050 addr = TREE_OPERAND (call, 0);
5054 /* If this is a readonly function pointer, extract its initial value. */
5055 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
5056 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
5057 && DECL_INITIAL (addr))
5058 addr = DECL_INITIAL (addr);
5060 /* If the address is just `&f' for some function `f', then we know
5061 that `f' is being called. */
5062 if (TREE_CODE (addr) == ADDR_EXPR
5063 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
5064 return TREE_OPERAND (addr, 0);
5066 /* We couldn't figure out what was being called. Maybe the front
5067 end has some idea. */
5068 return lang_hooks.lang_get_callee_fndecl (call);
5071 /* Print debugging information about tree nodes generated during the compile,
5072 and any language-specific information. */
5075 dump_tree_statistics (void)
5077 #ifdef GATHER_STATISTICS
5079 int total_nodes, total_bytes;
5082 fprintf (stderr, "\n??? tree nodes created\n\n");
5083 #ifdef GATHER_STATISTICS
5084 fprintf (stderr, "Kind Nodes Bytes\n");
5085 fprintf (stderr, "---------------------------------------\n");
5086 total_nodes = total_bytes = 0;
5087 for (i = 0; i < (int) all_kinds; i++)
5089 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
5090 tree_node_counts[i], tree_node_sizes[i]);
5091 total_nodes += tree_node_counts[i];
5092 total_bytes += tree_node_sizes[i];
5094 fprintf (stderr, "---------------------------------------\n");
5095 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
5096 fprintf (stderr, "---------------------------------------\n");
5097 ssanames_print_statistics ();
5098 phinodes_print_statistics ();
5100 fprintf (stderr, "(No per-node statistics)\n");
5102 print_type_hash_statistics ();
5103 lang_hooks.print_statistics ();
5106 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5108 /* Generate a crc32 of a string. */
5111 crc32_string (unsigned chksum, const char *string)
5115 unsigned value = *string << 24;
5118 for (ix = 8; ix--; value <<= 1)
5122 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
5131 /* P is a string that will be used in a symbol. Mask out any characters
5132 that are not valid in that context. */
5135 clean_symbol_name (char *p)
5139 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5142 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5149 /* Generate a name for a function unique to this translation unit.
5150 TYPE is some string to identify the purpose of this function to the
5151 linker or collect2. */
5154 get_file_function_name_long (const char *type)
5160 if (first_global_object_name)
5161 p = first_global_object_name;
5164 /* We don't have anything that we know to be unique to this translation
5165 unit, so use what we do have and throw in some randomness. */
5167 const char *name = weak_global_object_name;
5168 const char *file = main_input_filename;
5173 file = input_filename;
5175 len = strlen (file);
5176 q = alloca (9 * 2 + len + 1);
5177 memcpy (q, file, len + 1);
5178 clean_symbol_name (q);
5180 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
5181 crc32_string (0, flag_random_seed));
5186 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
5188 /* Set up the name of the file-level functions we may need.
5189 Use a global object (which is already required to be unique over
5190 the program) rather than the file name (which imposes extra
5192 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5194 return get_identifier (buf);
5197 /* If KIND=='I', return a suitable global initializer (constructor) name.
5198 If KIND=='D', return a suitable global clean-up (destructor) name. */
5201 get_file_function_name (int kind)
5208 return get_file_function_name_long (p);
5211 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5212 The result is placed in BUFFER (which has length BIT_SIZE),
5213 with one bit in each char ('\000' or '\001').
5215 If the constructor is constant, NULL_TREE is returned.
5216 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5219 get_set_constructor_bits (tree init, char *buffer, int bit_size)
5223 HOST_WIDE_INT domain_min
5224 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
5225 tree non_const_bits = NULL_TREE;
5227 for (i = 0; i < bit_size; i++)
5230 for (vals = TREE_OPERAND (init, 1);
5231 vals != NULL_TREE; vals = TREE_CHAIN (vals))
5233 if (!host_integerp (TREE_VALUE (vals), 0)
5234 || (TREE_PURPOSE (vals) != NULL_TREE
5235 && !host_integerp (TREE_PURPOSE (vals), 0)))
5237 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
5238 else if (TREE_PURPOSE (vals) != NULL_TREE)
5240 /* Set a range of bits to ones. */
5241 HOST_WIDE_INT lo_index
5242 = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
5243 HOST_WIDE_INT hi_index
5244 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5246 gcc_assert (lo_index >= 0);
5247 gcc_assert (lo_index < bit_size);
5248 gcc_assert (hi_index >= 0);
5249 gcc_assert (hi_index < bit_size);
5250 for (; lo_index <= hi_index; lo_index++)
5251 buffer[lo_index] = 1;
5255 /* Set a single bit to one. */
5257 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5258 if (index < 0 || index >= bit_size)
5260 error ("invalid initializer for bit string");
5266 return non_const_bits;
5269 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5270 The result is placed in BUFFER (which is an array of bytes).
5271 If the constructor is constant, NULL_TREE is returned.
5272 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5275 get_set_constructor_bytes (tree init, unsigned char *buffer, int wd_size)
5278 int set_word_size = BITS_PER_UNIT;
5279 int bit_size = wd_size * set_word_size;
5281 unsigned char *bytep = buffer;
5282 char *bit_buffer = alloca (bit_size);
5283 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
5285 for (i = 0; i < wd_size; i++)
5288 for (i = 0; i < bit_size; i++)
5292 if (BYTES_BIG_ENDIAN)
5293 *bytep |= (1 << (set_word_size - 1 - bit_pos));
5295 *bytep |= 1 << bit_pos;
5298 if (bit_pos >= set_word_size)
5299 bit_pos = 0, bytep++;
5301 return non_const_bits;
5304 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5306 /* Complain that the tree code of NODE does not match the expected 0
5307 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5311 tree_check_failed (const tree node, const char *file,
5312 int line, const char *function, ...)
5316 unsigned length = 0;
5319 va_start (args, function);
5320 while ((code = va_arg (args, int)))
5321 length += 4 + strlen (tree_code_name[code]);
5323 va_start (args, function);
5324 buffer = alloca (length);
5326 while ((code = va_arg (args, int)))
5330 strcpy (buffer + length, " or ");
5333 strcpy (buffer + length, tree_code_name[code]);
5334 length += strlen (tree_code_name[code]);
5338 internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
5339 buffer, tree_code_name[TREE_CODE (node)],
5340 function, trim_filename (file), line);
5343 /* Complain that the tree code of NODE does match the expected 0
5344 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5348 tree_not_check_failed (const tree node, const char *file,
5349 int line, const char *function, ...)
5353 unsigned length = 0;
5356 va_start (args, function);
5357 while ((code = va_arg (args, int)))
5358 length += 4 + strlen (tree_code_name[code]);
5360 va_start (args, function);
5361 buffer = alloca (length);
5363 while ((code = va_arg (args, int)))
5367 strcpy (buffer + length, " or ");
5370 strcpy (buffer + length, tree_code_name[code]);
5371 length += strlen (tree_code_name[code]);
5375 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5376 buffer, tree_code_name[TREE_CODE (node)],
5377 function, trim_filename (file), line);
5380 /* Similar to tree_check_failed, except that we check for a class of tree
5381 code, given in CL. */
5384 tree_class_check_failed (const tree node, const enum tree_code_class cl,
5385 const char *file, int line, const char *function)
5388 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
5389 TREE_CODE_CLASS_STRING (cl),
5390 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
5391 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
5394 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
5395 (dynamically sized) vector. */
5398 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
5399 const char *function)
5402 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
5403 idx + 1, len, function, trim_filename (file), line);
5406 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
5407 (dynamically sized) vector. */
5410 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
5411 const char *function)
5414 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
5415 idx + 1, len, function, trim_filename (file), line);
5418 /* Similar to above, except that the check is for the bounds of the operand
5419 vector of an expression node. */
5422 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
5423 int line, const char *function)
5426 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
5427 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
5428 function, trim_filename (file), line);
5430 #endif /* ENABLE_TREE_CHECKING */
5432 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
5433 and mapped to the machine mode MODE. Initialize its fields and build
5434 the information necessary for debugging output. */
5437 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
5439 tree t = make_node (VECTOR_TYPE);
5441 TREE_TYPE (t) = innertype;
5442 TYPE_VECTOR_SUBPARTS (t) = nunits;
5443 TYPE_MODE (t) = mode;
5447 tree index = build_int_cst (NULL_TREE, nunits - 1);
5448 tree array = build_array_type (innertype, build_index_type (index));
5449 tree rt = make_node (RECORD_TYPE);
5451 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
5452 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
5454 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
5455 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
5456 the representation type, and we want to find that die when looking up
5457 the vector type. This is most easily achieved by making the TYPE_UID
5459 TYPE_UID (rt) = TYPE_UID (t);
5466 make_or_reuse_type (unsigned size, int unsignedp)
5468 if (size == INT_TYPE_SIZE)
5469 return unsignedp ? unsigned_type_node : integer_type_node;
5470 if (size == CHAR_TYPE_SIZE)
5471 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5472 if (size == SHORT_TYPE_SIZE)
5473 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5474 if (size == LONG_TYPE_SIZE)
5475 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5476 if (size == LONG_LONG_TYPE_SIZE)
5477 return (unsignedp ? long_long_unsigned_type_node
5478 : long_long_integer_type_node);
5481 return make_unsigned_type (size);
5483 return make_signed_type (size);
5486 /* Create nodes for all integer types (and error_mark_node) using the sizes
5487 of C datatypes. The caller should call set_sizetype soon after calling
5488 this function to select one of the types as sizetype. */
5491 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
5493 error_mark_node = make_node (ERROR_MARK);
5494 TREE_TYPE (error_mark_node) = error_mark_node;
5496 initialize_sizetypes (signed_sizetype);
5498 /* Define both `signed char' and `unsigned char'. */
5499 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
5500 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
5502 /* Define `char', which is like either `signed char' or `unsigned char'
5503 but not the same as either. */
5506 ? make_signed_type (CHAR_TYPE_SIZE)
5507 : make_unsigned_type (CHAR_TYPE_SIZE));
5509 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
5510 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
5511 integer_type_node = make_signed_type (INT_TYPE_SIZE);
5512 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
5513 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
5514 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
5515 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
5516 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
5518 /* Define a boolean type. This type only represents boolean values but
5519 may be larger than char depending on the value of BOOL_TYPE_SIZE.
5520 Front ends which want to override this size (i.e. Java) can redefine
5521 boolean_type_node before calling build_common_tree_nodes_2. */
5522 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
5523 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
5524 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
5525 TYPE_PRECISION (boolean_type_node) = 1;
5527 /* Fill in the rest of the sized types. Reuse existing type nodes
5529 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
5530 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
5531 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
5532 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
5533 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
5535 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
5536 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
5537 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
5538 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
5539 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
5541 access_public_node = get_identifier ("public");
5542 access_protected_node = get_identifier ("protected");
5543 access_private_node = get_identifier ("private");
5546 /* Call this function after calling build_common_tree_nodes and set_sizetype.
5547 It will create several other common tree nodes. */
5550 build_common_tree_nodes_2 (int short_double)
5552 /* Define these next since types below may used them. */
5553 integer_zero_node = build_int_cst (NULL_TREE, 0);
5554 integer_one_node = build_int_cst (NULL_TREE, 1);
5555 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
5557 size_zero_node = size_int (0);
5558 size_one_node = size_int (1);
5559 bitsize_zero_node = bitsize_int (0);
5560 bitsize_one_node = bitsize_int (1);
5561 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
5563 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
5564 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
5566 void_type_node = make_node (VOID_TYPE);
5567 layout_type (void_type_node);
5569 /* We are not going to have real types in C with less than byte alignment,
5570 so we might as well not have any types that claim to have it. */
5571 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
5572 TYPE_USER_ALIGN (void_type_node) = 0;
5574 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
5575 layout_type (TREE_TYPE (null_pointer_node));
5577 ptr_type_node = build_pointer_type (void_type_node);
5579 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
5580 fileptr_type_node = ptr_type_node;
5582 float_type_node = make_node (REAL_TYPE);
5583 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
5584 layout_type (float_type_node);
5586 double_type_node = make_node (REAL_TYPE);
5588 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
5590 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
5591 layout_type (double_type_node);
5593 long_double_type_node = make_node (REAL_TYPE);
5594 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
5595 layout_type (long_double_type_node);
5597 float_ptr_type_node = build_pointer_type (float_type_node);
5598 double_ptr_type_node = build_pointer_type (double_type_node);
5599 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
5600 integer_ptr_type_node = build_pointer_type (integer_type_node);
5602 complex_integer_type_node = make_node (COMPLEX_TYPE);
5603 TREE_TYPE (complex_integer_type_node) = integer_type_node;
5604 layout_type (complex_integer_type_node);
5606 complex_float_type_node = make_node (COMPLEX_TYPE);
5607 TREE_TYPE (complex_float_type_node) = float_type_node;
5608 layout_type (complex_float_type_node);
5610 complex_double_type_node = make_node (COMPLEX_TYPE);
5611 TREE_TYPE (complex_double_type_node) = double_type_node;
5612 layout_type (complex_double_type_node);
5614 complex_long_double_type_node = make_node (COMPLEX_TYPE);
5615 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
5616 layout_type (complex_long_double_type_node);
5619 tree t = targetm.build_builtin_va_list ();
5621 /* Many back-ends define record types without setting TYPE_NAME.
5622 If we copied the record type here, we'd keep the original
5623 record type without a name. This breaks name mangling. So,
5624 don't copy record types and let c_common_nodes_and_builtins()
5625 declare the type to be __builtin_va_list. */
5626 if (TREE_CODE (t) != RECORD_TYPE)
5627 t = build_variant_type_copy (t);
5629 va_list_type_node = t;
5633 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
5636 If we requested a pointer to a vector, build up the pointers that
5637 we stripped off while looking for the inner type. Similarly for
5638 return values from functions.
5640 The argument TYPE is the top of the chain, and BOTTOM is the
5641 new type which we will point to. */
5644 reconstruct_complex_type (tree type, tree bottom)
5648 if (POINTER_TYPE_P (type))
5650 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5651 outer = build_pointer_type (inner);
5653 else if (TREE_CODE (type) == ARRAY_TYPE)
5655 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5656 outer = build_array_type (inner, TYPE_DOMAIN (type));
5658 else if (TREE_CODE (type) == FUNCTION_TYPE)
5660 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5661 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
5663 else if (TREE_CODE (type) == METHOD_TYPE)
5666 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5667 /* The build_method_type_directly() routine prepends 'this' to argument list,
5668 so we must compensate by getting rid of it. */
5669 argtypes = TYPE_ARG_TYPES (type);
5670 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
5672 TYPE_ARG_TYPES (type));
5673 TYPE_ARG_TYPES (outer) = argtypes;
5678 TYPE_READONLY (outer) = TYPE_READONLY (type);
5679 TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
5684 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
5687 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
5691 switch (GET_MODE_CLASS (mode))
5693 case MODE_VECTOR_INT:
5694 case MODE_VECTOR_FLOAT:
5695 nunits = GET_MODE_NUNITS (mode);
5699 /* Check that there are no leftover bits. */
5700 gcc_assert (GET_MODE_BITSIZE (mode)
5701 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
5703 nunits = GET_MODE_BITSIZE (mode)
5704 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
5711 return make_vector_type (innertype, nunits, mode);
5714 /* Similarly, but takes the inner type and number of units, which must be
5718 build_vector_type (tree innertype, int nunits)
5720 return make_vector_type (innertype, nunits, VOIDmode);
5723 /* Given an initializer INIT, return TRUE if INIT is zero or some
5724 aggregate of zeros. Otherwise return FALSE. */
5726 initializer_zerop (tree init)
5732 switch (TREE_CODE (init))
5735 return integer_zerop (init);
5738 /* ??? Note that this is not correct for C4X float formats. There,
5739 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
5740 negative exponent. */
5741 return real_zerop (init)
5742 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
5745 return integer_zerop (init)
5746 || (real_zerop (init)
5747 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
5748 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
5751 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
5752 if (!initializer_zerop (TREE_VALUE (elt)))
5757 elt = CONSTRUCTOR_ELTS (init);
5758 if (elt == NULL_TREE)
5761 /* A set is empty only if it has no elements. */
5762 if (TREE_CODE (TREE_TYPE (init)) == SET_TYPE)
5765 for (; elt ; elt = TREE_CHAIN (elt))
5766 if (! initializer_zerop (TREE_VALUE (elt)))
5776 add_var_to_bind_expr (tree bind_expr, tree var)
5778 BIND_EXPR_VARS (bind_expr)
5779 = chainon (BIND_EXPR_VARS (bind_expr), var);
5780 if (BIND_EXPR_BLOCK (bind_expr))
5781 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr))
5782 = BIND_EXPR_VARS (bind_expr);
5785 /* Build an empty statement. */
5788 build_empty_stmt (void)
5790 return build1 (NOP_EXPR, void_type_node, size_zero_node);
5794 /* Returns true if it is possible to prove that the index of
5795 an array access REF (an ARRAY_REF expression) falls into the
5799 in_array_bounds_p (tree ref)
5801 tree idx = TREE_OPERAND (ref, 1);
5804 if (TREE_CODE (idx) != INTEGER_CST)
5807 min = array_ref_low_bound (ref);
5808 max = array_ref_up_bound (ref);
5811 || TREE_CODE (min) != INTEGER_CST
5812 || TREE_CODE (max) != INTEGER_CST)
5815 if (tree_int_cst_lt (idx, min)
5816 || tree_int_cst_lt (max, idx))
5822 /* Return true if T (assumed to be a DECL) is a global variable. */
5825 is_global_var (tree t)
5827 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
5830 /* Return true if T (assumed to be a DECL) must be assigned a memory
5834 needs_to_live_in_memory (tree t)
5836 return (TREE_ADDRESSABLE (t)
5837 || is_global_var (t)
5838 || (TREE_CODE (t) == RESULT_DECL
5839 && aggregate_value_p (t, current_function_decl)));
5842 /* There are situations in which a language considers record types
5843 compatible which have different field lists. Decide if two fields
5844 are compatible. It is assumed that the parent records are compatible. */
5847 fields_compatible_p (tree f1, tree f2)
5849 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
5850 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
5853 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
5854 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
5857 if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
5863 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
5866 find_compatible_field (tree record, tree orig_field)
5870 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
5871 if (TREE_CODE (f) == FIELD_DECL
5872 && fields_compatible_p (f, orig_field))
5875 /* ??? Why isn't this on the main fields list? */
5876 f = TYPE_VFIELD (record);
5877 if (f && TREE_CODE (f) == FIELD_DECL
5878 && fields_compatible_p (f, orig_field))
5881 /* ??? We should abort here, but Java appears to do Bad Things
5882 with inherited fields. */
5886 /* Return value of a constant X. */
5889 int_cst_value (tree x)
5891 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
5892 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
5893 bool negative = ((val >> (bits - 1)) & 1) != 0;
5895 gcc_assert (bits <= HOST_BITS_PER_WIDE_INT);
5898 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
5900 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
5905 /* Returns the greatest common divisor of A and B, which must be
5909 tree_fold_gcd (tree a, tree b)
5912 tree type = TREE_TYPE (a);
5914 gcc_assert (TREE_CODE (a) == INTEGER_CST);
5915 gcc_assert (TREE_CODE (b) == INTEGER_CST);
5917 if (integer_zerop (a))
5920 if (integer_zerop (b))
5923 if (tree_int_cst_sgn (a) == -1)
5924 a = fold (build2 (MULT_EXPR, type, a,
5925 convert (type, integer_minus_one_node)));
5927 if (tree_int_cst_sgn (b) == -1)
5928 b = fold (build2 (MULT_EXPR, type, b,
5929 convert (type, integer_minus_one_node)));
5933 a_mod_b = fold (build2 (CEIL_MOD_EXPR, type, a, b));
5935 if (!TREE_INT_CST_LOW (a_mod_b)
5936 && !TREE_INT_CST_HIGH (a_mod_b))
5944 /* Returns unsigned variant of TYPE. */
5947 unsigned_type_for (tree type)
5949 return lang_hooks.types.unsigned_type (type);
5952 /* Returns signed variant of TYPE. */
5955 signed_type_for (tree type)
5957 return lang_hooks.types.signed_type (type);
5960 #include "gt-tree.h"