All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning
@ 2015-10-27 14:24 marcandre.lureau
  2015-10-27 16:02 ` Peter Maydell
  0 siblings, 1 reply; 2+ messages in thread
From: marcandre.lureau @ 2015-10-27 14:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, ehabkost, Marc-André Lureau, rth

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

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

* Re: [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning
  2015-10-27 14:24 [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning marcandre.lureau
@ 2015-10-27 16:02 ` Peter Maydell
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2015-10-27 16:02 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Paolo Bonzini, Richard Henderson, QEMU Developers, Eduardo Habkost

On 27 October 2015 at 14:24,  <marcandre.lureau@redhat.com> wrote:
> 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);

Looks like Eduardo already had a patch on list for this:

http://patchwork.ozlabs.org/patch/524590/

thanks
-- PMM

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

end of thread, other threads:[~2015-10-27 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27 14:24 [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning marcandre.lureau
2015-10-27 16:02 ` Peter Maydell

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.