public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <rdsandiford@googlemail.com>
To: Mikael Pettersson <mikpe@it.uu.se>
Cc: John David Anglin <dave.anglin@nrc-cnrc.gc.ca>,
	 Eric Botcazou <ebotcazou@adacore.com>,
	 gcc-patches@gcc.gnu.org
Subject: Re: [5/8] Tweak bitfield alignment handling
Date: Tue, 20 Nov 2012 19:56:00 -0000	[thread overview]
Message-ID: <87vcd0ujz3.fsf@talisman.default> (raw)
In-Reply-To: <87y5hwva2d.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com>	(Richard Sandiford's message of "Tue, 20 Nov 2012 10:32:42 +0000")

Richard Sandiford <rdsandiford@googlemail.com> writes:
> Mikael Pettersson <mikpe@it.uu.se> writes:
>> John David Anglin writes:
>>  > On Sun, 18 Nov 2012, Richard Sandiford wrote:
>>  > 
>>  > >        HOST_WIDE_INT start = bitpos_ - (bitpos_ % unit);
>>  > >        if (bitregion_start_ && start < bitregion_start_)
>>  > >  	break;
>>  > > -      if (bitregion_end_ && start + unit > bitregion_end_ + 1)
>>  > > +      if (start + unit > bitregion_end_ + 1)
>>  > 
>>  > This causes:
>>  > 
>>  > /home/dave/gnu/gcc/objdir/./prev-gcc/g++ -B/home/dave/gnu/gcc/objdir/./prev-gcc/ -B/home/dave/opt/gnu/gcc/gcc-4.8.0/hppa-linux-gnu/bin/ -nostdinc++ -B/home/dave/gnu/gcc/objdir/prev-hppa-linux-gnu/libstdc++-v3/src/.libs -B/home/dave/gnu/gcc/objdir/prev-hppa-linux-gnu/libstdc++-v3/libsupc++/.libs -I/home/dave/gnu/gcc/objdir/prev-hppa-linux-gnu/libstdc++-v3/include/hppa-linux-gnu -I/home/dave/gnu/gcc
>>  > /objdir/prev-hppa-linux-gnu/libstdc++-v3/include -I/home/dave/gnu/gcc/gcc/libstdc++-v3/libsupc++ -L/home/dave/gnu/gcc/objdir/prev-hppa-linux-gnu/libstdc++-v3/sr
>>  > c/.libs -L/home/dave/gnu/gcc/objdir/prev-hppa-linux-gnu/libstdc++-v3/libsupc++/.libs -c   -g -O2 -DIN_GCC   -fno-exceptions -fno-rtti -fasynchronous-unwind-tabl
>>  > es -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribut
>>  > e -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror 
>>  > -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../g
>>  > cc/gcc/../include -I../../gcc/gcc/../libcpp/include  -I../../gcc/gcc/../libdecnu
>>  > mber -I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/gcc/../li
>>  > bbacktrace    ../../gcc/gcc/stor-layout.c -o stor-layout.o../../gcc/gcc/stor-layout.c: In member function 〘bool bit_field_mode_iterator::n
>>  > ext_mode(machine_mode*)〙:
>>  > ../../gcc/gcc/stor-layout.c:2690:43: error: comparison between signed and unsign
>>  > ed integer expressions [-Werror=sign-compare]
>>  >        if (start + unit > bitregion_end_ + 1)
>>  > 					   ^
>>  > cc1plus: all warnings being treated as errors
>>
>> This error also breaks m68k-linux bootstrap.
>>
>> HWI32 issue?
>
> Yeah, I expect so, sorry.
>
> Logically, everything here would be unsigned arithmetic, but as the
> comment says:
>
>   /* We use signed values here because the bit position can be negative
>      for invalid input such as gcc.dg/pr48335-8.c.  */
>
> This is the patch I'm testing.  There are three things being checked here:
>
> - "unit", the size of the mode in isolation.  This really is an unsigned
>   value, and is compared to unsigned values like GET_MODE_PRECISION.
>
> - bitpos_ % unit (+ bitsize_), the start and end positions of the bitfield
>   relative to the start of the mode.  The start position is supposed to be
>   [0, unit), so the modulus and result should be unsigned.  (Using unsigned
>   modulus doesn't cope with negative bit positions combined with
>   non-power-of-2 units, but I don't think we support that.)
>
> - bitregion_start_ and bitregion_end_.  bitpos_ is signed and can be
>   negative, so the bitregion comparison should continue to be signed.
>
> OK to commit if testing succeeds?

Now bootstrapped & regression-tested on x86_64-linux-gnu.

>
> Richard
>
>
> gcc/
> 	* stor-layout.c (bit_field_mode_iterator::next_mode): Fix signedness.
>
> Index: gcc/stor-layout.c
> ===================================================================
> --- gcc/stor-layout.c	2012-11-20 10:15:39.000000000 +0000
> +++ gcc/stor-layout.c	2012-11-20 10:15:39.464712715 +0000
> @@ -2670,10 +2670,6 @@ bit_field_mode_iterator::next_mode (enum
>        if (unit != GET_MODE_PRECISION (mode_))
>  	continue;
>  
> -      /* Skip modes that are too small.  */
> -      if ((bitpos_ % unit) + bitsize_ > unit)
> -	continue;
> -
>        /* Stop if the mode is too wide to handle efficiently.  */
>        if (unit > MAX_FIXED_MODE_SIZE)
>  	break;
> @@ -2683,11 +2679,18 @@ bit_field_mode_iterator::next_mode (enum
>        if (count_ > 0 && unit > BITS_PER_WORD)
>  	break;
>  
> +      /* Skip modes that are too small.  */
> +      unsigned HOST_WIDE_INT substart = (unsigned HOST_WIDE_INT) bitpos_ % unit;
> +      unsigned HOST_WIDE_INT subend = substart + bitsize_;
> +      if (subend > unit)
> +	continue;
> +
>        /* Stop if the mode goes outside the bitregion.  */
> -      HOST_WIDE_INT start = bitpos_ - (bitpos_ % unit);
> +      HOST_WIDE_INT start = bitpos_ - substart;
>        if (bitregion_start_ && start < bitregion_start_)
>  	break;
> -      if (start + unit > bitregion_end_ + 1)
> +      HOST_WIDE_INT end = start + unit;
> +      if (end > bitregion_end_ + 1)
>  	break;
>  
>        /* Stop if the mode requires too much alignment.  */

  reply	other threads:[~2012-11-20 19:56 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-03 11:10 [0/8] Add optabs alternatives for insv, extv and extzv Richard Sandiford
2012-11-03 11:13 ` [1/8] Handle TRUNCATE in make_extraction Richard Sandiford
2012-11-10 15:52   ` Eric Botcazou
2012-11-03 11:14 ` [2/8] Add adjust_bitfield_address_size Richard Sandiford
2012-11-10 15:53   ` Eric Botcazou
2012-11-03 11:16 ` [3/8] Add narrow_bit_field_mem Richard Sandiford
2012-11-10 16:02   ` Eric Botcazou
2012-11-03 11:21 ` [4/8] Add bit_field_mode_iterator Richard Sandiford
2012-11-13 12:44   ` Eric Botcazou
2012-11-13 21:46     ` Richard Henderson
2012-11-13 22:05       ` Eric Botcazou
2012-11-15 12:11         ` Richard Sandiford
2012-11-15 20:39           ` Richard Henderson
2012-11-18 17:34             ` Richard Sandiford
2012-11-18 17:36     ` Richard Sandiford
2012-11-03 11:27 ` [5/8] Tweak bitfield alignment handling Richard Sandiford
2012-11-13 13:52   ` Eric Botcazou
2012-11-18 17:36     ` Richard Sandiford
2012-11-20  2:57       ` John David Anglin
2012-11-20  8:21         ` Mikael Pettersson
2012-11-20 10:32           ` Richard Sandiford
2012-11-20 19:56             ` Richard Sandiford [this message]
2012-11-20 22:11             ` Eric Botcazou
2012-11-03 11:28 ` [6/8] Add strict volatile handling to bit_field_mode_iterator Richard Sandiford
2012-11-13 13:57   ` Eric Botcazou
2012-11-15 12:25     ` Richard Sandiford
2012-11-15 17:10       ` Eric Botcazou
2012-11-15 17:47         ` Richard Sandiford
2012-11-15 19:32           ` Eric Botcazou
2012-11-18 17:36             ` Richard Sandiford
2012-11-03 11:39 ` [7/8] Replace mode_for_extraction with new interface Richard Sandiford
2012-11-03 11:41 ` [8/8] Add new optabs and use them for MIPS Richard Sandiford
2012-11-27 17:11 ` [0/8] Add optabs alternatives for insv, extv and extzv Ramana Radhakrishnan
2012-11-27 20:22   ` Richard Sandiford
2012-11-27 22:45     ` Ramana Radhakrishnan
2012-11-28 10:25       ` Richard Biener
2012-11-28 12:06         ` Ramana Radhakrishnan
2012-11-28 12:51           ` Richard Biener
2012-11-28 13:58       ` Richard Sandiford
2012-11-28 23:19         ` Eric Botcazou
2012-11-29 10:31           ` Richard Sandiford
2012-11-29 15:31             ` Eric Botcazou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vcd0ujz3.fsf@talisman.default \
    --to=rdsandiford@googlemail.com \
    --cc=dave.anglin@nrc-cnrc.gc.ca \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mikpe@it.uu.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).