[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [PATCH] Remove left shifts of negative signed integer

From: Peter Maydell
Subject: Re: [Qemu-trivial] [PATCH] Remove left shifts of negative signed integers
Date: Tue, 16 Aug 2016 15:00:22 +0100

On 30 June 2016 at 21:15, Paolo Bonzini <address@hidden> wrote:
> 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.

James Molloy kindly wrote a patch for clang which fixes PR25552
(so -fwrapv silences the compiler warning and the sanitizer
warning), and that has now been committed to clang. So I'm now
happy that both clang and gcc agree that -fwrapv is the way to
give you a well-defined C dialect with the shift semantics we
want. Post-2.7 we should add -fwrapv to our compiler flags
(we'll want to keep -Wno-shift-negative-value for the benefit
of clang versions without the 25552 bugfix).

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]