public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix handling of negative bitpos in expand_debug_expr
@ 2016-05-05 14:21 Richard Sandiford
  2016-05-09  9:11 ` Bernd Schmidt
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2016-05-05 14:21 UTC (permalink / raw)
  To: gcc-patches

expand_debug_expr handled negative bit positions using:

            else if (bitpos < 0)
              {
                HOST_WIDE_INT units
                  = (-bitpos + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
                op0 = adjust_address_nv (op0, mode1, units);
                bitpos += units * BITS_PER_UNIT;
              }

Here "units" is the negative of the (negative) byte offset, so I think
we should be offsetting OP0 by -units instead.  E.g. a bitpos of -17
would give units==3, so this code would move OP0 up by 3 bytes and set
bitpos to 7, giving a total bitpos of 31.

Just noticed by inspection.  An assert triggered for:

    gcc.target/i386/mpx/bitfields-1-lbv.c
    gcc.target/i386/mpx/field-addr-7-lbv.c
    gcc.target/i386/mpx/reference-3-lbv.cpp
    gcc.target/i386/mpx/reference-4-lbv.cpp

at -m32 but otherwise this case doesn't seem to trigger during a
bootstrap and regtest.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
	* cfgexpand.c (expand_debug_expr): Fix address offset for negative
	bitpos.

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 21f21c9..77a1964 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4473,7 +4473,7 @@ expand_debug_expr (tree exp)
 	      {
 		HOST_WIDE_INT units
 		  = (-bitpos + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
-		op0 = adjust_address_nv (op0, mode1, units);
+		op0 = adjust_address_nv (op0, mode1, -units);
 		bitpos += units * BITS_PER_UNIT;
 	      }
 	    else if (bitpos == 0 && bitsize == GET_MODE_BITSIZE (mode))

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix handling of negative bitpos in expand_debug_expr
  2016-05-05 14:21 Fix handling of negative bitpos in expand_debug_expr Richard Sandiford
@ 2016-05-09  9:11 ` Bernd Schmidt
  0 siblings, 0 replies; 2+ messages in thread
From: Bernd Schmidt @ 2016-05-09  9:11 UTC (permalink / raw)
  To: gcc-patches, richard.sandiford

On 05/05/2016 04:20 PM, Richard Sandiford wrote:
> expand_debug_expr handled negative bit positions using:
>
>              else if (bitpos < 0)
>                {
>                  HOST_WIDE_INT units
>                    = (-bitpos + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
>                  op0 = adjust_address_nv (op0, mode1, units);
>                  bitpos += units * BITS_PER_UNIT;
>                }
>
> Here "units" is the negative of the (negative) byte offset, so I think
> we should be offsetting OP0 by -units instead.  E.g. a bitpos of -17
> would give units==3, so this code would move OP0 up by 3 bytes and set
> bitpos to 7, giving a total bitpos of 31.

> gcc/
> 	* cfgexpand.c (expand_debug_expr): Fix address offset for negative
> 	bitpos.

Ok.


Bernd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-09  9:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-05 14:21 Fix handling of negative bitpos in expand_debug_expr Richard Sandiford
2016-05-09  9:11 ` Bernd Schmidt

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).