qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH for 2.5] QEMU does not care about left shifts of


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH for 2.5] QEMU does not care about left shifts of signed negative values
Date: Tue, 17 Nov 2015 10:19:17 +0000

On 17 November 2015 at 09:59, Paolo Bonzini <address@hidden> wrote:
> There's no reason for the compiler to exploit the undefinedness of left
> shifts, In fact GCC explicitly documents that they do not use at all
> all this possibility.  They also say this is subject to change, but
> they have been saying this for 10 years (since the wording appeared in
> the GCC 4.0 manual).
>
> Any workaround for this particular case of undefined behavior uglifies
> the code: using unsigned is unsafe because the value becomes positive
> when extended; using -(a << b) does not express as well that the
> intention is to compute -a * 2^N.
>
> Clang has just added an obnoxious, pointless, *totally useless*, unsafe
> warning about this.  It's obnoxious and pointless because the compiler
> is not using the latitude that the standard gives it, so it just adds
> noise.  It is useless and unsafe because it does not catch the widely
> more common case where the LHS is a variable, and thus gives a false
> sense of security.

I think we should only take this patch if you can get a cast-iron
guarantee from both clang and gcc that they will never use this
UB to drive optimizations. As you say gcc already say this more or
less, but clang doesn't, and if they're warning about it that to
me suggests that they will feel freer to rely on the UB in future.

GCC is not our only supported compiler; UB is a real thing that
compilers in general take advantage of; we should be trying to
reduce our reliance on UB, not carving out extra areas where we
feel free to use it.

thanks
-- PMM



reply via email to

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