From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126913 invoked by alias); 20 Mar 2019 17:36:39 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 126167 invoked by uid 89); 20 Mar 2019 17:36:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=str=c3=bcbe, Str=c3=bcbe, HX-Languages-Length:993, Ltd?= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Mar 2019 17:36:37 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09DB5C02E60C; Wed, 20 Mar 2019 17:36:36 +0000 (UTC) Received: from zebedee.pink (unknown [10.33.36.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 349FA5D71C; Wed, 20 Mar 2019 17:36:35 +0000 (UTC) To: =?UTF-8?Q?Moritz_Str=c3=bcbe?= , Jakub Jelinek , "gcc@gcc.gnu.org" References: <4af9e251-f4c3-a5a4-e33d-fb8750c87e36@redheads.de> <20190311091449.GB7611@tucnak> <9085342b-41a6-851c-28e3-08a40cc30103@redheads.de> <20190311111702.GD7611@tucnak> <99e48024-6331-2ba6-272c-51f8cf9e9780@redheads.de> From: Andrew Haley Openpgp: preference=signencrypt Subject: Re: GCC turns &~ into | due to undefined bit-shift without warning Message-ID: <7644f9cc-2fcd-c13c-a631-53c62c17333b@redhat.com> Date: Wed, 20 Mar 2019 17:36:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <99e48024-6331-2ba6-272c-51f8cf9e9780@redheads.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-03/txt/msg00144.txt.bz2 On 3/20/19 2:08 PM, Moritz Strübe wrote: > > Ok, I played around a bit. Interestingly, if I set > -fsanitize=udefined and -fsanitize-undefined-trap-on-error the > compiler detects that it will always trap, and optimizes the code > accordingly (the code after the trap is removed).* Which kind of > brings me to David's argument: Shouldn't the compiler warn if there > is undefined behavior it certainly knows of? Maybe an example would help. Consider this code: for (int i = start; i < limit; i++) { foo(i * 5); } Should GCC be entitled to turn it into int limit_tmp = i * 5; for (int i = start * 5; i < limit_tmp; i += 5) { foo(i); } If you answered "Yes, GCC should be allowed to do this", would you want a warning? And how many such warnings might there be in a typical program? -- Andrew Haley Java Platform Lead Engineer Red Hat UK Ltd. EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671