All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Richard Henderson <rth@twiddle.net>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] target-i386: Don't left shift negative constant
Date: Thu, 1 Oct 2015 14:06:36 -0300	[thread overview]
Message-ID: <20151001170636.GD1260@thinpad.lan.raisama.net> (raw)
In-Reply-To: <560C8DF8.7020700@twiddle.net>

On Thu, Oct 01, 2015 at 11:35:52AM +1000, Richard Henderson wrote:
> On 09/30/2015 06:34 AM, Eduardo Habkost wrote:
> >Left shift of negative values is undefined behavior. Detected by clang:
> >   qemu/target-i386/translate.c:2423:26: runtime error:
> >     left shift of negative value -8
> >
> >This changes the code to reverse the sign after the left shift.
> >
> >Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >---
> >  target-i386/translate.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/target-i386/translate.c b/target-i386/translate.c
> >index 8b35de1..cc59b7e 100644
> >--- a/target-i386/translate.c
> >+++ b/target-i386/translate.c
> >@@ -2420,7 +2420,7 @@ static void gen_pusha(DisasContext *s)
> >  {
> >      int i;
> >      gen_op_movl_A0_reg(R_ESP);
> >-    gen_op_addl_A0_im(-8 << s->dflag);
> >+    gen_op_addl_A0_im(-(8 << s->dflag));
> 
> Better as -8U << s->d_flag?

That's even more confusing to me. I wouldn't want to require other
people to read the C specification to find out how many type conversions
are happening in that statement. (Because I will have to do that, to
find out what's the type of "-8U").

I would prefer an expression that doesn't involve any type conversion.
But you are more familiar with that code, so it's up to you.

-- 
Eduardo

  reply	other threads:[~2015-10-01 17:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 20:34 [Qemu-devel] [PATCH 0/2] target-i386: Fix undefined behavior on bit shifts Eduardo Habkost
2015-09-29 20:34 ` [Qemu-devel] [PATCH 1/2] target-i386: Use 1UL for bit shift Eduardo Habkost
2015-09-30 13:27   ` Paolo Bonzini
2015-09-30 20:24     ` Richard Henderson
2015-10-01  8:29       ` Paolo Bonzini
2015-10-01  9:24       ` Peter Maydell
2015-10-01 13:52         ` Paolo Bonzini
2015-10-01 17:07           ` Laszlo Ersek
2015-10-01 17:30             ` Paolo Bonzini
2015-10-01 17:38               ` Peter Maydell
2015-10-01 19:17                 ` Laszlo Ersek
2015-10-02  8:34                   ` Paolo Bonzini
2015-10-02 11:14                     ` Laszlo Ersek
2015-10-02 12:07                       ` Paolo Bonzini
2015-10-04  2:34                         ` Kevin O'Connor
2015-10-01 20:35                 ` Markus Armbruster
2015-10-01 18:40               ` Laszlo Ersek
2015-10-02  8:48                 ` Paolo Bonzini
2015-09-29 20:34 ` [Qemu-devel] [PATCH 2/2] target-i386: Don't left shift negative constant Eduardo Habkost
2015-10-01  1:35   ` Richard Henderson
2015-10-01 17:06     ` Eduardo Habkost [this message]
2015-10-23 15:07       ` Eduardo Habkost
2015-10-23 18:20         ` Richard Henderson

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=20151001170636.GD1260@thinpad.lan.raisama.net \
    --to=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.