qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, ehabkost@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	rth@twiddle.net
Subject: [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning
Date: Tue, 27 Oct 2015 15:24:29 +0100	[thread overview]
Message-ID: <1445955869-24612-1-git-send-email-marcandre.lureau@redhat.com> (raw)

From: Marc-André Lureau <marcandre.lureau@redhat.com>

When running vhost-user-test with clang compiled qemu with
--extra-cflags=-fsanitize=undefined, the following error is printed:

qemu/target-i386/translate.c:2435:26: runtime error: left shift of negative value -8

According to c99, this is undefined behaviour. (see also
http://stackoverflow.com/questions/22883790/left-shift-of-negative-values)

I guess the intended code is to subtract (8 << s->dflag), thus adding
parentheses seems to be enough.

Signed-off-by: Marc-André Lureau <marcandre.lureau@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 764b1e4..862f8e0 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -2432,7 +2432,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));
     if (!s->ss32)
         tcg_gen_ext16u_tl(cpu_A0, cpu_A0);
     tcg_gen_mov_tl(cpu_T[1], cpu_A0);
-- 
2.4.3

             reply	other threads:[~2015-10-27 14:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 14:24 marcandre.lureau [this message]
2015-10-27 16:02 ` [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning Peter Maydell

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=1445955869-24612-1-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=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 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 NNTP newsgroup(s).