X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Ftree.c;h=12aa391d8e8eb46e6141fc55a2753fd7e580e91d;hb=74ca0dd9c18166183e5181020d21e17db185904f;hp=a4bbd668bb324365def7ef001875dfab66649270;hpb=3cb98335f5a6d00604531c7874c897d91ac8a4d6;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/tree.c b/gcc/tree.c index a4bbd668bb3..12aa391d8e8 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -48,6 +48,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "tree-iterator.h" #include "basic-block.h" #include "tree-flow.h" +#include "params.h" /* obstack.[ch] explicitly declined to prototype this. */ extern int _obstack_allocated_p (struct obstack *h, void *obj); @@ -94,9 +95,6 @@ struct type_hash GTY(()) tree type; }; -/* Additional language-dependent binfo slots. */ -unsigned binfo_lang_slots; - /* Initial size of the hash table (rounded to next prime). */ #define TYPE_HASH_INITIAL_SIZE 1000 @@ -114,7 +112,7 @@ static void set_type_quals (tree, int); static int type_hash_eq (const void *, const void *); static hashval_t type_hash_hash (const void *); static void print_type_hash_statistics (void); -static void finish_vector_type (tree); +static tree make_vector_type (tree, int, enum machine_mode); static int type_hash_marked_p (const void *); static unsigned int type_hash_list (tree, hashval_t); static unsigned int attribute_hash_list (tree, hashval_t); @@ -394,6 +392,13 @@ copy_node_stat (tree node MEM_STAT_DECL) but the optimizer should catch that. */ TYPE_SYMTAB_POINTER (t) = 0; TYPE_SYMTAB_ADDRESS (t) = 0; + + /* Do not copy the values cache. */ + if (TYPE_CACHED_VALUES_P(t)) + { + TYPE_CACHED_VALUES_P (t) = 0; + TYPE_CACHED_VALUES (t) = NULL_TREE; + } } return t; @@ -423,20 +428,91 @@ copy_list (tree list) } -/* Return a newly constructed INTEGER_CST node whose constant value - is specified by the two ints LOW and HI. - The TREE_TYPE is set to `int'. - - This function should be used via the `build_int_2' macro. */ +/* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL, + integer_type_node is used. */ tree -build_int_2_wide (unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) +build_int_cst (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) { - tree t = make_node (INTEGER_CST); + tree t; + int ix = -1; + int limit = 0; + + if (!type) + type = integer_type_node; + + switch (TREE_CODE (type)) + { + case POINTER_TYPE: + case REFERENCE_TYPE: + /* Cache NULL pointer. */ + if (!hi && !low) + { + limit = 1; + ix = 0; + } + break; + + case BOOLEAN_TYPE: + /* Cache false or true. */ + limit = 2; + if (!hi && low < 2) + ix = low; + break; + + case INTEGER_TYPE: + case CHAR_TYPE: + case OFFSET_TYPE: + if (TYPE_UNSIGNED (type)) + { + /* Cache 0..N */ + limit = INTEGER_SHARE_LIMIT; + if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) + ix = low; + } + else + { + /* Cache -1..N */ + limit = INTEGER_SHARE_LIMIT + 1; + if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) + ix = low + 1; + else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) + ix = 0; + } + break; + default: + break; + } + + if (ix >= 0) + { + if (!TYPE_CACHED_VALUES_P (type)) + { + TYPE_CACHED_VALUES_P (type) = 1; + TYPE_CACHED_VALUES (type) = make_tree_vec (limit); + } + + t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); + if (t) + { + /* Make sure no one is clobbering the shared constant. */ + if (TREE_TYPE (t) != type) + abort (); + if (TREE_INT_CST_LOW (t) != low || TREE_INT_CST_HIGH (t) != hi) + abort (); + return t; + } + } + + t = make_node (INTEGER_CST); TREE_INT_CST_LOW (t) = low; TREE_INT_CST_HIGH (t) = hi; - TREE_TYPE (t) = integer_type_node; + TREE_TYPE (t) = type; + + if (ix >= 0) + TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; + return t; } @@ -582,21 +658,12 @@ build_complex (tree type, tree real, tree imag) /* Build a BINFO with LEN language slots. */ tree -make_tree_binfo_stat (unsigned lang_slots MEM_STAT_DECL) +make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL) { tree t; - static unsigned length; - - if (!length) - { - length = (offsetof (struct tree_binfo, lang_slots) - + (sizeof (((struct tree_binfo *)0)->lang_slots[0]) - * lang_slots)); - binfo_lang_slots = lang_slots; - } - else if (binfo_lang_slots != lang_slots) - abort (); - + size_t length = (offsetof (struct tree_binfo, base_binfos) + + VEC_embedded_size (tree, base_binfos)); + #ifdef GATHER_STATISTICS tree_node_counts[(int) binfo_kind]++; tree_node_sizes[(int) binfo_kind] += length; @@ -604,10 +671,12 @@ make_tree_binfo_stat (unsigned lang_slots MEM_STAT_DECL) t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT); - memset (t, 0, length); + memset (t, 0, offsetof (struct tree_binfo, base_binfos)); TREE_SET_CODE (t, TREE_BINFO); + VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos); + return t; } @@ -963,21 +1032,6 @@ purpose_member (tree elem, tree list) return NULL_TREE; } -/* Return first list element whose BINFO_TYPE is ELEM. - Return 0 if ELEM is not in LIST. */ - -tree -binfo_member (tree elem, tree list) -{ - while (list) - { - if (elem == BINFO_TYPE (list)) - return list; - list = TREE_CHAIN (list); - } - return NULL_TREE; -} - /* Return nonzero if ELEM is part of the chain CHAIN. */ int @@ -1157,7 +1211,7 @@ size_in_bytes (tree type) } if (TREE_CODE (t) == INTEGER_CST) - force_fit_type (t, 0); + t = force_fit_type (t, 0, false, false); return t; } @@ -1244,7 +1298,7 @@ expr_align (tree t) case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: - case CLEANUP_POINT_EXPR: case UNSAVE_EXPR: + case CLEANUP_POINT_EXPR: /* These don't change the alignment of an object. */ return expr_align (TREE_OPERAND (t, 0)); @@ -1294,10 +1348,10 @@ array_type_nelts (tree type) : fold (build2 (MINUS_EXPR, TREE_TYPE (max), max, min))); } -/* Return nonzero if arg is static -- a reference to an object in +/* Return true if arg is static -- a reference to an object in static storage. This is not the same as the C meaning of `static'. */ -int +bool staticp (tree arg) { switch (TREE_CODE (arg)) @@ -1318,10 +1372,10 @@ staticp (tree arg) case LABEL_DECL: case STRING_CST: - return 1; + return true; case COMPONENT_REF: - /* If the thing being referenced is not a field, then it is + /* If the thing being referenced is not a field, then it is something language specific. */ if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL) return (*lang_hooks.staticp) (arg); @@ -1329,12 +1383,12 @@ staticp (tree arg) /* If we are referencing a bitfield, we can't evaluate an ADDR_EXPR at compile time and so it isn't a constant. */ if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1))) - return 0; + return false; return staticp (TREE_OPERAND (arg, 0)); case BIT_FIELD_REF: - return 0; + return false; #if 0 /* This case is technically correct, but results in setting @@ -1350,14 +1404,14 @@ staticp (tree arg) && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) return staticp (TREE_OPERAND (arg, 0)); else - return 0; + return false; default: if ((unsigned int) TREE_CODE (arg) >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) return lang_hooks.staticp (arg); else - return 0; + return false; } } @@ -1463,24 +1517,6 @@ skip_simple_arithmetic (tree expr) return inner; } -/* Arrange for an expression to be expanded multiple independent - times. This is useful for cleanup actions, as the backend can - expand them multiple times in different places. */ - -tree -unsave_expr (tree expr) -{ - tree t; - - /* If this is already protected, no sense in protecting it again. */ - if (TREE_CODE (expr) == UNSAVE_EXPR) - return expr; - - t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr); - TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr); - return t; -} - /* Returns the index of the first non-tree operand for CODE, or the number of operands if all are trees. */ @@ -1489,10 +1525,6 @@ first_rtl_op (enum tree_code code) { switch (code) { - case GOTO_SUBROUTINE_EXPR: - return 0; - case WITH_CLEANUP_EXPR: - return 2; default: return TREE_CODE_LENGTH (code); } @@ -1539,131 +1571,6 @@ tree_node_structure (tree t) abort (); } } - -/* Perform any modifications to EXPR required when it is unsaved. Does - not recurse into EXPR's subtrees. */ - -void -unsave_expr_1 (tree expr) -{ - switch (TREE_CODE (expr)) - { - case TARGET_EXPR: - /* Don't mess with a TARGET_EXPR that hasn't been expanded. - It's OK for this to happen if it was part of a subtree that - isn't immediately expanded, such as operand 2 of another - TARGET_EXPR. */ - if (TREE_OPERAND (expr, 1)) - break; - - TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3); - TREE_OPERAND (expr, 3) = NULL_TREE; - break; - - default: - break; - } -} - -/* Return 0 if it is safe to evaluate EXPR multiple times, - return 1 if it is safe if EXPR is unsaved afterward, or - return 2 if it is completely unsafe. - - This assumes that CALL_EXPRs and TARGET_EXPRs are never replicated in - an expression tree, so that it safe to unsave them and the surrounding - context will be correct. - - SAVE_EXPRs basically *only* appear replicated in an expression tree, - occasionally across the whole of a function. It is therefore only - safe to unsave a SAVE_EXPR if you know that all occurrences appear - below the UNSAVE_EXPR. */ - -int -unsafe_for_reeval (tree expr) -{ - int unsafeness = 0; - enum tree_code code; - int i, tmp, tmp2; - tree exp; - int first_rtl; - - if (expr == NULL_TREE) - return 1; - - code = TREE_CODE (expr); - first_rtl = first_rtl_op (code); - - switch (code) - { - case SAVE_EXPR: - return 2; - - /* A label can only be emitted once. */ - case LABEL_EXPR: - return 1; - - case BIND_EXPR: - unsafeness = 1; - break; - - case TREE_LIST: - for (exp = expr; exp != 0; exp = TREE_CHAIN (exp)) - { - tmp = unsafe_for_reeval (TREE_VALUE (exp)); - unsafeness = MAX (tmp, unsafeness); - } - - return unsafeness; - - case CALL_EXPR: - tmp2 = unsafe_for_reeval (TREE_OPERAND (expr, 0)); - tmp = unsafe_for_reeval (TREE_OPERAND (expr, 1)); - return MAX (MAX (tmp, 1), tmp2); - - case TARGET_EXPR: - unsafeness = 1; - break; - - case EXIT_BLOCK_EXPR: - /* EXIT_BLOCK_LABELED_BLOCK, a.k.a. TREE_OPERAND (expr, 0), holds - a reference to an ancestor LABELED_BLOCK, so we need to avoid - unbounded recursion in the 'e' traversal code below. */ - exp = EXIT_BLOCK_RETURN (expr); - return exp ? unsafe_for_reeval (exp) : 0; - - default: - tmp = lang_hooks.unsafe_for_reeval (expr); - if (tmp >= 0) - return tmp; - break; - } - - switch (TREE_CODE_CLASS (code)) - { - case 'c': /* a constant */ - case 't': /* a type node */ - case 'x': /* something random, like an identifier or an ERROR_MARK. */ - case 'd': /* A decl node */ - return 0; - - case 'e': /* an expression */ - case 'r': /* a reference */ - case 's': /* an expression with side effects */ - case '<': /* a comparison expression */ - case '2': /* a binary arithmetic expression */ - case '1': /* a unary arithmetic expression */ - for (i = first_rtl - 1; i >= 0; i--) - { - tmp = unsafe_for_reeval (TREE_OPERAND (expr, i)); - unsafeness = MAX (tmp, unsafeness); - } - - return unsafeness; - - default: - return 2; - } -} /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size or offset that depends on a field within a record. */ @@ -1846,7 +1753,6 @@ has_cleanups (tree exp) switch (TREE_CODE (exp)) { case TARGET_EXPR: - case GOTO_SUBROUTINE_EXPR: case WITH_CLEANUP_EXPR: return 1; @@ -1930,8 +1836,7 @@ substitute_in_expr (tree exp, tree f, tree r) && TREE_OPERAND (exp, 1) == f) return r; - /* If this expression hasn't been completed let, leave it - alone. */ + /* If this expression hasn't been completed let, leave it alone. */ if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0) return exp; @@ -1939,8 +1844,8 @@ substitute_in_expr (tree exp, tree f, tree r) if (op0 == TREE_OPERAND (exp, 0)) return exp; - new = fold (build (code, TREE_TYPE (exp), op0, TREE_OPERAND (exp, 1), - NULL_TREE)); + new = fold (build3 (COMPONENT_REF, TREE_TYPE (exp), + op0, TREE_OPERAND (exp, 1), NULL_TREE)); } else switch (TREE_CODE_CLASS (code)) @@ -2346,18 +2251,22 @@ do { tree _node = (NODE); \ else if (TREE_CODE (node) == BIT_FIELD_REF) UPDATE_TITCSE (TREE_OPERAND (node, 2)); } - + /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from - it. If it's a decl, it's definitely invariant and it's constant if the - decl is static. (Taking the address of a volatile variable is not - volatile.) If it's a constant, the address is both invariant and - constant. Otherwise it's neither. */ + it. If it's a decl, it's invariant and constant if the decl is static. + It's also invariant if it's a decl in the current function. (Taking the + address of a volatile variable is not volatile.) If it's a constant, + the address is both invariant and constant. Otherwise it's neither. */ if (TREE_CODE (node) == INDIRECT_REF) UPDATE_TITCSE (node); else if (DECL_P (node)) { - if (!staticp (node)) + if (staticp (node)) + ; + else if (decl_function_context (node) == current_function_decl) tc = false; + else + ti = tc = false; } else if (TREE_CODE_CLASS (TREE_CODE (node)) == 'c') ; @@ -2378,7 +2287,7 @@ do { tree _node = (NODE); \ Constants, decls, types and misc nodes cannot be. We define 5 non-variadic functions, from 0 to 4 arguments. This is - enough for all extant tree codes. These functions can be called + enough for all extant tree codes. These functions can be called directly (preferably!), but can also be obtained via GCC preprocessor magic within the build macro. */ @@ -2544,7 +2453,7 @@ build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) TREE_READONLY (t) = read_only; TREE_CONSTANT (t) = constant; TREE_INVARIANT (t) = invariant; - TREE_SIDE_EFFECTS (t) = side_effects; + TREE_SIDE_EFFECTS (t) = side_effects; TREE_THIS_VOLATILE (t) = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0); @@ -2595,7 +2504,7 @@ build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1, } } - TREE_SIDE_EFFECTS (t) = side_effects; + TREE_SIDE_EFFECTS (t) = side_effects; TREE_THIS_VOLATILE (t) = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0); @@ -2627,7 +2536,7 @@ build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1, PROCESS_ARG(2); PROCESS_ARG(3); - TREE_SIDE_EFFECTS (t) = side_effects; + TREE_SIDE_EFFECTS (t) = side_effects; TREE_THIS_VOLATILE (t) = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0); @@ -2730,6 +2639,11 @@ build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL) else if (code == FUNCTION_DECL) DECL_MODE (t) = FUNCTION_MODE; + /* Set default visibility to whatever the user supplied with + visibility_specified depending on #pragma GCC visibility. */ + DECL_VISIBILITY (t) = default_visibility; + DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma; + return t; } @@ -2761,12 +2675,13 @@ expanded_location expand_location (source_location loc) { expanded_location xloc; - if (loc == 0) { xloc.file = NULL; xloc.line = 0; } + if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; } else { const struct line_map *map = linemap_lookup (&line_table, loc); xloc.file = map->to_file; xloc.line = SOURCE_LINE (map, loc); + xloc.column = SOURCE_COLUMN (map, loc); }; return xloc; } @@ -3028,7 +2943,7 @@ merge_decl_attributes (tree olddecl, tree newdecl) DECL_ATTRIBUTES (newdecl)); } -#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES +#if TARGET_DLLIMPORT_DECL_ATTRIBUTES /* Specialization of merge_decl_attributes for various Windows targets. @@ -3081,6 +2996,81 @@ merge_dllimport_decl_attributes (tree old, tree new) return a; } +/* Handle a "dllimport" or "dllexport" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_dll_attribute (tree * pnode, tree name, tree args, int flags, + bool *no_add_attrs) +{ + tree node = *pnode; + + /* These attributes may apply to structure and union types being created, + but otherwise should pass to the declaration involved. */ + if (!DECL_P (node)) + { + if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT + | (int) ATTR_FLAG_ARRAY_NEXT)) + { + *no_add_attrs = true; + return tree_cons (name, args, NULL_TREE); + } + if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE) + { + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + *no_add_attrs = true; + } + + return NULL_TREE; + } + + /* Report error on dllimport ambiguities seen now before they cause + any damage. */ + if (is_attribute_p ("dllimport", name)) + { + /* Like MS, treat definition of dllimported variables and + non-inlined functions on declaration as syntax errors. We + allow the attribute for function definitions if declared + inline. */ + if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node) + && !DECL_DECLARED_INLINE_P (node)) + { + error ("%Jfunction `%D' definition is marked dllimport.", node, node); + *no_add_attrs = true; + } + + else if (TREE_CODE (node) == VAR_DECL) + { + if (DECL_INITIAL (node)) + { + error ("%Jvariable `%D' definition is marked dllimport.", + node, node); + *no_add_attrs = true; + } + + /* `extern' needn't be specified with dllimport. + Specify `extern' now and hope for the best. Sigh. */ + DECL_EXTERNAL (node) = 1; + /* Also, implicitly give dllimport'd variables declared within + a function global scope, unless declared static. */ + if (current_function_decl != NULL_TREE && !TREE_STATIC (node)) + TREE_PUBLIC (node) = 1; + } + } + + /* Report error if symbol is not accessible at global scope. */ + if (!TREE_PUBLIC (node) + && (TREE_CODE (node) == VAR_DECL + || TREE_CODE (node) == FUNCTION_DECL)) + { + error ("%Jexternal linkage required for symbol '%D' because of " + "'%s' attribute.", node, node, IDENTIFIER_POINTER (name)); + *no_add_attrs = true; + } + + return NULL_TREE; +} + #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */ /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask @@ -3143,29 +3133,45 @@ build_qualified_type (tree type, int type_quals) /* If not, build it. */ if (!t) { - t = build_type_copy (type); + t = build_variant_type_copy (type); set_type_quals (t, type_quals); } return t; } +/* Create a new distinct copy of TYPE. The new type is made its own + MAIN_VARIANT. */ + +tree +build_distinct_type_copy (tree type) +{ + tree t = copy_node (type); + + TYPE_POINTER_TO (t) = 0; + TYPE_REFERENCE_TO (t) = 0; + + /* Make it its own variant. */ + TYPE_MAIN_VARIANT (t) = t; + TYPE_NEXT_VARIANT (t) = 0; + + return t; +} + /* Create a new variant of TYPE, equivalent but distinct. This is so the caller can modify it. */ tree -build_type_copy (tree type) +build_variant_type_copy (tree type) { tree t, m = TYPE_MAIN_VARIANT (type); - t = copy_node (type); - - TYPE_POINTER_TO (t) = 0; - TYPE_REFERENCE_TO (t) = 0; - - /* Add this type to the chain of variants of TYPE. */ + t = build_distinct_type_copy (type); + + /* Add the new type to the chain of variants of TYPE. */ TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); TYPE_NEXT_VARIANT (m) = t; + TYPE_MAIN_VARIANT (t) = m; return t; } @@ -3253,7 +3259,7 @@ type_hash_eq (const void *va, const void *vb) && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST && type_list_equal (TYPE_ARG_TYPES (a->type), TYPE_ARG_TYPES (b->type))))); - + case ARRAY_TYPE: case SET_TYPE: return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type); @@ -3706,7 +3712,7 @@ simple_cst_equal (tree t1, tree t2) TREE_STRING_LENGTH (t1))); case CONSTRUCTOR: - return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1), + return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1), CONSTRUCTOR_ELTS (t2)); case SAVE_EXPR: @@ -4130,6 +4136,28 @@ build_index_type (tree maxval) return itype; } +/* Builds a signed or unsigned integer type of precision PRECISION. + Used for C bitfields whose precision does not match that of + built-in target types. */ +tree +build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision, + int unsignedp) +{ + tree itype = make_node (INTEGER_TYPE); + + TYPE_PRECISION (itype) = precision; + + if (unsignedp) + fixup_unsigned_type (itype); + else + fixup_signed_type (itype); + + if (host_integerp (TYPE_MAX_VALUE (itype), 1)) + return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype); + + return itype; +} + /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with low bound LOWVAL and high bound HIGHVAL. @@ -4326,7 +4354,7 @@ build_method_type (tree basetype, tree type) if (TREE_CODE (type) != FUNCTION_TYPE) abort (); - return build_method_type_directly (basetype, + return build_method_type_directly (basetype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); } @@ -4536,6 +4564,7 @@ get_narrower (tree op, int *unsignedp_ptr) int uns = 0; int first = 1; tree win = op; + bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op)); while (TREE_CODE (op) == NOP_EXPR) { @@ -4572,6 +4601,10 @@ get_narrower (tree op, int *unsignedp_ptr) uns = TYPE_UNSIGNED (TREE_TYPE (op)); first = 0; op = TREE_OPERAND (op, 0); + /* Keep trying to narrow, but don't assign op to win if it + would turn an integral type into something else. */ + if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p) + continue; } win = op; @@ -4677,25 +4710,55 @@ int_fits_type_p (tree c, tree type) { c = copy_node (c); TREE_TYPE (c) = type; - return !force_fit_type (c, 0); + c = force_fit_type (c, -1, false, false); + return !TREE_OVERFLOW (c); } } +/* Subprogram of following function. Called by walk_tree. + + Return *TP if it is an automatic variable or parameter of the + function passed in as DATA. */ + +static tree +find_var_from_fn (tree *tp, int *walk_subtrees, void *data) +{ + tree fn = (tree) data; + + if (TYPE_P (*tp)) + *walk_subtrees = 0; + + else if (DECL_P (*tp) && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn)) + return *tp; + + return NULL_TREE; +} + /* Returns true if T is, contains, or refers to a type with variable - size. This concept is more general than that of C99 'variably - modified types': in C99, a struct type is never variably modified - because a VLA may not appear as a structure member. However, in - GNU C code like: + size. If FN is nonzero, only return true if a modifier of the type + or position of FN is a variable or parameter inside FN. + + This concept is more general than that of C99 'variably modified types': + in C99, a struct type is never variably modified because a VLA may not + appear as a structure member. However, in GNU C code like: struct S { int i[f()]; }; is valid, and other languages may define similar constructs. */ bool -variably_modified_type_p (tree type) +variably_modified_type_p (tree type, tree fn) { tree t; +/* Test if T is either variable (if FN is zero) or an expression containing + a variable in FN. */ +#define RETURN_TRUE_IF_VAR(T) \ + do { tree _t = (T); \ + if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \ + && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ + return true; } while (0) + if (type == error_mark_node) return false; @@ -4704,9 +4767,8 @@ variably_modified_type_p (tree type) We do not yet have a representation of the C99 '[*]' syntax. When a representation is chosen, this function should be modified to test for that case as well. */ - t = TYPE_SIZE (type); - if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST) - return true; + RETURN_TRUE_IF_VAR (TYPE_SIZE (type)); + RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type)); switch (TREE_CODE (type)) { @@ -4715,7 +4777,7 @@ variably_modified_type_p (tree type) case ARRAY_TYPE: case SET_TYPE: case VECTOR_TYPE: - if (variably_modified_type_p (TREE_TYPE (type))) + if (variably_modified_type_p (TREE_TYPE (type), fn)) return true; break; @@ -4723,13 +4785,13 @@ variably_modified_type_p (tree type) case METHOD_TYPE: /* If TYPE is a function type, it is variably modified if any of the parameters or the return type are variably modified. */ - if (variably_modified_type_p (TREE_TYPE (type))) + if (variably_modified_type_p (TREE_TYPE (type), fn)) return true; for (t = TYPE_ARG_TYPES (type); t && t != void_list_node; t = TREE_CHAIN (t)) - if (variably_modified_type_p (TREE_VALUE (t))) + if (variably_modified_type_p (TREE_VALUE (t), fn)) return true; break; @@ -4740,13 +4802,8 @@ variably_modified_type_p (tree type) case CHAR_TYPE: /* Scalar types are variably modified if their end points aren't constant. */ - t = TYPE_MIN_VALUE (type); - if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST) - return true; - - t = TYPE_MAX_VALUE (type); - if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST) - return true; + RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type)); + RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type)); break; case RECORD_TYPE: @@ -4759,14 +4816,12 @@ variably_modified_type_p (tree type) for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t)) if (TREE_CODE (t) == FIELD_DECL) { - tree t1 = DECL_FIELD_OFFSET (t); - - if (t1 && t1 != error_mark_node && TREE_CODE (t1) != INTEGER_CST) - return true; + RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t)); + RETURN_TRUE_IF_VAR (DECL_SIZE (t)); + RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t)); - t1 = DECL_SIZE (t); - if (t1 && t1 != error_mark_node && TREE_CODE (t1) != INTEGER_CST) - return true; + if (TREE_CODE (type) == QUAL_UNION_TYPE) + RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t)); } break; @@ -4776,7 +4831,9 @@ variably_modified_type_p (tree type) /* The current language may have other cases to check, but in general, all other types are not variably modified. */ - return lang_hooks.tree_inlining.var_mod_type_p (type); + return lang_hooks.tree_inlining.var_mod_type_p (type, fn); + +#undef RETURN_TRUE_IF_VAR } /* Given a DECL or TYPE, return the scope in which it was declared, or @@ -4843,16 +4900,16 @@ decl_type_context (tree decl) case UNION_TYPE: case QUAL_UNION_TYPE: return context; - + case TYPE_DECL: case FUNCTION_DECL: context = DECL_CONTEXT (context); break; - + case BLOCK: context = BLOCK_SUPERCONTEXT (context); break; - + default: abort (); } @@ -4891,7 +4948,7 @@ get_callee_fndecl (tree call) if (TREE_CODE (addr) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL) return TREE_OPERAND (addr, 0); - + /* We couldn't figure out what was being called. Maybe the front end has some idea. */ return lang_hooks.lang_get_callee_fndecl (call); @@ -4943,11 +5000,11 @@ crc32_string (unsigned chksum, const char *string) { unsigned value = *string << 24; unsigned ix; - + for (ix = 8; ix--; value <<= 1) { unsigned feedback; - + feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0; chksum <<= 1; chksum ^= feedback; @@ -5162,7 +5219,7 @@ tree_check_failed (const tree node, const char *file, length += strlen (tree_code_name[code]); } va_end (args); - + internal_error ("tree check: expected %s, have %s in %s, at %s:%d", buffer, tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); @@ -5199,7 +5256,7 @@ tree_not_check_failed (const tree node, const char *file, length += strlen (tree_code_name[code]); } va_end (args); - + internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d", buffer, tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); @@ -5256,18 +5313,23 @@ tree_operand_check_failed (int idx, enum tree_code code, const char *file, } #endif /* ENABLE_TREE_CHECKING */ -/* For a new vector type node T, build the information necessary for - debugging output. */ +/* Create a new vector type node holding SUBPARTS units of type INNERTYPE, + and mapped to the machine mode MODE. Initialize its fields and build + the information necessary for debugging output. */ -static void -finish_vector_type (tree t) +static tree +make_vector_type (tree innertype, int nunits, enum machine_mode mode) { + tree t = make_node (VECTOR_TYPE); + + TREE_TYPE (t) = innertype; + TYPE_VECTOR_SUBPARTS (t) = nunits; + TYPE_MODE (t) = mode; layout_type (t); { - tree index = build_int_2 (TYPE_VECTOR_SUBPARTS (t) - 1, 0); - tree array = build_array_type (TREE_TYPE (t), - build_index_type (index)); + tree index = build_int_cst (NULL_TREE, nunits - 1, 0); + tree array = build_array_type (innertype, build_index_type (index)); tree rt = make_node (RECORD_TYPE); TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array); @@ -5280,6 +5342,8 @@ finish_vector_type (tree t) numbers equal. */ TYPE_UID (rt) = TYPE_UID (t); } + + return t; } static tree @@ -5308,12 +5372,12 @@ make_or_reuse_type (unsigned size, int unsignedp) this function to select one of the types as sizetype. */ void -build_common_tree_nodes (int signed_char) +build_common_tree_nodes (bool signed_char, bool signed_sizetype) { error_mark_node = make_node (ERROR_MARK); TREE_TYPE (error_mark_node) = error_mark_node; - initialize_sizetypes (); + initialize_sizetypes (signed_sizetype); /* Define both `signed char' and `unsigned char'. */ signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); @@ -5341,8 +5405,7 @@ build_common_tree_nodes (int signed_char) boolean_type_node before calling build_common_tree_nodes_2. */ boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); - TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0); - TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node; + TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1, 0); TYPE_PRECISION (boolean_type_node) = 1; /* Fill in the rest of the sized types. Reuse existing type nodes @@ -5358,7 +5421,7 @@ build_common_tree_nodes (int signed_char) unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1); unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1); unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1); - + access_public_node = get_identifier ("public"); access_protected_node = get_identifier ("protected"); access_private_node = get_identifier ("private"); @@ -5371,9 +5434,9 @@ void build_common_tree_nodes_2 (int short_double) { /* Define these next since types below may used them. */ - integer_zero_node = build_int_2 (0, 0); - integer_one_node = build_int_2 (1, 0); - integer_minus_one_node = build_int_2 (-1, -1); + integer_zero_node = build_int_cst (NULL_TREE, 0, 0); + integer_one_node = build_int_cst (NULL_TREE, 1, 0); + integer_minus_one_node = build_int_cst (NULL_TREE, -1, -1); size_zero_node = size_int (0); size_one_node = size_int (1); @@ -5392,8 +5455,8 @@ build_common_tree_nodes_2 (int short_double) TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; TYPE_USER_ALIGN (void_type_node) = 0; - null_pointer_node = build_int_2 (0, 0); - TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); + null_pointer_node = build_int_cst (build_pointer_type (void_type_node), + 0, 0); layout_type (TREE_TYPE (null_pointer_node)); ptr_type_node = build_pointer_type (void_type_node); @@ -5446,7 +5509,7 @@ build_common_tree_nodes_2 (int short_double) don't copy record types and let c_common_nodes_and_builtins() declare the type to be __builtin_va_list. */ if (TREE_CODE (t) != RECORD_TYPE) - t = build_type_copy (t); + t = build_variant_type_copy (t); va_list_type_node = t; } @@ -5486,7 +5549,7 @@ reconstruct_complex_type (tree type, tree bottom) { inner = reconstruct_complex_type (TREE_TYPE (type), bottom); outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type), - inner, + inner, TYPE_ARG_TYPES (type)); } else @@ -5498,36 +5561,39 @@ reconstruct_complex_type (tree type, tree bottom) return outer; } -/* Returns a vector tree node given a vector mode and inner type. */ +/* Returns a vector tree node given a mode (integer, vector, or BLKmode) and + the inner type. */ tree build_vector_type_for_mode (tree innertype, enum machine_mode mode) { - tree t; - t = make_node (VECTOR_TYPE); - TREE_TYPE (t) = innertype; - TYPE_MODE (t) = mode; - finish_vector_type (t); - return t; -} + int nunits; -/* Similarly, but takes inner type and units. */ + if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT + || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) + nunits = GET_MODE_NUNITS (mode); -tree -build_vector_type (tree innertype, int nunits) -{ - enum machine_mode innermode = TYPE_MODE (innertype); - enum machine_mode mode; + else if (GET_MODE_CLASS (mode) == MODE_INT) + { + /* Check that there are no leftover bits. */ + if (GET_MODE_BITSIZE (mode) % TREE_INT_CST_LOW (TYPE_SIZE (innertype))) + abort (); - if (GET_MODE_CLASS (innermode) == MODE_FLOAT) - mode = MIN_MODE_VECTOR_FLOAT; + nunits = GET_MODE_BITSIZE (mode) + / TREE_INT_CST_LOW (TYPE_SIZE (innertype)); + } else - mode = MIN_MODE_VECTOR_INT; + abort (); - for (; mode != VOIDmode ; mode = GET_MODE_WIDER_MODE (mode)) - if (GET_MODE_NUNITS (mode) == nunits && GET_MODE_INNER (mode) == innermode) - return build_vector_type_for_mode (innertype, mode); + return make_vector_type (innertype, nunits, mode); +} - return NULL_TREE; +/* Similarly, but takes the inner type and number of units, which must be + a power of two. */ + +tree +build_vector_type (tree innertype, int nunits) +{ + return make_vector_type (innertype, nunits, VOIDmode); } /* Given an initializer INIT, return TRUE if INIT is zero or some @@ -5601,19 +5667,158 @@ build_empty_stmt (void) } +/* Returns true if it is possible to prove that the index of + an array access REF (an ARRAY_REF expression) falls into the + array bounds. */ + +bool +in_array_bounds_p (tree ref) +{ + tree idx = TREE_OPERAND (ref, 1); + tree min, max; + + if (TREE_CODE (idx) != INTEGER_CST) + return false; + + min = array_ref_low_bound (ref); + max = array_ref_up_bound (ref); + if (!min + || !max + || TREE_CODE (min) != INTEGER_CST + || TREE_CODE (max) != INTEGER_CST) + return false; + + if (tree_int_cst_lt (idx, min) + || tree_int_cst_lt (max, idx)) + return false; + + return true; +} + +/* Return true if T (assumed to be a DECL) is a global variable. */ + +bool +is_global_var (tree t) +{ + return (TREE_STATIC (t) || DECL_EXTERNAL (t)); +} + /* Return true if T (assumed to be a DECL) must be assigned a memory location. */ bool needs_to_live_in_memory (tree t) { - return (DECL_NEEDS_TO_LIVE_IN_MEMORY_INTERNAL (t) - || TREE_STATIC (t) - || DECL_EXTERNAL (t) - || DECL_NONLOCAL (t) + return (TREE_ADDRESSABLE (t) + || is_global_var (t) || (TREE_CODE (t) == RESULT_DECL - && aggregate_value_p (t, current_function_decl)) - || decl_function_context (t) != current_function_decl); + && aggregate_value_p (t, current_function_decl))); +} + +/* There are situations in which a language considers record types + compatible which have different field lists. Decide if two fields + are compatible. It is assumed that the parent records are compatible. */ + +bool +fields_compatible_p (tree f1, tree f2) +{ + if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1), + DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST)) + return false; + + if (!operand_equal_p (DECL_FIELD_OFFSET (f1), + DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST)) + return false; + + if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2))) + return false; + + return true; +} + +/* Locate within RECORD a field that is compatible with ORIG_FIELD. */ + +tree +find_compatible_field (tree record, tree orig_field) +{ + tree f; + + for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL + && fields_compatible_p (f, orig_field)) + return f; + + /* ??? Why isn't this on the main fields list? */ + f = TYPE_VFIELD (record); + if (f && TREE_CODE (f) == FIELD_DECL + && fields_compatible_p (f, orig_field)) + return f; + + /* ??? We should abort here, but Java appears to do Bad Things + with inherited fields. */ + return orig_field; +} + +/* Return value of a constant X. */ + +HOST_WIDE_INT +int_cst_value (tree x) +{ + unsigned bits = TYPE_PRECISION (TREE_TYPE (x)); + unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x); + bool negative = ((val >> (bits - 1)) & 1) != 0; + + if (bits > HOST_BITS_PER_WIDE_INT) + abort (); + + if (negative) + val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1; + else + val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1); + + return val; +} + +/* Returns the greatest common divisor of A and B, which must be + INTEGER_CSTs. */ + +tree +tree_fold_gcd (tree a, tree b) +{ + tree a_mod_b; + tree type = TREE_TYPE (a); + +#if defined ENABLE_CHECKING + if (TREE_CODE (a) != INTEGER_CST + || TREE_CODE (b) != INTEGER_CST) + abort (); +#endif + + if (integer_zerop (a)) + return b; + + if (integer_zerop (b)) + return a; + + if (tree_int_cst_sgn (a) == -1) + a = fold (build2 (MULT_EXPR, type, a, + convert (type, integer_minus_one_node))); + + if (tree_int_cst_sgn (b) == -1) + b = fold (build2 (MULT_EXPR, type, b, + convert (type, integer_minus_one_node))); + + while (1) + { + a_mod_b = fold (build2 (CEIL_MOD_EXPR, type, a, b)); + + if (!TREE_INT_CST_LOW (a_mod_b) + && !TREE_INT_CST_HIGH (a_mod_b)) + return b; + + a = b; + b = a_mod_b; + } } #include "gt-tree.h"