diff options
author | Kenneth Zadeck <zadeck@naturalbridge.com> | 2014-05-06 16:25:05 +0000 |
---|---|---|
committer | Mike Stump <mrs@gcc.gnu.org> | 2014-05-06 16:25:05 +0000 |
commit | 807e902eea17f3132488c256c963823976b2348c (patch) | |
tree | e5e1af94eb1502ba893bd6ce4a11f68877ff62a9 /gcc/c-family | |
parent | 6122336c832dc4dfedc49279549caddce86306ff (diff) | |
download | gcc-807e902eea17f3132488c256c963823976b2348c.zip gcc-807e902eea17f3132488c256c963823976b2348c.tar.gz gcc-807e902eea17f3132488c256c963823976b2348c.tar.bz2 |
Merge in wide-int.
From-SVN: r210113
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/c-ada-spec.c | 34 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 70 | ||||
-rw-r--r-- | gcc/c-family/c-format.c | 2 | ||||
-rw-r--r-- | gcc/c-family/c-lex.c | 39 | ||||
-rw-r--r-- | gcc/c-family/c-pretty-print.c | 13 | ||||
-rw-r--r-- | gcc/c-family/cilk.c | 3 |
6 files changed, 65 insertions, 96 deletions
diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index fc21b62..a21bc49 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -29,21 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "cpplib.h" #include "c-pragma.h" #include "cpp-id-data.h" - -/* Adapted from hwint.h to use the Ada prefix. */ -#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG -# if HOST_BITS_PER_WIDE_INT == 64 -# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ - "16#%" HOST_LONG_FORMAT "x%016" HOST_LONG_FORMAT "x#" -# else -# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ - "16#%" HOST_LONG_FORMAT "x%08" HOST_LONG_FORMAT "x#" -# endif -#else - /* We can assume that 'long long' is at least 64 bits. */ -# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ - "16#%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x#" -#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */ +#include "wide-int.h" /* Local functions, macros and variables. */ static int dump_generic_ada_node (pretty_printer *, tree, tree, int, int, @@ -2211,19 +2197,19 @@ dump_generic_ada_node (pretty_printer *buffer, tree node, tree type, int spc, pp_unsigned_wide_integer (buffer, tree_to_uhwi (node)); else { - tree val = node; - unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val); - HOST_WIDE_INT high = TREE_INT_CST_HIGH (val); - - if (tree_int_cst_sgn (val) < 0) + wide_int val = node; + int i; + if (wi::neg_p (val)) { pp_minus (buffer); - high = ~high + !low; - low = -low; + val = -val; } sprintf (pp_buffer (buffer)->digit_buffer, - ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX, - (unsigned HOST_WIDE_INT) high, low); + "16#%" HOST_WIDE_INT_PRINT "x", + val.elt (val.get_len () - 1)); + for (i = val.get_len () - 2; i >= 0; i--) + sprintf (pp_buffer (buffer)->digit_buffer, + HOST_WIDE_INT_PRINT_PADDED_HEX, val.elt (i)); pp_string (buffer, pp_buffer (buffer)->digit_buffer); } break; diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 0ad955d..0afe2f5 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "target-def.h" #include "gimplify.h" +#include "wide-int-print.h" cpp_reader *parse_in; /* Declared in c-pragma.h. */ @@ -4122,9 +4123,12 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, { /* Convert primop1 to target type, but do not introduce additional overflow. We know primop1 is an int_cst. */ - primop1 = force_fit_type_double (*restype_ptr, - tree_to_double_int (primop1), - 0, TREE_OVERFLOW (primop1)); + primop1 = force_fit_type (*restype_ptr, + wide_int::from + (primop1, + TYPE_PRECISION (*restype_ptr), + TYPE_SIGN (TREE_TYPE (primop1))), + 0, TREE_OVERFLOW (primop1)); } if (type != *restype_ptr) { @@ -4132,20 +4136,10 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, maxval = convert (*restype_ptr, maxval); } - if (unsignedp && unsignedp0) - { - min_gt = INT_CST_LT_UNSIGNED (primop1, minval); - max_gt = INT_CST_LT_UNSIGNED (primop1, maxval); - min_lt = INT_CST_LT_UNSIGNED (minval, primop1); - max_lt = INT_CST_LT_UNSIGNED (maxval, primop1); - } - else - { - min_gt = INT_CST_LT (primop1, minval); - max_gt = INT_CST_LT (primop1, maxval); - min_lt = INT_CST_LT (minval, primop1); - max_lt = INT_CST_LT (maxval, primop1); - } + min_gt = tree_int_cst_lt (primop1, minval); + max_gt = tree_int_cst_lt (primop1, maxval); + min_lt = tree_int_cst_lt (minval, primop1); + max_lt = tree_int_cst_lt (maxval, primop1); val = 0; /* This used to be a switch, but Genix compiler can't handle that. */ @@ -4434,8 +4428,7 @@ pointer_int_sum (location_t loc, enum tree_code resultcode, convert (TREE_TYPE (intop), size_exp), 1); intop = convert (sizetype, t); if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t)) - intop = build_int_cst_wide (TREE_TYPE (intop), TREE_INT_CST_LOW (intop), - TREE_INT_CST_HIGH (intop)); + intop = wide_int_to_tree (TREE_TYPE (intop), intop); } /* Create the sum or difference. */ @@ -5512,7 +5505,7 @@ c_common_nodes_and_builtins (void) } /* This node must not be shared. */ - void_zero_node = make_node (INTEGER_CST); + void_zero_node = make_int_cst (1, 1); TREE_TYPE (void_zero_node) = void_type_node; void_list_node = build_void_list_node (); @@ -5719,7 +5712,7 @@ c_common_nodes_and_builtins (void) /* Create the built-in __null node. It is important that this is not shared. */ - null_node = make_node (INTEGER_CST); + null_node = make_int_cst (1, 1); TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0); /* Since builtin_types isn't gc'ed, don't export these nodes. */ @@ -6097,22 +6090,14 @@ c_add_case_label (location_t loc, splay_tree cases, tree cond, tree orig_type, static void match_case_to_enum_1 (tree key, tree type, tree label) { - char buf[2 + 2*HOST_BITS_PER_WIDE_INT/4 + 1]; - - /* ??? Not working too hard to print the double-word value. - Should perhaps be done with %lwd in the diagnostic routines? */ - if (TREE_INT_CST_HIGH (key) == 0) - snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_UNSIGNED, - TREE_INT_CST_LOW (key)); - else if (!TYPE_UNSIGNED (type) - && TREE_INT_CST_HIGH (key) == -1 - && TREE_INT_CST_LOW (key) != 0) - snprintf (buf, sizeof (buf), "-" HOST_WIDE_INT_PRINT_UNSIGNED, - -TREE_INT_CST_LOW (key)); + char buf[WIDE_INT_PRINT_BUFFER_SIZE]; + + if (tree_fits_uhwi_p (key)) + print_dec (key, buf, UNSIGNED); + else if (tree_fits_shwi_p (key)) + print_dec (key, buf, SIGNED); else - snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DOUBLE_HEX, - (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (key), - (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (key)); + print_hex (key, buf); if (TYPE_NAME (type) == 0) warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)), @@ -8849,13 +8834,14 @@ check_nonnull_arg (void * ARG_UNUSED (ctx), tree param, static bool get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp) { - /* Verify the arg number is a constant. */ - if (TREE_CODE (arg_num_expr) != INTEGER_CST - || TREE_INT_CST_HIGH (arg_num_expr) != 0) + /* Verify the arg number is a small constant. */ + if (tree_fits_uhwi_p (arg_num_expr)) + { + *valp = TREE_INT_CST_LOW (arg_num_expr); + return true; + } + else return false; - - *valp = TREE_INT_CST_LOW (arg_num_expr); - return true; } /* Handle a "nothrow" attribute; arguments as in diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 4c0313d..eeefce8 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -227,7 +227,7 @@ check_format_string (tree fntype, unsigned HOST_WIDE_INT format_num, static bool get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p) { - if (TREE_CODE (expr) != INTEGER_CST || TREE_INT_CST_HIGH (expr) != 0) + if (!tree_fits_uhwi_p (expr)) { gcc_assert (!validated_p); return false; diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index e3e1da2..ea24bfc 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "splay-tree.h" #include "debug.h" #include "target.h" +#include "wide-int.h" /* We may keep statistics about how long which files took to compile. */ static int header_time, body_time; @@ -49,9 +50,9 @@ static tree interpret_float (const cpp_token *, unsigned int, const char *, enum overflow_type *); static tree interpret_fixed (const cpp_token *, unsigned int); static enum integer_type_kind narrowest_unsigned_type - (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); + (const widest_int &, unsigned int); static enum integer_type_kind narrowest_signed_type - (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); + (const widest_int &, unsigned int); static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool); static tree lex_charconst (const cpp_token *); static void update_header_times (const char *); @@ -527,9 +528,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, there isn't one. */ static enum integer_type_kind -narrowest_unsigned_type (unsigned HOST_WIDE_INT low, - unsigned HOST_WIDE_INT high, - unsigned int flags) +narrowest_unsigned_type (const widest_int &val, unsigned int flags) { int itk; @@ -548,9 +547,7 @@ narrowest_unsigned_type (unsigned HOST_WIDE_INT low, continue; upper = TYPE_MAX_VALUE (integer_types[itk]); - if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high - || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high - && TREE_INT_CST_LOW (upper) >= low)) + if (wi::geu_p (wi::to_widest (upper), val)) return (enum integer_type_kind) itk; } @@ -559,8 +556,7 @@ narrowest_unsigned_type (unsigned HOST_WIDE_INT low, /* Ditto, but narrowest signed type. */ static enum integer_type_kind -narrowest_signed_type (unsigned HOST_WIDE_INT low, - unsigned HOST_WIDE_INT high, unsigned int flags) +narrowest_signed_type (const widest_int &val, unsigned int flags) { int itk; @@ -571,7 +567,6 @@ narrowest_signed_type (unsigned HOST_WIDE_INT low, else itk = itk_long_long; - for (; itk < itk_none; itk += 2 /* skip signed types */) { tree upper; @@ -580,9 +575,7 @@ narrowest_signed_type (unsigned HOST_WIDE_INT low, continue; upper = TYPE_MAX_VALUE (integer_types[itk]); - if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high - || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high - && TREE_INT_CST_LOW (upper) >= low)) + if (wi::geu_p (wi::to_widest (upper), val)) return (enum integer_type_kind) itk; } @@ -597,6 +590,7 @@ interpret_integer (const cpp_token *token, unsigned int flags, tree value, type; enum integer_type_kind itk; cpp_num integer; + HOST_WIDE_INT ival[3]; *overflow = OT_NONE; @@ -604,18 +598,23 @@ interpret_integer (const cpp_token *token, unsigned int flags, if (integer.overflow) *overflow = OT_OVERFLOW; + ival[0] = integer.low; + ival[1] = integer.high; + ival[2] = 0; + widest_int wval = widest_int::from_array (ival, 3); + /* The type of a constant with a U suffix is straightforward. */ if (flags & CPP_N_UNSIGNED) - itk = narrowest_unsigned_type (integer.low, integer.high, flags); + itk = narrowest_unsigned_type (wval, flags); else { /* The type of a potentially-signed integer constant varies depending on the base it's in, the standard in use, and the length suffixes. */ enum integer_type_kind itk_u - = narrowest_unsigned_type (integer.low, integer.high, flags); + = narrowest_unsigned_type (wval, flags); enum integer_type_kind itk_s - = narrowest_signed_type (integer.low, integer.high, flags); + = narrowest_signed_type (wval, flags); /* In both C89 and C99, octal and hex constants may be signed or unsigned, whichever fits tighter. We do not warn about this @@ -667,7 +666,7 @@ interpret_integer (const cpp_token *token, unsigned int flags, : "integer constant is too large for %<long%> type"); } - value = build_int_cst_wide (type, integer.low, integer.high); + value = wide_int_to_tree (type, wval); /* Convert imaginary to a complex type. */ if (flags & CPP_N_IMAGINARY) @@ -1165,9 +1164,9 @@ lex_charconst (const cpp_token *token) /* Cast to cppchar_signed_t to get correct sign-extension of RESULT before possibly widening to HOST_WIDE_INT for build_int_cst. */ if (unsignedp || (cppchar_signed_t) result >= 0) - value = build_int_cst_wide (type, result, 0); + value = build_int_cst (type, result); else - value = build_int_cst_wide (type, (cppchar_signed_t) result, -1); + value = build_int_cst (type, (cppchar_signed_t) result); return value; } diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index 62a0030..2e97d01 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pretty-print.h" #include "tree-iterator.h" #include "diagnostic.h" +#include "wide-int-print.h" /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti @@ -923,16 +924,14 @@ pp_c_integer_constant (c_pretty_printer *pp, tree i) pp_unsigned_wide_integer (pp, tree_to_uhwi (i)); else { - unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i); - HOST_WIDE_INT high = TREE_INT_CST_HIGH (i); - if (tree_int_cst_sgn (i) < 0) + wide_int wi = i; + + if (wi::lt_p (i, 0, TYPE_SIGN (TREE_TYPE (i)))) { pp_minus (pp); - high = ~high + !low; - low = -low; + wi = -wi; } - sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX, - (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low); + print_hex (wi, pp_buffer (pp)->digit_buffer); pp_string (pp, pp_buffer (pp)->digit_buffer); } if (TYPE_UNSIGNED (type)) diff --git a/gcc/c-family/cilk.c b/gcc/c-family/cilk.c index bf549ad..a952902 100644 --- a/gcc/c-family/cilk.c +++ b/gcc/c-family/cilk.c @@ -666,8 +666,7 @@ declare_one_free_variable (const void *var0, void **map0, /* Maybe promote to int. */ if (INTEGRAL_TYPE_P (var_type) && COMPLETE_TYPE_P (var_type) - && INT_CST_LT_UNSIGNED (TYPE_SIZE (var_type), - TYPE_SIZE (integer_type_node))) + && tree_int_cst_lt (TYPE_SIZE (var_type), TYPE_SIZE (integer_type_node))) arg_type = integer_type_node; else arg_type = var_type; |