This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [wide-int 1/8] Fix some off-by-one errors and bounds tests
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Kenneth Zadeck <zadeck at naturalbridge dot com>, Mike Stump <mikestump at comcast dot net>, Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Wed, 23 Apr 2014 11:50:53 +0200
- Subject: Re: [wide-int 1/8] Fix some off-by-one errors and bounds tests
- Authentication-results: sourceware.org; auth=none
- References: <87d2g9f8s8 dot fsf at talisman dot default>
On Tue, Apr 22, 2014 at 9:45 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> This is the first of 8 patches from reading through the diff with mainline.
> Some places had an off-by-one error on an index and some used "<= 0"
> instead of ">= 0".
>
> I think we should use MAX_BITSIZE_MODE_ANY_MODE rather than
> MAX_BITSIZE_MODE_ANY_INT when handling floating-point modes.
>
> Two hunks contain unrelated formatting fixes too.
>
> Tested on x86_64-linux-gnu. OK to install?
Ok.
Thanks,
Richard.
> Thanks,
> Richard
>
> Index: gcc/c-family/c-ada-spec.c
> ===================================================================
> --- gcc/c-family/c-ada-spec.c 2014-04-22 20:31:10.632895953 +0100
> +++ gcc/c-family/c-ada-spec.c 2014-04-22 20:31:24.880998602 +0100
> @@ -2205,8 +2205,9 @@ dump_generic_ada_node (pretty_printer *b
> val = -val;
> }
> sprintf (pp_buffer (buffer)->digit_buffer,
> - "16#%" HOST_WIDE_INT_PRINT "x", val.elt (val.get_len () - 1));
> - for (i = val.get_len () - 2; i <= 0; i--)
> + "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);
> Index: gcc/dbxout.c
> ===================================================================
> --- gcc/dbxout.c 2014-04-22 20:31:10.632895953 +0100
> +++ gcc/dbxout.c 2014-04-22 20:31:24.881998608 +0100
> @@ -720,7 +720,7 @@ stabstr_O (tree cst)
> }
>
> prec -= res_pres;
> - for (i = prec - 3; i <= 0; i = i - 3)
> + for (i = prec - 3; i >= 0; i = i - 3)
> {
> digit = wi::extract_uhwi (cst, i, 3);
> stabstr_C ('0' + digit);
> Index: gcc/dwarf2out.c
> ===================================================================
> --- gcc/dwarf2out.c 2014-04-22 20:31:10.632895953 +0100
> +++ gcc/dwarf2out.c 2014-04-22 20:31:24.884998630 +0100
> @@ -1847,7 +1847,7 @@ output_loc_operands (dw_loc_descr_ref lo
> int i;
> int len = get_full_len (*val2->v.val_wide);
> if (WORDS_BIG_ENDIAN)
> - for (i = len; i >= 0; --i)
> + for (i = len - 1; i >= 0; --i)
> dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
> val2->v.val_wide->elt (i), NULL);
> else
> @@ -2073,7 +2073,7 @@ output_loc_operands (dw_loc_descr_ref lo
>
> dw2_asm_output_data (1, len * l, NULL);
> if (WORDS_BIG_ENDIAN)
> - for (i = len; i >= 0; --i)
> + for (i = len - 1; i >= 0; --i)
> dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
> else
> for (i = 0; i < len; ++i)
> @@ -5398,11 +5398,11 @@ print_die (dw_die_ref die, FILE *outfile
> int i = a->dw_attr_val.v.val_wide->get_len ();
> fprintf (outfile, "constant (");
> gcc_assert (i > 0);
> - if (a->dw_attr_val.v.val_wide->elt (i) == 0)
> + if (a->dw_attr_val.v.val_wide->elt (i - 1) == 0)
> fprintf (outfile, "0x");
> fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
> a->dw_attr_val.v.val_wide->elt (--i));
> - while (-- i >= 0)
> + while (--i >= 0)
> fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
> a->dw_attr_val.v.val_wide->elt (i));
> fprintf (outfile, ")");
> @@ -8723,7 +8723,7 @@ output_die (dw_die_ref die)
> NULL);
>
> if (WORDS_BIG_ENDIAN)
> - for (i = len; i >= 0; --i)
> + for (i = len - 1; i >= 0; --i)
> {
> dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
> name);
> Index: gcc/simplify-rtx.c
> ===================================================================
> --- gcc/simplify-rtx.c 2014-04-22 20:31:10.632895953 +0100
> +++ gcc/simplify-rtx.c 2014-04-22 20:31:24.884998630 +0100
> @@ -5395,7 +5395,7 @@ simplify_immed_subreg (enum machine_mode
> case MODE_DECIMAL_FLOAT:
> {
> REAL_VALUE_TYPE r;
> - long tmp[MAX_BITSIZE_MODE_ANY_INT / 32];
> + long tmp[MAX_BITSIZE_MODE_ANY_MODE / 32];
>
> /* real_from_target wants its input in words affected by
> FLOAT_WORDS_BIG_ENDIAN. However, we ignore this,