From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwExV-0001Gy-5i for qemu-devel@nongnu.org; Tue, 10 Nov 2015 14:52:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwExT-0006xs-Ue for qemu-devel@nongnu.org; Tue, 10 Nov 2015 14:52:01 -0500 Received: from mail-lb0-x229.google.com ([2a00:1450:4010:c04::229]:35046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwExT-0006xc-MC for qemu-devel@nongnu.org; Tue, 10 Nov 2015 14:51:59 -0500 Received: by lbces9 with SMTP id es9so4618443lbc.2 for ; Tue, 10 Nov 2015 11:51:58 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <87vb99lmae.fsf@blackfin.pond.sub.org> References: <1447171055-29567-1-git-send-email-stefanha@redhat.com> <1447171055-29567-4-git-send-email-stefanha@redhat.com> <56422A70.8040306@redhat.com> <87vb99lmae.fsf@blackfin.pond.sub.org> Date: Tue, 10 Nov 2015 11:51:58 -0800 Message-ID: From: Steven Noonan Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH 3/3] disas/arm: avoid clang shifting negative signed warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Peter Maydell , Eduardo Habkost , QEMU Developers , Stefan Hajnoczi , Paolo Bonzini On Tue, Nov 10, 2015 at 10:52 AM, Markus Armbruster wrote: > Peter Maydell writes: > >> On 10 November 2015 at 17:33, Paolo Bonzini 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 >>> >>> 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.