diff options
author | Greg McGary <greg@mcgary.org> | 2000-09-06 18:20:59 +0000 |
---|---|---|
committer | Greg McGary <greg@mcgary.org> | 2000-09-06 18:20:59 +0000 |
commit | 34801b4b9e3077963610a3ab89d5f686d6450d81 (patch) | |
tree | e66d76982e312f1c5dc6564696b5a060c6a9a18b | |
parent | cf2fdda9e756ebc90e199eedfe04e3b34093337b (diff) |
Assorted cleanups
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/bounded-pointers-branch@36203 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/builtins.c | 20 | ||||
-rw-r--r-- | gcc/c-common.c | 4 | ||||
-rw-r--r-- | gcc/c-decl.c | 22 | ||||
-rw-r--r-- | gcc/c-parse.in | 8 | ||||
-rw-r--r-- | gcc/c-tree.h | 5 | ||||
-rw-r--r-- | gcc/c-typeck.c | 161 | ||||
-rw-r--r-- | gcc/config/mips/mips-protos.h | 3 | ||||
-rw-r--r-- | gcc/config/mips/mips.c | 118 | ||||
-rw-r--r-- | gcc/config/mips/mips.h | 3 | ||||
-rw-r--r-- | gcc/config/mips/mips.md | 20 | ||||
-rw-r--r-- | gcc/convert.c | 4 | ||||
-rw-r--r-- | gcc/cp/parse.y | 6 | ||||
-rw-r--r-- | gcc/expr.c | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 6 | ||||
-rw-r--r-- | gcc/output.h | 8 | ||||
-rw-r--r-- | gcc/stor-layout.c | 2 | ||||
-rw-r--r-- | gcc/tree.c | 51 | ||||
-rw-r--r-- | gcc/tree.h | 54 | ||||
-rw-r--r-- | gcc/varasm.c | 2 |
19 files changed, 263 insertions, 240 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index bdf793c08d8..cadf591970e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1167,7 +1167,7 @@ expand_builtin_constant_p (exp) false-positive for the test that immediately follows. */ if (TREE_CODE (arg) == CONSTRUCTOR && TREE_BOUNDED (arg)) { - arg = build_bounded_ptr_value_ref (arg); + arg = build_bounded_ptr_field_ref (arg, 0); STRIP_NOPS (arg); } @@ -1357,7 +1357,7 @@ expand_builtin_strlen (exp, target, mode) if (len != 0) return expand_expr (len, target, mode, EXPAND_MEMORY_USE_BAD); - /* GKM FIXME: check if length goes beyond extent of string. */ + /* GKM FIXME: check if length goes beyond high_bound of string. */ /* If SRC is not a pointer type, don't do this operation inline. */ if (align == 0) return 0; @@ -1444,9 +1444,9 @@ bounded_ptr_dest (dest, dest_addr, target) rtx dest_addr; rtx target; { - rtx low_bound_rtx = expand_expr (build_low_bound_ref (dest), + rtx low_bound_rtx = expand_expr (build_bounded_ptr_field_ref (dest, 1), NULL_RTX, Pmode, 0); - rtx high_bound_rtx = expand_expr (build_high_bound_ref (dest), + rtx high_bound_rtx = expand_expr (build_bounded_ptr_field_ref (dest, 2), NULL_RTX, Pmode, 0); if (!target) target = assign_temp (TREE_TYPE (dest), 1, 0, 0); @@ -1564,7 +1564,7 @@ expand_builtin_strcpy (exp, target) if (TREE_BOUNDED (src)) /* Don't check bounds here. Do it in expand_builtin_memcpy. */ - src = build_bounded_ptr_value_ref (src); + src = build_bounded_ptr_field_ref (src, 0); len = c_strlen (src); if (len == 0) return 0; @@ -1830,14 +1830,14 @@ expand_builtin_strcmp (exp, target) len = c_strlen (arg1); if (len) len = size_binop (PLUS_EXPR, ssize_int (1), len); - /* GKM FIXME: check if length goes beyond extent of string. */ + /* GKM FIXME: check if length goes beyond high_bound of string. */ if (TREE_BOUNDED (arg2)) arg2 = build_bounded_ptr_check (arg2, NULL_TREE); len2 = c_strlen (arg2); if (len2) len2 = size_binop (PLUS_EXPR, ssize_int (1), len2); - /* GKM FIXME: check if length goes beyond extent of string. */ + /* GKM FIXME: check if length goes beyond high_bound of string. */ /* If we don't have a constant length for the first, use the length of the second, if we know it. We don't require a constant for @@ -2387,7 +2387,7 @@ expand_builtin_alloca (exp, target) if (TREE_BOUNDED (exp)) { - TREE_TYPE (exp) = TYPE_BOUNDED_SUBTYPE (TREE_TYPE (exp)); + TREE_TYPE (exp) = TYPE_UNBOUNDED_TYPE (TREE_TYPE (exp)); TREE_BOUNDED (exp) = 0; if (TREE_SIDE_EFFECTS (arg)) TREE_VALUE (arglist) = arg = save_expr (arg); @@ -2557,9 +2557,9 @@ expand_builtin (exp, target, subtarget, mode, ignore) __builtin_apply_args in bounded-pointer variables, we must strip away the bounds. */ if (TREE_BOUNDED (func)) - func = build_bounded_ptr_value_ref (func); + func = build_bounded_ptr_field_ref (func, 0); if (TREE_BOUNDED (args)) - args = build_bounded_ptr_value_ref (args); + args = build_bounded_ptr_field_ref (args, 0); if (! POINTER_TYPE_P (TREE_TYPE (func)) || TREE_CODE (TREE_TYPE (args)) != POINTER_TYPE diff --git a/gcc/c-common.c b/gcc/c-common.c index b7dfd69e924..4f4cf9aa398 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1894,7 +1894,7 @@ check_format_info (info, params) while (TREE_CODE (format_tree) == NOP_EXPR) format_tree = TREE_OPERAND (format_tree, 0); if (TREE_BOUNDED (format_tree)) - format_tree = build_bounded_ptr_value_ref (format_tree); + format_tree = build_bounded_ptr_field_ref (format_tree, 0); while (TREE_CODE (format_tree) == NOP_EXPR) format_tree = TREE_OPERAND (format_tree, 0); @@ -3920,7 +3920,7 @@ lang_get_alias_set (t) the pointed-to types. This issue has been reported to the C++ committee. */ if (BOUNDED_INDIRECT_TYPE_P (t)) - t = TYPE_BOUNDED_SUBTYPE (t); + t = TYPE_UNBOUNDED_TYPE (t); t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t)); t1 = ((TREE_CODE (t) == POINTER_TYPE) ? build_pointer_type (t1) : build_reference_type (t1)); diff --git a/gcc/c-decl.c b/gcc/c-decl.c index ff8e02c11eb..acda709fe3a 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1496,21 +1496,6 @@ duplicate_decls (newdecl, olddecl, different_binding_level) else if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl)) { - if (!types_match - && TYPE_BOUNDED (oldtype) != TYPE_BOUNDED (newtype) - && comptypes_logically (newtype, oldtype)) - { - /* Newdecl and olddecl were parsed with different values - of default_pointer_boundedness. */ - /* GKM FIXME: we can lose arg types if the newdecl isn't - a prototype. It might work better to convert the - boundedness of olddecl's arg types. */ - TREE_TYPE (olddecl) = newtype; - if (!comptypes_physically (newtype, oldtype)) - remake_function_rtl (olddecl); - types_match = 1; - } - /* A function declaration for a built-in function. */ if (!TREE_PUBLIC (newdecl)) { @@ -3102,9 +3087,9 @@ init_decl_processing () boolean_true_node = integer_one_node; boolean_false_node = integer_zero_node; - string_type_node = build_default_pointer_type (char_type_node); + string_type_node = build_default_ptr_type (char_type_node); const_string_type_node - = build_default_pointer_type (build_qualified_type (char_type_node, + = build_default_ptr_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); /* Make a type to be the domain of a few array types @@ -4776,7 +4761,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, asmspec) { /* Force pointers to va_list arrays to be unbounded. */ enum tree_code code = ((TYPE_POINTER_DEPTH (type) == VA_LIST_POINTER_DEPTH) - ? POINTER_TYPE : VOID_TYPE); + ? POINTER_TYPE + : default_pointer_type_code (TREE_TYPE (type))); type = TREE_TYPE (type); if (type_quals) /* Transfer const-ness of array into that of type pointed to. */ diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 9e66198aadc..6e36be9dfa6 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -524,11 +524,11 @@ unary_expr: | IMAGPART cast_expr %prec UNARY { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); } | PTR_VALUE cast_expr %prec UNARY - { $$ = build_bounded_ptr_value_ref (default_conversion ($2)); } + { $$ = build_bounded_ptr_field_ref (default_conversion ($2), 0); } | PTR_LOW_BOUND cast_expr %prec UNARY - { $$ = build_low_bound_ref (default_conversion ($2)); } + { $$ = build_bounded_ptr_field_ref (default_conversion ($2), 1); } | PTR_HIGH_BOUND cast_expr %prec UNARY - { $$ = build_high_bound_ref (default_conversion ($2)); } + { $$ = build_bounded_ptr_field_ref (default_conversion ($2), 2); } | VA_ARG '(' expr_no_commas ',' typename ')' { $$ = build_va_arg ($3, groktypename ($5)); } ; @@ -1972,7 +1972,7 @@ stmt: stmt_count++; emit_line_note ($<filename>-1, $<lineno>0); if (TREE_BOUNDED ($3)) - $3 = build_bounded_ptr_value_ref ($3); + $3 = build_bounded_ptr_field_ref ($3, 0); expand_computed_goto (convert (unbounded_ptr_type_node, $3)); } | ';' ; diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 79265d5275e..2ebc1dd29ea 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -222,10 +222,7 @@ extern tree xref_tag PARAMS ((enum tree_code, tree)); /* in c-typeck.c */ extern tree require_complete_type PARAMS ((tree)); extern void incomplete_type_error PARAMS ((tree, tree)); -extern int comptypes_how PARAMS ((tree, tree, int)); -#define comptypes_logically(a, b) comptypes_how ((a), (b), 1) -#define comptypes_physically(a, b) comptypes_how ((a), (b), 0) -#define comptypes(a, b) comptypes_physically (a, b) +extern int comptypes PARAMS ((tree, tree)); extern tree c_sizeof PARAMS ((tree)); extern tree c_sizeof_nowarn PARAMS ((tree)); extern tree c_size_in_bytes PARAMS ((tree)); diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 60cbe694531..3771a8a8296 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -50,12 +50,9 @@ static int missing_braces_mentioned; /* 1 if we explained undeclared var errors. */ static int undeclared_variable_notice; -static int comp_target_types_how PARAMS ((tree, tree, int)); -#define comp_target_types(a, b) comp_target_types_physically ((a), (b)) -#define comp_target_types_physically(a, b) comp_target_types_how ((a), (b), 0) -#define comp_target_types_logically(a, b) comp_target_types_how ((a), (b), 1) -static int function_types_compatible_p PARAMS ((tree, tree, int)); -static int type_lists_compatible_p PARAMS ((tree, tree, int)); +static int comp_target_types PARAMS ((tree, tree)); +static int function_types_compatible_p PARAMS ((tree, tree)); +static int type_lists_compatible_p PARAMS ((tree, tree)); static tree decl_constant_value PARAMS ((tree)); static tree lookup_field PARAMS ((tree, tree, tree *)); static tree convert_arguments PARAMS ((tree, tree, tree, tree, tree)); @@ -427,9 +424,8 @@ common_type (t1, t2) pointer types. */ int -comptypes_how (type1, type2, logicalp) +comptypes (type1, type2) tree type1, type2; - int logicalp; { register tree t1 = type1; register tree t2 = type2; @@ -464,9 +460,7 @@ comptypes_how (type1, type2, logicalp) /* Different classes of types can't be compatible. */ - if (TREE_CODE (t1) != TREE_CODE (t2) - && !(logicalp && MAYBE_BOUNDED_POINTER_TYPE_P (t1) - && MAYBE_BOUNDED_POINTER_TYPE_P (t2))) + if (TREE_CODE (t1) != TREE_CODE (t2)) return 0; /* Qualifiers other than BOUNDED must match. */ @@ -478,16 +472,8 @@ comptypes_how (type1, type2, logicalp) definition. Note that we already checked for equality of the type qualifiers (just above). */ - if (logicalp) - { - if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)) - return 1; - } - else - { - if (TYPE_MAIN_VARIANTS_PHYSICALLY_EQUAL_P (t1, t2)) - return 1; - } + if (TYPE_MAIN_VARIANTS_PHYSICALLY_EQUAL_P (t1, t2)) + return 1; #ifndef COMP_TYPE_ATTRIBUTES #define COMP_TYPE_ATTRIBUTES(t1,t2) 1 @@ -508,7 +494,7 @@ comptypes_how (type1, type2, logicalp) break; case FUNCTION_TYPE: - val = function_types_compatible_p (t1, t2, logicalp); + val = function_types_compatible_p (t1, t2); break; case ARRAY_TYPE: @@ -539,8 +525,8 @@ comptypes_how (type1, type2, logicalp) case RECORD_TYPE: if (BOUNDED_POINTER_TYPE_P (t1) && BOUNDED_POINTER_TYPE_P (t2)) - return comptypes (TYPE_BOUNDED_SUBTYPE (t1), - TYPE_BOUNDED_SUBTYPE (t2)); + return comptypes (TYPE_UNBOUNDED_TYPE (t1), + TYPE_UNBOUNDED_TYPE (t2)); if (maybe_objc_comptypes (t1, t2, 0) == 1) val = 1; break; @@ -555,9 +541,8 @@ comptypes_how (type1, type2, logicalp) ignoring their qualifiers. */ static int -comp_target_types_how (ttl, ttr, logicalp) +comp_target_types (ttl, ttr) tree ttl, ttr; - int logicalp; { int val; @@ -565,8 +550,8 @@ comp_target_types_how (ttl, ttr, logicalp) if ((val = maybe_objc_comptypes (ttl, ttr, 1)) >= 0) return val; - val = comptypes_how (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)), - TYPE_MAIN_VARIANT (TREE_TYPE (ttr)), logicalp); + val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)), + TYPE_MAIN_VARIANT (TREE_TYPE (ttr))); if (val == 2 && pedantic) pedwarn ("types are not quite compatible"); @@ -583,9 +568,8 @@ comp_target_types_how (ttl, ttr, logicalp) Otherwise, the argument types must match. */ static int -function_types_compatible_p (f1, f2, logicalp) +function_types_compatible_p (f1, f2) tree f1, f2; - int logicalp; { tree args1, args2; /* 1 if no need for warning yet, 2 if warning cause has been seen. */ @@ -593,7 +577,7 @@ function_types_compatible_p (f1, f2, logicalp) int val1; if (!(TREE_TYPE (f1) == TREE_TYPE (f2) - || (val = comptypes_how (TREE_TYPE (f1), TREE_TYPE (f2), logicalp)))) + || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2))))) return 0; args1 = TYPE_ARG_TYPES (f1); @@ -610,7 +594,7 @@ function_types_compatible_p (f1, f2, logicalp) compare that with the other type's arglist. If they don't match, ask for a warning (but no error). */ if (TYPE_ACTUAL_ARG_TYPES (f1) - && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), logicalp)) + && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1))) val = 2; return val; } @@ -619,13 +603,13 @@ function_types_compatible_p (f1, f2, logicalp) if (!self_promoting_args_p (args1)) return 0; if (TYPE_ACTUAL_ARG_TYPES (f2) - && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), logicalp)) + && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2))) val = 2; return val; } /* Both types have argument lists: compare them and propagate results. */ - val1 = type_lists_compatible_p (args1, args2, logicalp); + val1 = type_lists_compatible_p (args1, args2); return val1 != 1 ? val1 : val; } @@ -634,9 +618,8 @@ function_types_compatible_p (f1, f2, logicalp) or 2 for compatible with warning. */ static int -type_lists_compatible_p (args1, args2, logicalp) +type_lists_compatible_p (args1, args2) tree args1, args2; - int logicalp; { /* 1 if no need for warning yet, 2 if warning cause has been seen. */ int val = 1; @@ -664,7 +647,7 @@ type_lists_compatible_p (args1, args2, logicalp) if (simple_type_promotes_to (TREE_VALUE (args1)) != NULL_TREE) return 0; } - else if (! (newval = comptypes_how (TREE_VALUE (args1), TREE_VALUE (args2), logicalp))) + else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2)))) { /* Allow wait (union {union wait *u; int *i} *) and wait (union wait *) to be compatible. */ @@ -989,7 +972,7 @@ default_conversion (exp) { tree op0 = TREE_OPERAND (exp, 0); op0 = build_bounded_ptr_constructor (op0); - return convert (build_default_pointer_type (restype), op0); + return convert (build_default_ptr_type (restype), op0); } if (TREE_CODE (exp) == COMPOUND_EXPR) @@ -1028,7 +1011,7 @@ default_conversion (exp) if (!TREE_BOUNDED (addr)) addr = build_bounded_ptr_constructor (addr); } - return convert (build_default_pointer_type (restype), addr); + return convert (build_default_ptr_type (restype), addr); } } return exp; @@ -1239,7 +1222,7 @@ build_bounded_ptr_field_ref (bp, field_number) if (! BOUNDED_POINTER_TYPE_P (TREE_TYPE (bp))) abort (); - subtype = TYPE_BOUNDED_SUBTYPE (TREE_TYPE (bp)); + subtype = TYPE_UNBOUNDED_TYPE (TREE_TYPE (bp)); field = TYPE_FIELDS (TREE_TYPE (bp)); for (i = 0; i < field_number && field; i++) @@ -1276,7 +1259,7 @@ build_bounded_ptr_field_ref (bp, field_number) /* If the underlaying value is an integer type, keep it that way for enclosing arithmetic. */ if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE - && subtype != TYPE_BOUNDED_SUBTYPE (TREE_TYPE (bp))) + && subtype != TYPE_UNBOUNDED_TYPE (TREE_TYPE (bp))) value = convert (subtype, value); return value; } @@ -1295,7 +1278,7 @@ build_bounded_ptr_field_ref (bp, field_number) } -/* This is just like build_bounded_ptr_value_ref except with the +/* This is just like build_bounded_ptr_field_ref except with the side-effect of generating bounds checks. Strip away bounds, check pointer value against low_bound & high_bound, then return a COMPONENT_REF to the pointer value, or return the pointer value @@ -1319,18 +1302,18 @@ build_bounded_ptr_check (bp, length) abort (); if (skip_evaluation || ! flag_bounds_check) - return build_bounded_ptr_value_ref (bp); + return build_bounded_ptr_field_ref (bp, 0); if (TREE_SIDE_EFFECTS (bp) && TREE_CODE (bp) != CONSTRUCTOR) bp = save_expr (bp); - value = build_bounded_ptr_value_ref (bp); + value = build_bounded_ptr_field_ref (bp, 0); /* The type of value might be integer, but since we're not doing arithmetic, coerce it back to pointer. */ if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE) - value = convert (TYPE_BOUNDED_SUBTYPE (TREE_TYPE (bp)), value); - low_bound = build_low_bound_ref (bp); - high_bound = build_high_bound_ref (bp); + value = convert (TYPE_UNBOUNDED_TYPE (TREE_TYPE (bp)), value); + low_bound = build_bounded_ptr_field_ref (bp, 1); + high_bound = build_bounded_ptr_field_ref (bp, 2); if (TREE_CODE (bp) == CONSTRUCTOR) { @@ -1397,7 +1380,7 @@ build_indirect_ref (ptr, errorstring) if (BOUNDED_POINTER_TYPE_P (TREE_TYPE (ptr)) && (TREE_CODE (ptr) == CONSTRUCTOR && (TREE_CODE (TREE_VALUE (CONSTRUCTOR_ELTS (ptr))) == ADDR_EXPR))) - ptr = build_bounded_ptr_value_ref (ptr); + ptr = build_bounded_ptr_field_ref (ptr, 0); pointer = default_conversion (ptr); if (BOUNDED_POINTER_TYPE_P (TREE_TYPE (pointer))) @@ -1561,7 +1544,7 @@ build_array_ref (array, index) /* Index might be a int-casted pointer, so toss its bounds. */ if (TREE_BOUNDED (index)) - index = build_bounded_ptr_value_ref (index); + index = build_bounded_ptr_field_ref (index, 0); { tree ar = default_conversion (array); tree ind = default_conversion (index); @@ -1862,7 +1845,7 @@ convert_arguments (typelist, values, name, fundecl, funtype) || DECL_FUNCTION_CODE (fundecl) == BUILT_IN_VARARGS_START))) /* Silently strip away bounds if arg-type or funtype expects unbounded pointers. */ - val = build_bounded_ptr_value_ref (val); + val = build_bounded_ptr_field_ref (val, 0); /* GKM FIXME: silently add permissive bounds if arg-type or funtype expects bounded pointers? */ @@ -2238,13 +2221,13 @@ build_binary_op (code, orig_op0, orig_op1, convert_p) { if (TREE_CODE (bp0) == BIND_EXPR) bp0 = save_expr (bp0); - op0 = build_bounded_ptr_value_ref (bp0); + op0 = build_bounded_ptr_field_ref (bp0, 0); /* BP constructors shadow scalar-type conversions, so we must take care to restore them. */ if (TREE_CODE (TREE_TYPE (op0)) != POINTER_TYPE) type0 = TREE_TYPE (op0); else if (BOUNDED_POINTER_TYPE_P (type0)) - type0 = TYPE_BOUNDED_SUBTYPE (type0); + type0 = TYPE_UNBOUNDED_TYPE (type0); /* Convert back to scalar type, if op0 was a int-casted pointer */ op0 = convert (type0, op0); } @@ -2263,13 +2246,13 @@ build_binary_op (code, orig_op0, orig_op1, convert_p) { if (TREE_CODE (bp1) == BIND_EXPR) bp1 = save_expr (bp1); - op1 = build_bounded_ptr_value_ref (bp1); + op1 = build_bounded_ptr_field_ref (bp1, 0); /* BP constructors shadow scalar-type conversions, so we must take care to restore them. */ if (TREE_CODE (TREE_TYPE (op1)) != POINTER_TYPE) type1 = TREE_TYPE (op1); else if (BOUNDED_POINTER_TYPE_P (type1)) - type1 = TYPE_BOUNDED_SUBTYPE (type1); + type1 = TYPE_UNBOUNDED_TYPE (type1); /* Convert back to scalar type, if op1 was a int-casted pointer */ op1 = convert (type1, op1); } @@ -3231,7 +3214,7 @@ build_unary_op (code, xarg, noconvert) case TRUTH_NOT_EXPR: if (BOUNDED_POINTER_TYPE_P (TREE_TYPE (arg))) { - arg = build_bounded_ptr_value_ref (arg); + arg = build_bounded_ptr_field_ref (arg, 0); typecode = TREE_CODE (TREE_TYPE (arg)); } if (typecode != INTEGER_TYPE @@ -3274,7 +3257,7 @@ build_unary_op (code, xarg, noconvert) { tree expr, rec, ref; arg = stabilize_reference (arg); - ref = build_bounded_ptr_value_ref (arg); + ref = build_bounded_ptr_field_ref (arg, 0); rec = TREE_OPERAND (ref, 0); while (TREE_CODE (rec) == NOP_EXPR || TREE_CODE (rec) == CONVERT_EXPR) { @@ -3291,11 +3274,11 @@ build_unary_op (code, xarg, noconvert) TREE_OPERAND (ref, 0) = rec; expr = build_unary_op (code, ref, noconvert); val = build (CONSTRUCTOR, argtype, NULL_TREE, - tree_cons (TYPE_BOUNDED_VALUE_FIELD (argtype), expr, - tree_cons (TYPE_LOW_BOUND_FIELD (argtype), - build_low_bound_ref (arg), - tree_cons (TYPE_HIGH_BOUND_FIELD (argtype), - build_high_bound_ref (arg), + tree_cons (BOUNDED_PTR_VALUE_FIELD (argtype), expr, + tree_cons (BOUNDED_PTR_LOW_FIELD (argtype), + build_bounded_ptr_field_ref (arg, 1), + tree_cons (BOUNDED_PTR_HIGH_FIELD (argtype), + build_bounded_ptr_field_ref (arg, 2), NULL_TREE)))); TREE_THIS_VOLATILE (val) = TREE_THIS_VOLATILE (expr); TREE_SIDE_EFFECTS (val) = TREE_SIDE_EFFECTS (expr); @@ -3482,7 +3465,7 @@ build_unary_op (code, xarg, noconvert) case FIX_CEIL_EXPR: if (pedantic) pedwarn ("ISO C forbids the address of a cast expression"); - return convert (build_default_pointer_type (TREE_TYPE (arg)), + return convert (build_default_ptr_type (TREE_TYPE (arg)), build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0)); } @@ -3547,8 +3530,8 @@ build_unary_op (code, xarg, noconvert) /* GKM FIXME: is this test sufficent to identify the final field? */ if (FINAL_FIELD_P (field)) - high_bound = build_high_bound_ref (addr); - addr = build_bounded_ptr_value_ref (addr); + high_bound = build_bounded_ptr_field_ref (addr, 2); + addr = build_bounded_ptr_field_ref (addr, 0); } addr = fold (build (PLUS_EXPR, argtype, @@ -3664,7 +3647,7 @@ build_high_bound (addr) { tree datum = TREE_OPERAND (deep, 0); if (TREE_CODE (datum) == FUNCTION_DECL) - return build_high_bound_ref (permissive_null_bounded_ptr_node); + return build_bounded_ptr_field_ref (null_bounded_ptr_node, 2); if (TREE_CODE (datum) == VAR_DECL && DECL_EXTERNAL (datum) && (! COMPLETE_TYPE_P (TREE_TYPE (datum)) || variable_high_bound_p (TREE_TYPE (datum)))) @@ -3682,13 +3665,6 @@ build_high_bound (addr) abort (); } return build_binary_op (PLUS_EXPR, addr, integer_one_node, 0); -#if 0 - { - ... if (variable_high_bound_p (TREE_TYPE (datum))) - } - warning ("unknown high_bound for bounded pointer"); - return build_high_bound_ref (permissive_null_bounded_ptr_node); -#endif } /* Build a phony VAR_DECL to represent the end address of VAR. @@ -3740,8 +3716,8 @@ build_bounded_ptr_constructor_2 (addr, bounds) || !default_pointer_boundedness) return addr; - low_bound = build_low_bound_ref (bounds); - high_bound = build_high_bound_ref (bounds); + low_bound = build_bounded_ptr_field_ref (bounds, 1); + high_bound = build_bounded_ptr_field_ref (bounds, 2); return build_bounded_ptr_constructor_3 (addr, low_bound, high_bound); } @@ -3766,14 +3742,14 @@ build_bounded_ptr_constructor_3 (addr, low_bound, high_bound) if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) { - low_bound = build_low_bound_ref (strict_null_bounded_ptr_node); - high_bound = build_high_bound_ref (strict_null_bounded_ptr_node); + low_bound = build_bounded_ptr_field_ref (null_bounded_ptr_node, 1); + high_bound = build_bounded_ptr_field_ref (null_bounded_ptr_node, 2); } - value = build_tree_list (TYPE_BOUNDED_VALUE_FIELD (bptype), addr); - low_bound = build_tree_list (TYPE_LOW_BOUND_FIELD (bptype), + value = build_tree_list (BOUNDED_PTR_VALUE_FIELD (bptype), addr); + low_bound = build_tree_list (BOUNDED_PTR_LOW_FIELD (bptype), convert (type, low_bound)); - high_bound = build_tree_list (TYPE_HIGH_BOUND_FIELD (bptype), + high_bound = build_tree_list (BOUNDED_PTR_HIGH_FIELD (bptype), convert (type, high_bound)); result = build (CONSTRUCTOR, bptype, NULL_TREE, @@ -4184,7 +4160,7 @@ build_conditional_expr (ifexp, op1, op2) else { op2 = (BOUNDED_POINTER_TYPE_P (type1) - ? strict_null_bounded_ptr_node : null_unbounded_ptr_node); + ? null_bounded_ptr_node : null_unbounded_ptr_node); #if 0 /* The spec seems to say this is permitted. */ if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE) pedwarn ("ANSI C forbids conditional expr between 0 and function pointer"); @@ -4199,7 +4175,7 @@ build_conditional_expr (ifexp, op1, op2) else { op1 = (BOUNDED_POINTER_TYPE_P (type2) - ? strict_null_bounded_ptr_node : null_unbounded_ptr_node); + ? null_bounded_ptr_node : null_unbounded_ptr_node); #if 0 /* The spec seems to say this is permitted. */ if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE) pedwarn ("ANSI C forbids conditional expr between 0 and function pointer"); @@ -4467,7 +4443,7 @@ build_c_cast (type, expr) { /* GKM FIXME: print better diagnostic message */ warning ("cast to bounded pointer from unbounded type"); - type = TYPE_BOUNDED_SUBTYPE (type); + type = TYPE_UNBOUNDED_TYPE (type); } ovalue = value; @@ -4574,7 +4550,7 @@ build_modify_expr (lhs, modifycode, rhs) if (modifycode != NOP_EXPR && BOUNDED_POINTER_TYPE_P (lhstype)) { bplhs = lhs; - lhs = build_bounded_ptr_value_ref (bplhs); + lhs = build_bounded_ptr_field_ref (bplhs, 0); lhstype = TREE_TYPE (lhs); } newrhs = build_binary_op (modifycode, lhs, rhs, 1); @@ -4809,7 +4785,7 @@ convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum) && integer_zerop (TREE_OPERAND (rhs, 0)))) { rhs = (BOUNDED_POINTER_TYPE_P (rhstype) - ? strict_null_bounded_ptr_node : null_unbounded_ptr_node); + ? null_bounded_ptr_node : null_unbounded_ptr_node); break; } } @@ -4909,16 +4885,13 @@ convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum) errtype, funname, parmnum); } } - else if (comp_target_types_logically (type, rhstype)) - error_for_assignment ("%s between pointer types of different boundedness", - errtype, funname, parmnum); else warn_for_assignment ("%s from incompatible pointer type", errtype, funname, parmnum); /* Strip away bounds here so convert_to_pointer won't complain. */ if (TREE_BOUNDED (rhs) && !BOUNDED_POINTER_TYPE_P (type)) - rhs = build_bounded_ptr_value_ref (rhs); + rhs = build_bounded_ptr_field_ref (rhs, 0); return convert (type, rhs); } else if (MAYBE_BOUNDED_POINTER_TYPE_P (type) && coder == INTEGER_TYPE) @@ -4938,7 +4911,7 @@ convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum) return convert (type, rhs); } return (BOUNDED_POINTER_TYPE_P (type) - ? strict_null_bounded_ptr_node : null_unbounded_ptr_node); + ? null_bounded_ptr_node : null_unbounded_ptr_node); } else if (codel == INTEGER_TYPE && MAYBE_BOUNDED_POINTER_TYPE_P (rhstype)) { @@ -6643,7 +6616,7 @@ output_init_element (value, type, field, pending) if (TREE_CODE (val) == CONVERT_EXPR && BOUNDED_POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (val, 0)))) value = convert (TREE_TYPE (value), - build_bounded_ptr_value_ref (TREE_OPERAND (val, 0))); + build_bounded_ptr_field_ref (TREE_OPERAND (val, 0), 0)); if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE @@ -7069,7 +7042,7 @@ process_init_element (value) if (string_flag) value = build_bounded_ptr_constructor (value); else if (integer_zerop (value)) - value = strict_null_bounded_ptr_node; + value = null_bounded_ptr_node; } /* Accept a string constant to initialize a subarray. */ @@ -7154,7 +7127,7 @@ process_init_element (value) if (string_flag) value = build_bounded_ptr_constructor (value); else if (integer_zerop (value)) - value = strict_null_bounded_ptr_node; + value = null_bounded_ptr_node; } /* Accept a string constant to initialize a subarray. */ @@ -7313,7 +7286,7 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) tree output = TREE_VALUE (tail); if (TREE_BOUNDED (output)) - output = TREE_VALUE (tail) = build_bounded_ptr_value_ref (output); + output = TREE_VALUE (tail) = build_bounded_ptr_field_ref (output, 0); /* We can remove conversions that just change the type, not the mode. */ STRIP_NOPS (output); @@ -7345,7 +7318,7 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) || TREE_CODE (TREE_TYPE (input)) == FUNCTION_TYPE) input = default_conversion (input); if (TREE_BOUNDED (input)) - input = build_bounded_ptr_value_ref (input); + input = build_bounded_ptr_field_ref (input, 0); TREE_VALUE (tail) = input; } diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h index 74149e5abb0..826cd5e1b6a 100644 --- a/gcc/config/mips/mips-protos.h +++ b/gcc/config/mips/mips-protos.h @@ -67,6 +67,7 @@ extern void mips_select_section PARAMS ((tree, int)); extern int arith32_operand PARAMS ((rtx, enum machine_mode)); extern int arith_operand PARAMS ((rtx, enum machine_mode)); extern int cmp_op PARAMS ((rtx, enum machine_mode)); +extern int trap_cmp_op PARAMS ((rtx, enum machine_mode)); extern int const_float_1_operand PARAMS ((rtx, enum machine_mode)); extern void expand_block_move PARAMS ((rtx [])); extern int equality_op PARAMS ((rtx, enum machine_mode)); @@ -77,7 +78,7 @@ extern void init_cumulative_args PARAMS ((CUMULATIVE_ARGS *c, tree, rtx)); #endif /* TREE_CODE */ extern void gen_conditional_branch PARAMS ((rtx[], enum rtx_code)); extern void gen_conditional_move PARAMS ((rtx *)); -extern void mips_gen_conditional_trap PARAMS ((rtx *, enum rtx_code)); +extern void mips_gen_conditional_trap PARAMS ((rtx *)); extern int large_int PARAMS ((rtx, enum machine_mode)); extern void machine_dependent_reorg PARAMS ((rtx)); extern int mips_address_cost PARAMS ((rtx)); diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index 4b336843ac9..860ce956d7b 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -188,8 +188,8 @@ int num_refs[3]; /* registers to check for load delay */ rtx mips_load_reg, mips_load_reg2, mips_load_reg3, mips_load_reg4; -/* Cached operands, and operator to compare for use in set/branch on - condition codes. */ +/* Cached operands, and operator to compare for use in set/branch/trap + on condition codes. */ rtx branch_cmp[2]; /* what type of branch to use */ @@ -964,6 +964,34 @@ cmp_op (op, mode) return GET_RTX_CLASS (GET_CODE (op)) == '<'; } +/* Return nonzero if the code is a relational operation suitable for a + conditional trap instructuion (only EQ, NE, LT, LTU, GE, GEU). + We need this in the insn that expands `trap_if' in order to prevent + combine from erroneously altering the condition. */ + +int +trap_cmp_op (op, mode) + rtx op; + enum machine_mode mode; +{ + if (mode != GET_MODE (op)) + return 0; + + switch (GET_CODE (op)) + { + case EQ: + case NE: + case LT: + case LTU: + case GE: + case GEU: + return 1; + + default: + return 0; + } +} + /* Return nonzero if the operand is either the PC or a label_ref. */ int @@ -2975,25 +3003,26 @@ gen_int_relational (test_code, result, cmp0, cmp1, p_invert) operand[0] is the label to jump to. The comparison operands are saved away by cmp{si,di,sf,df}. */ -static rtx -gen_conditional (test_code, p_invert) +void +gen_conditional_branch (operands, test_code) + rtx operands[]; enum rtx_code test_code; - int *p_invert; { enum cmp_type type = branch_type; rtx cmp0 = branch_cmp[0]; rtx cmp1 = branch_cmp[1]; enum machine_mode mode; rtx reg; + int invert; + rtx label1, label2; - if (p_invert) - *p_invert = 0; switch (type) { case CMP_SI: case CMP_DI: mode = type == CMP_SI ? SImode : DImode; - reg = gen_int_relational (test_code, NULL_RTX, cmp0, cmp1, p_invert); + invert = 0; + reg = gen_int_relational (test_code, NULL_RTX, cmp0, cmp1, &invert); if (reg) { @@ -3027,27 +3056,18 @@ gen_conditional (test_code, p_invert) mode = CCmode; cmp0 = reg; cmp1 = const0_rtx; + invert = 0; break; default: abort_with_insn (gen_rtx (test_code, VOIDmode, cmp0, cmp1), "bad test"); } - return gen_rtx (test_code, mode, cmp0, cmp1); -} - -void -gen_conditional_branch (operands, test_code) - rtx operands[]; - enum rtx_code test_code; -{ - int invert; - rtx cond_rtx = gen_conditional (test_code, &invert); - rtx label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]); - rtx label2 = pc_rtx; - /* Generate the branch. */ + label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]); + label2 = pc_rtx; + if (invert) { label2 = label1; @@ -3055,22 +3075,12 @@ gen_conditional_branch (operands, test_code) } emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, - gen_rtx_IF_THEN_ELSE (VOIDmode, cond_rtx, + gen_rtx_IF_THEN_ELSE (VOIDmode, + gen_rtx (test_code, mode, + cmp0, cmp1), label1, label2))); } -/* Emit the common code for conditional traps. OPERANDS is the array - of operands passed to the conditional_trap define_expand. */ - -void -mips_gen_conditional_trap (operands, test_code) - rtx operands[]; - enum rtx_code test_code; -{ - emit_insn (gen_rtx_TRAP_IF (VOIDmode, gen_conditional (test_code, (int *) 0), - operands[1])); -} - /* Emit the common code for conditional moves. OPERANDS is the array of operands passed to the conditional move defined_expand. */ @@ -3157,6 +3167,46 @@ gen_conditional_move (operands) CONST0_RTX (SImode)), operands[2], operands[3]))); } + +/* Emit the common code for conditional moves. OPERANDS is the array + of operands passed to the conditional move defined_expand. */ + +void +mips_gen_conditional_trap (operands) + rtx operands[]; +{ + rtx op0, op1; + enum rtx_code cmp_code = GET_CODE (operands[0]); + enum machine_mode mode = GET_MODE (branch_cmp[0]); + + /* MIPS conditional trap machine instructions don't have GT or LE + flavors, so we must invert the comparison and convert to LT and + GE, respectively. */ + switch (cmp_code) + { + case GT: cmp_code = LT; break; + case LE: cmp_code = GE; break; + case GTU: cmp_code = LTU; break; + case LEU: cmp_code = GEU; break; + default: break; + } + if (cmp_code == GET_CODE (operands[0])) + { + op0 = force_reg (mode, branch_cmp[0]); + op1 = branch_cmp[1]; + } + else + { + op0 = force_reg (mode, branch_cmp[1]); + op1 = branch_cmp[0]; + } + if (GET_CODE (op1) == CONST_INT && ! SMALL_INT (op1)) + op1 = force_reg (mode, op1); + + emit_insn (gen_rtx_TRAP_IF (VOIDmode, + gen_rtx (cmp_code, GET_MODE (operands[0]), op0, op1), + operands[1])); +} /* Write a loop to move a constant number of bytes. Generate load/stores as follows: diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index 531af1790e9..98c046b8cea 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -607,6 +607,8 @@ extern void sbss_section PARAMS ((void)); #define ISA_HAS_FP4 (mips_isa == 4 \ ) +/* ISA has conditional trap instructions. */ +#define ISA_HAS_COND_TRAP (mips_isa >= 2) /* CC1_SPEC causes -mips3 and -mips4 to set -mfp64 and -mgp64; -mips1 or @@ -3713,6 +3715,7 @@ while (0) {"equality_op", { EQ, NE }}, \ {"cmp_op", { EQ, NE, GT, GE, GTU, GEU, LT, LE, \ LTU, LEU }}, \ + {"trap_cmp_op", { EQ, NE, GE, GEU, LT, LTU }}, \ {"pc_or_label_operand", { PC, LABEL_REF }}, \ {"call_insn_operand", { CONST_INT, CONST, SYMBOL_REF, REG}}, \ {"move_operand", { CONST_INT, CONST_DOUBLE, CONST, \ diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index beb0b103fce..1e8f35a8422 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -10460,23 +10460,29 @@ ld\\t%2,%1-%S1(%2)\;daddu\\t%2,%2,$31\;j\\t%2" (define_insn "trap" [(trap_if (const_int 1) (const_int 0))] "" - "teq\\t$0,$0") + "* +{ + if (ISA_HAS_COND_TRAP) + return \"teq\\t$0,$0\"; + else + return \"break\"; +}") (define_expand "conditional_trap" [(trap_if (match_operator 0 "cmp_op" [(match_dup 2) (match_dup 3)]) (match_operand 1 "const_int_operand" ""))] - "" + "ISA_HAS_COND_TRAP" " { - mips_gen_conditional_trap (operands, GET_CODE (operands[0])); + mips_gen_conditional_trap (operands); DONE; }") (define_insn "" - [(trap_if (match_operator:SI 0 "cmp_op" - [(match_operand:SI 1 "reg_or_0_operand" "") - (match_operand:SI 2 "reg_or_0_operand" "")]) + [(trap_if (match_operator 0 "trap_cmp_op" + [(match_operand:SI 1 "reg_or_0_operand" "d,d") + (match_operand:SI 2 "general_operand" "d,I")]) (const_int 0))] - "" + "ISA_HAS_COND_TRAP" "t%C0\\t%z1,%z2") diff --git a/gcc/convert.c b/gcc/convert.c index 7b78dc0d27d..61f292123a9 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -65,7 +65,7 @@ convert_to_pointer (type, expr) expr = convert (type_for_size (POINTER_SIZE, 0), expr); if (BOUNDED_POINTER_TYPE_P (type)) { - expr = build1 (CONVERT_EXPR, TYPE_BOUNDED_SUBTYPE (type), expr); + expr = build1 (CONVERT_EXPR, TYPE_UNBOUNDED_TYPE (type), expr); TREE_CONSTANT (expr) = TREE_CONSTANT (TREE_OPERAND (expr, 0)); return build_bounded_ptr_constructor (expr); } @@ -81,7 +81,7 @@ convert_to_pointer (type, expr) return expr; } else - return convert (type, build_bounded_ptr_value_ref (expr)); + return convert (type, build_bounded_ptr_field_ref (expr, 0)); } /* else FALL THROUGH */ diff --git a/gcc/cp/parse.y b/gcc/cp/parse.y index bd6cceb9235..3e4818fcbcc 100644 --- a/gcc/cp/parse.y +++ b/gcc/cp/parse.y @@ -1253,11 +1253,11 @@ unary_expr: { $$ = build_x_unary_op (IMAGPART_EXPR, $2); } | PTR_VALUE cast_expr %prec UNARY { $$ = (TREE_BOUNDED ($2) - ? build_bounded_ptr_value_ref ($2) : $2); } + ? build_bounded_ptr_field_ref ($2, 0) : $2); } | PTR_LOW_BOUND cast_expr %prec UNARY - { $$ = build_low_bound_ref ($2); } + { $$ = build_bounded_ptr_field_ref ($2, 1); } | PTR_HIGH_BOUND cast_expr %prec UNARY - { $$ = build_high_bound_ref ($2); } + { $$ = build_bounded_ptr_field_ref ($2, 2); } | VA_ARG '(' expr_no_commas ',' type_id ')' { $$ = build_x_va_arg ($3, groktypename ($5.t)); check_for_new_type ("__builtin_va_arg", $5); } diff --git a/gcc/expr.c b/gcc/expr.c index 092a84072cd..80d268b5520 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7102,7 +7102,7 @@ expand_expr (exp, target, tmode, modifier) if (BOUNDED_POINTER_TYPE_P (type) && ! TREE_BOUNDED (TREE_OPERAND (exp, 0))) { tree exp0 = TREE_OPERAND (exp, 0); - exp = convert (TYPE_BOUNDED_SUBTYPE (type), exp0); + exp = convert (TYPE_UNBOUNDED_TYPE (type), exp0); if (TREE_CODE (TREE_TYPE (exp0)) == POINTER_TYPE) exp = build_bounded_ptr_constructor (exp); else @@ -7111,7 +7111,7 @@ expand_expr (exp, target, tmode, modifier) (TREE_CODE (TREE_TYPE (exp0)) == INTEGER_TYPE && !integer_zerop (exp0)) ? "integer" : "non-pointer"); - exp = build_bounded_ptr_constructor_2 (exp, strict_null_bounded_ptr_node); + exp = build_bounded_ptr_constructor_2 (exp, null_bounded_ptr_node); } return expand_expr (exp, target, tmode, modifier); } @@ -7122,7 +7122,7 @@ expand_expr (exp, target, tmode, modifier) && TREE_BOUNDED (TREE_OPERAND (exp, 0))) { warning ("discarding pointer bounds in type conversion"); - exp = build_bounded_ptr_value_ref (TREE_OPERAND (exp, 0)); + exp = build_bounded_ptr_field_ref (TREE_OPERAND (exp, 0), 0); exp = convert (type, exp); return expand_expr (exp, target, tmode, modifier); } diff --git a/gcc/fold-const.c b/gcc/fold-const.c index a1b4a664a37..3ed430d037b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5113,11 +5113,11 @@ fold (expr) { if (BOUNDED_POINTER_TYPE_P (TREE_TYPE (a0))) arg0 = convert (TREE_TYPE (arg0), - convert (TYPE_BOUNDED_SUBTYPE (TREE_TYPE (a0)), + convert (TYPE_UNBOUNDED_TYPE (TREE_TYPE (a0)), a0)); if (BOUNDED_POINTER_TYPE_P (TREE_TYPE (a1))) arg1 = convert (TREE_TYPE (arg1), - convert (TYPE_BOUNDED_SUBTYPE (TREE_TYPE (a1)), + convert (TYPE_UNBOUNDED_TYPE (TREE_TYPE (a1)), a1)); return fold (build (MINUS_EXPR, type, arg0, arg1)); } @@ -5238,7 +5238,7 @@ fold (expr) /* Don't fold consecutive conversions from integer to unbounded pointer to bounded pointer. */ if (BOUNDED_INDIRECT_TYPE_P (final_type) - && TYPE_BOUNDED_SUBTYPE (final_type) == inter_type) + && TYPE_UNBOUNDED_TYPE (final_type) == inter_type) return t; } diff --git a/gcc/output.h b/gcc/output.h index 18933eb800b..2511e298469 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -270,10 +270,10 @@ extern void assemble_end_function PARAMS ((tree, const char *)); initial value (that will be done by the caller). */ extern void assemble_variable PARAMS ((tree, int, int, int)); -/* Output a set directive for the extent of a global variable which - can have variable size, i.e., any variable having a type whose - layout terminates with an array type (e.g., a simple array, or a - record or union type with a terminating array member. */ +/* Output a .set directive for the high bound of a global variable + which can have variable size, i.e., any variable having a type + whose layout terminates with an array type (e.g., a simple array, + or a record or union type with a terminating array member. */ extern void assemble_high_bound PARAMS ((tree)); /* Output something to declare an external symbol to the assembler. diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 8d1df35f7c1..5cd387254eb 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -1349,7 +1349,7 @@ layout_type (type) register tree index = TYPE_DOMAIN (type); register tree element = TREE_TYPE (type); - build_default_pointer_type (element); + build_default_ptr_type (element); /* We need to know both bounds in order to compute the size. */ if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index) diff --git a/gcc/tree.c b/gcc/tree.c index 88b23d9a1d7..83b332067be 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4062,7 +4062,7 @@ build_qualified_type (type, type_quals) layout_type (t); } else if (BOUNDED_INDIRECT_TYPE_P (type) && !(type_quals & TYPE_QUAL_BOUNDED)) - t = build_type_copy (TYPE_BOUNDED_SUBTYPE (type)); + t = build_type_copy (TYPE_UNBOUNDED_TYPE (type)); else t = build_type_copy (type); @@ -4700,6 +4700,34 @@ default_pointer_type_code (to_type) } tree +build_pointer_type (to_type) + tree to_type; +{ + return build_pointer_type_2 (POINTER_TYPE, to_type); +} + +tree +build_unbounded_ptr_type (to_type) + tree to_type; +{ + return build_pointer_type_2 (POINTER_TYPE, to_type); +} + +tree +build_bounded_ptr_type (to_type) + tree to_type; +{ + return build_pointer_type_2 (RECORD_TYPE, to_type); +} + +tree +build_default_ptr_type (to_type) + tree to_type; +{ + return build_pointer_type_2 (default_pointer_type_code (to_type), to_type); +} + +tree build_pointer_type_2 (code, to_type) enum tree_code code; tree to_type; @@ -4730,8 +4758,6 @@ build_pointer_type_2 (code, to_type) caller thinks s/he wants. */ if (TREE_CODE (to_type) == FUNCTION_TYPE) code = POINTER_TYPE; - else if (code == VOID_TYPE) - code = default_pointer_type_code (to_type); if (code == RECORD_TYPE) t = build_qualified_type (t, TYPE_QUAL_BOUNDED); @@ -4763,10 +4789,10 @@ build_null_pointer_node (type) tree null = build_int_2 (0, 0); if (BOUNDED_POINTER_TYPE_P (type)) { - tree value = build_tree_list (TYPE_BOUNDED_VALUE_FIELD (type), null); - tree low_bound = build_tree_list (TYPE_LOW_BOUND_FIELD (type), null); - tree high_bound = build_tree_list (TYPE_HIGH_BOUND_FIELD (type), null); - TREE_TYPE (null) = TYPE_BOUNDED_SUBTYPE (type); + tree value = build_tree_list (BOUNDED_PTR_VALUE_FIELD (type), null); + tree low_bound = build_tree_list (BOUNDED_PTR_LOW_FIELD (type), null); + tree high_bound = build_tree_list (BOUNDED_PTR_HIGH_FIELD (type), null); + TREE_TYPE (null) = TYPE_UNBOUNDED_TYPE (type); null = build (CONSTRUCTOR, type, NULL_TREE, chainon (value, chainon (low_bound, high_bound))); TREE_CONSTANT (null) = 1; @@ -4933,7 +4959,7 @@ build_array_type (elt_type, index_type) } /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */ - build_default_pointer_type (elt_type); + build_default_ptr_type (elt_type); /* Allocate the array after the pointer type, in case we free it in type_hash_canon. */ @@ -5969,20 +5995,17 @@ build_common_tree_nodes_2 (short_double) unbounded_ptr_type_node = build_pointer_type_2 (POINTER_TYPE, void_type_node); bounded_ptr_type_node = build_pointer_type_2 (RECORD_TYPE, void_type_node); - ptr_type_node = build_pointer_type_2 (VOID_TYPE, void_type_node); + ptr_type_node = build_default_ptr_type (void_type_node); { tree to_type = build_qualified_type (void_type_node, TYPE_QUAL_CONST); const_bounded_ptr_type_node = build_pointer_type_2 (RECORD_TYPE, to_type); const_unbounded_ptr_type_node = build_pointer_type_2 (POINTER_TYPE, to_type); - const_ptr_type_node = build_pointer_type_2 (VOID_TYPE, to_type); + const_ptr_type_node = build_default_ptr_type (to_type); } null_unbounded_ptr_node = build_null_pointer_node (unbounded_ptr_type_node); - strict_null_bounded_ptr_node = build_null_pointer_node (bounded_ptr_type_node); + null_bounded_ptr_node = build_null_pointer_node (bounded_ptr_type_node); null_pointer_node = build_null_pointer_node (ptr_type_node); - permissive_null_bounded_ptr_node = build_null_pointer_node (bounded_ptr_type_node); - TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (permissive_null_bounded_ptr_node)))) - = build_int_2 (~0, ~0); float_type_node = make_node (REAL_TYPE); TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; diff --git a/gcc/tree.h b/gcc/tree.h index 504031a121c..1a5fbd451bd 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -415,7 +415,7 @@ extern void tree_class_check_failed PARAMS ((const tree, int, #define BOUNDED_POINTER_TYPE_P(TYPE) \ (BOUNDED_INDIRECT_TYPE_P (TYPE) \ - && TREE_CODE (TYPE_BOUNDED_SUBTYPE (TYPE)) == POINTER_TYPE) + && TREE_CODE (TYPE_UNBOUNDED_TYPE (TYPE)) == POINTER_TYPE) /* Nonzero if TYPE represents a bounded reference type. Bounded reference types have two specific uses: (1) When a reference is @@ -431,7 +431,7 @@ extern void tree_class_check_failed PARAMS ((const tree, int, #define BOUNDED_REFERENCE_TYPE_P(TYPE) \ (BOUNDED_INDIRECT_TYPE_P (TYPE) \ - && TREE_CODE (TYPE_BOUNDED_SUBTYPE (TYPE)) == REFERENCE_TYPE) + && TREE_CODE (TYPE_UNBOUNDED_TYPE (TYPE)) == REFERENCE_TYPE) /* Nonzero if TYPE represents a pointer or reference type, either bounded or unbounded. */ @@ -1064,17 +1064,12 @@ struct tree_block of such chains is always the unbounded type. */ /* Access the field decls of a bounded-pointer type. */ -#define TYPE_BOUNDED_VALUE_FIELD(TYPE) TYPE_FIELDS (TYPE) -#define TYPE_LOW_BOUND_FIELD(TYPE) TREE_CHAIN (TYPE_BOUNDED_VALUE_FIELD (TYPE)) -#define TYPE_HIGH_BOUND_FIELD(TYPE) TREE_CHAIN (TYPE_LOW_BOUND_FIELD (TYPE)) +#define BOUNDED_PTR_VALUE_FIELD(TYPE) TYPE_FIELDS (TYPE) +#define BOUNDED_PTR_LOW_FIELD(TYPE) TREE_CHAIN (BOUNDED_PTR_VALUE_FIELD (TYPE)) +#define BOUNDED_PTR_HIGH_FIELD(TYPE) TREE_CHAIN (BOUNDED_PTR_LOW_FIELD (TYPE)) /* Access the simple-pointer subtype of a bounded-pointer type. */ -#define TYPE_BOUNDED_SUBTYPE(TYPE) TREE_TYPE (TYPE_BOUNDED_VALUE_FIELD (TYPE)) - -/* Find the unbounded counterpart to a type, or return TYPE if it is - already unbounded. */ -#define TYPE_UNBOUNDED_VARIANT(TYPE) \ - (BOUNDED_POINTER_TYPE_P (TYPE) ? TYPE_BOUNDED_SUBTYPE (TYPE) : (TYPE)) +#define TYPE_UNBOUNDED_TYPE(TYPE) TREE_TYPE (BOUNDED_PTR_VALUE_FIELD (TYPE)) /* This field comprises two bits, for values in the range 0..3: @@ -1731,8 +1726,7 @@ enum tree_index TI_INTEGER_ONE, TI_NULL_POINTER, TI_NULL_UNBOUNDED_PTR, - TI_STRICT_NULL_BOUNDED_PTR, - TI_PERMISSIVE_NULL_BOUNDED_PTR, + TI_NULL_BOUNDED_PTR, TI_SIZE_ZERO, TI_SIZE_ONE, @@ -1767,9 +1761,7 @@ enum tree_index TI_V2SI_TYPE, TI_MAIN_IDENTIFIER, - - TI_CHECK_BOUNDS_FUNC, - TI_TRAP_FUNC, + TI_TRAP_FUNC_DECL, TI_MAX }; @@ -1803,12 +1795,9 @@ extern tree global_trees[TI_MAX]; #define null_pointer_node global_trees[TI_NULL_POINTER] /* null_unbounded_ptr_node is always unbounded. */ #define null_unbounded_ptr_node global_trees[TI_NULL_UNBOUNDED_PTR] -/* strict_null_bounded_ptr_node has an extent of 0, so that dereferencing +/* null_bounded_ptr_node has an extent of 0, so that dereferencing it is disallowed and raises a bounds violation. */ -#define strict_null_bounded_ptr_node global_trees[TI_STRICT_NULL_BOUNDED_PTR] -/* permissive_null_bounded_ptr_node has bounds of ~0, so that dereferencing - it is permissable and raises no bounds violation. */ -#define permissive_null_bounded_ptr_node global_trees[TI_PERMISSIVE_NULL_BOUNDED_PTR] +#define null_bounded_ptr_node global_trees[TI_NULL_BOUNDED_PTR] #define float_type_node global_trees[TI_FLOAT_TYPE] #define double_type_node global_trees[TI_DOUBLE_TYPE] @@ -1826,7 +1815,7 @@ extern tree global_trees[TI_MAX]; #define ptr_type_node global_trees[TI_PTR_TYPE] /* null_unbounded_ptr_node is always an unbounded pointer type. */ #define unbounded_ptr_type_node global_trees[TI_UNBOUNDED_PTR_TYPE] -/* strict_null_bounded_ptr_node is always a bounded pointer type. */ +/* null_bounded_ptr_node is always a bounded pointer type. */ #define bounded_ptr_type_node global_trees[TI_BOUNDED_PTR_TYPE] /* The C type `const void *'. */ #define const_ptr_type_node global_trees[TI_CONST_PTR_TYPE] @@ -1838,7 +1827,7 @@ extern tree global_trees[TI_MAX]; #define main_identifier_node global_trees[TI_MAIN_IDENTIFIER] #define MAIN_NAME_P(NODE) (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node) -#define trap_fndecl global_trees[TI_TRAP_FUNC] +#define trap_fndecl global_trees[TI_TRAP_FUNC_DECL] #define V4SF_type_node global_trees[TI_V4SF_TYPE] #define V4SI_type_node global_trees[TI_V4SI_TYPE] @@ -1956,18 +1945,13 @@ extern tree build_decl PARAMS ((enum tree_code, tree, tree)); extern tree build_block PARAMS ((tree, tree, tree, tree, tree)); extern tree build_expr_wfl PARAMS ((tree, const char *, int, int)); -/* Construct nodes for use by bounded pointers */ - extern tree build_va_list_type PARAMS ((void)); extern tree build_null_pointer_node PARAMS ((tree)); extern tree build_bounded_ptr_constructor PARAMS ((tree)); extern tree build_bounded_ptr_constructor_2 PARAMS ((tree, tree)); extern tree build_bounded_ptr_constructor_3 PARAMS ((tree, tree, tree)); -extern tree build_bounded_ptr_field_ref PARAMS ((tree, int)); -#define build_bounded_ptr_value_ref(T) build_bounded_ptr_field_ref ((T), 0) -#define build_low_bound_ref(T) build_bounded_ptr_field_ref ((T), 1) -#define build_high_bound_ref(T) build_bounded_ptr_field_ref ((T), 2) -extern tree build_bounded_ptr_check PARAMS ((tree, tree)); +extern tree build_bounded_ptr_field_ref PARAMS ((tree, int)); +extern tree build_bounded_ptr_check PARAMS ((tree, tree)); extern tree make_signed_type PARAMS ((int)); extern tree make_unsigned_type PARAMS ((int)); @@ -1976,13 +1960,11 @@ extern void set_sizetype PARAMS ((tree)); extern tree signed_or_unsigned_type PARAMS ((int, tree)); extern void fixup_unsigned_type PARAMS ((tree)); extern tree build_pointer_type_2 PARAMS ((enum tree_code, tree)); +extern tree build_pointer_type PARAMS ((tree)); +extern tree build_bounded_ptr_type PARAMS ((tree)); +extern tree build_unbounded_ptr_type PARAMS ((tree)); +extern tree build_default_ptr_type PARAMS ((tree)); extern enum tree_code default_pointer_type_code PARAMS ((tree)); -#define build_pointer_type(TYPE) \ - build_pointer_type_2 (POINTER_TYPE, (TYPE)) -#define build_bounded_ptr_pointer_type(TYPE) \ - build_pointer_type_2 (RECORD_TYPE, (TYPE)) -#define build_default_pointer_type(TYPE) \ - build_pointer_type_2 (VOID_TYPE, (TYPE)) extern tree build_reference_type PARAMS ((tree)); extern tree build_index_type PARAMS ((tree)); extern tree build_index_2_type PARAMS ((tree, tree)); diff --git a/gcc/varasm.c b/gcc/varasm.c index eba2f563019..9b0dca725b8 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4901,8 +4901,10 @@ assemble_high_bound (decl) const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (high_bound)); if (TREE_PUBLIC (decl)) assemble_global (name); +#ifdef ASM_DECLARE_HIGH_BOUND if (TREE_PUBLIC (decl) || TREE_USED (decl)) ASM_DECLARE_HIGH_BOUND (asm_out_file, decl); +#endif } /* This determines whether or not we support link-once semantics. */ |