From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIiNQ-0006W6-FM for qemu-devel@nongnu.org; Thu, 30 Jun 2016 16:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIiNO-0007Zc-BD for qemu-devel@nongnu.org; Thu, 30 Jun 2016 16:15:55 -0400 Date: Thu, 30 Jun 2016 16:15:46 -0400 (EDT) From: Paolo Bonzini Message-ID: <209727639.3312728.1467317746061.JavaMail.zimbra@redhat.com> In-Reply-To: <1467315396-3628-1-git-send-email-jsnow@redhat.com> References: <1467315396-3628-1-git-send-email-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Remove left shifts of negative signed integers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, kraxel@redhat.com, peter maydell ----- Original Message ----- > From: "John Snow" > To: qemu-devel@nongnu.org > Cc: qemu-trivial@nongnu.org, pbonzini@redhat.com, kraxel@redhat.com, "peter maydell" , > "John Snow" > Sent: Thursday, June 30, 2016 9:36:36 PM > Subject: [PATCH] Remove left shifts of negative signed integers > > Another exercise in placating Clang's increasingly strict -Werror mode. > Technically, this is undefined behavior. In practice, -N< as -(N< > Signed-off-by: John Snow There's been discussions on this in the past; sorry but this is a super-duper NACK. GCC correctly puts this warning under -Wextra, and promises not to ever make use of this facet of undefined behavior. The only correct patch is the one that disables the warning for clang, and possibly adds -fwrapv. In GCC, -fwrapv correctly silences ubsan's left-shift and signed-overflow warnings. In Clang, this is reported at https://llvm.org/bugs/show_bug.cgi?id=25552. It's a heavy hammer but it's the safest options as compiler evolve. Paolo > --- > hw/audio/fmopl.c | 2 +- > target-i386/monitor.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c > index 731110f..de9338b 100644 > --- a/hw/audio/fmopl.c > +++ b/hw/audio/fmopl.c > @@ -69,7 +69,7 @@ static int opl_dbg_maxchip,opl_dbg_chip; > /* final output shift , limit minimum and maximum */ > #define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */ > #define OPL_MAXOUT (0x7fff< -#define OPL_MINOUT (-0x8000< +#define OPL_MINOUT (-(0x8000< > /* -------------------- quality selection --------------------- */ > > diff --git a/target-i386/monitor.c b/target-i386/monitor.c > index fccfe40..94e9871 100644 > --- a/target-i386/monitor.c > +++ b/target-i386/monitor.c > @@ -36,7 +36,7 @@ static void print_pte(Monitor *mon, hwaddr addr, > { > #ifdef TARGET_X86_64 > if (addr & (1ULL << 47)) { > - addr |= -1LL << 48; > + addr |= -(1LL << 48); > } > #endif > monitor_printf(mon, TARGET_FMT_plx ": " TARGET_FMT_plx > -- > 2.5.5 > >