From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr5B0-00027p-Pk for qemu-devel@nongnu.org; Tue, 27 Oct 2015 10:24:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zr5Ay-0004yA-Jk for qemu-devel@nongnu.org; Tue, 27 Oct 2015 10:24:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr5Ay-0004x0-FR for qemu-devel@nongnu.org; Tue, 27 Oct 2015 10:24:36 -0400 From: marcandre.lureau@redhat.com Date: Tue, 27 Oct 2015 15:24:29 +0100 Message-Id: <1445955869-24612-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] target-i386: fix clang sanitize warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, ehabkost@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , rth@twiddle.net From: Marc-Andr=C3=A9 Lureau When running vhost-user-test with clang compiled qemu with --extra-cflags=3D-fsanitize=3Dundefined, the following error is printed: qemu/target-i386/translate.c:2435:26: runtime error: left shift of negati= ve 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=C3=A9 Lureau --- 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); --=20 2.4.3