All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Noonan <steven@uplinklabs.net>
To: Markus Armbruster <armbru@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Eduardo Habkost <ehabkost@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/3] disas/arm: avoid clang shifting negative signed warning
Date: Tue, 10 Nov 2015 11:51:58 -0800	[thread overview]
Message-ID: <CAKbGBLiF5tYNk_GA4XWPTvQuvux5khyVazkFi+REetuo1Th0dg@mail.gmail.com> (raw)
In-Reply-To: <87vb99lmae.fsf@blackfin.pond.sub.org>

On Tue, Nov 10, 2015 at 10:52 AM, Markus Armbruster <armbru@redhat.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On 10 November 2015 at 17:33, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>
>>>
>>> On 10/11/2015 16:57, Stefan Hajnoczi wrote:
>>>> clang 3.7.0 on x86_64 warns about the following:
>>>>
>>>>   disas/arm.c:1782:17: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
>>>>     imm |= (-1 << 7);
>>>>             ~~ ^
>>>>
>>>> Note that this patch preserves the tab indent in this source file
>>>> because the surrounding code still uses tabs.
>>>>
>>>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>>>
>>> I would like to know a case where (except with ubsan) clang actually
>>> uses the optimization.
>>>
>>> If not, this is just error message theatre (which is not news for clang)
>>> and shouldn't have been part of -Wall.
>>
>> It could be they're attempting to warn us now about the possibility
>> that in a future version of clang they will start using this UB
>> to optimize with.
>>
>> http://stackoverflow.com/questions/22883790/left-shift-of-negative-values
>> reports that Intel's ICC will use this in dead-code-elimination
>> optimization. One day clang might do that too.
>
> Nice example of a compiler being gratuitously nasty.
>

I don't read this warning as "clang will do crazy things with your
code eventually". Clang has always been very verbose when it comes to
undefined behavior, and I don't think that's really a bad thing to do.
Even if clang does emit sane code for it, all bets are off for other
compilers -- so it's more of a portability warning. And I know some
other compilers *won't* warn before doing crazy things in the name of
undefined behavior. The ICC example is a fine one...

In my experience fixing the warnings produced by clang has actually
eliminated bugs that were present but undiscovered on other platforms.

  reply	other threads:[~2015-11-10 19:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10 15:57 [Qemu-devel] [PATCH 0/3] fix clang negative signed bit shift warning Stefan Hajnoczi
2015-11-10 15:57 ` [Qemu-devel] [PATCH 1/3] monitor: avoid clang shifting negative signed warning Stefan Hajnoczi
2015-11-13 15:37   ` Eduardo Habkost
2015-11-10 15:57 ` [Qemu-devel] [PATCH 2/3] tpm: " Stefan Hajnoczi
2015-11-10 15:57 ` [Qemu-devel] [PATCH 3/3] disas/arm: " Stefan Hajnoczi
2015-11-10 17:33   ` Paolo Bonzini
2015-11-10 17:48     ` Peter Maydell
2015-11-10 17:59       ` Paolo Bonzini
2015-11-10 18:52       ` Markus Armbruster
2015-11-10 19:51         ` Steven Noonan [this message]
2015-11-10 20:06           ` Markus Armbruster
2015-11-10 20:17             ` Steven Noonan
2015-11-10 20:18           ` Paolo Bonzini
2015-11-10 16:04 ` [Qemu-devel] [PATCH 0/3] fix clang negative signed bit shift warning Peter Maydell
2015-11-16 14:23 ` Peter Maydell
2015-11-16 15:20   ` Peter Maydell
2015-11-17  3:50     ` Stefan Hajnoczi
2015-11-17  3:53 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKbGBLiF5tYNk_GA4XWPTvQuvux5khyVazkFi+REetuo1Th0dg@mail.gmail.com \
    --to=steven@uplinklabs.net \
    --cc=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.