From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19991 invoked by alias); 21 Mar 2019 08:17:47 -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 19981 invoked by uid 89); 21 Mar 2019 08:17:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*i:sk:7644f9c, H*f:sk:7644f9c, Ltd, ltd X-HELO: mail-lf1-f48.google.com Received: from mail-lf1-f48.google.com (HELO mail-lf1-f48.google.com) (209.85.167.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Mar 2019 08:17:45 +0000 Received: by mail-lf1-f48.google.com with SMTP id u2so3919469lfd.4 for ; Thu, 21 Mar 2019 01:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=golEbfWYzBa3LzCYJUNJvQXx+dXK12p+JaZ7gwwzMuA=; b=QqMqd/K7zJaQOqrzP4CAdLa+kGoeEPPGB+tG/UX40+rocG4wswCS5RLfpXca7UEX8U PXbJLIMgV3xqzBf3G7OKhSLAf7iB1RBp8sors3JDtZaOaSDklRE3riMpU0zEWiGLor1S 0f7fn6adPBW2sSKKQL6ktPV+e4UOrjRhtMeBTkPmFPNOUBB2Vy+0Uos5CdLDS9m/iuh+ oI1ke5fOEBTsn9gscCkRK8E4+P8Qa1KlqUJ+RgukMZGehvnRXsQebhcNgkiY4Ngn6s4L 8t0r3BJnhOzEs9hHRGG16iJX+wmq63mHBes8nAsk8FGISBj8kckP8cv89NOP0uQRlAIF 28gA== MIME-Version: 1.0 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> <7644f9cc-2fcd-c13c-a631-53c62c17333b@redhat.com> In-Reply-To: <7644f9cc-2fcd-c13c-a631-53c62c17333b@redhat.com> From: Richard Biener Date: Thu, 21 Mar 2019 08:17:00 -0000 Message-ID: Subject: Re: GCC turns &~ into | due to undefined bit-shift without warning To: Andrew Haley Cc: =?UTF-8?Q?Moritz_Str=C3=BCbe?= , Jakub Jelinek , "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-03/txt/msg00148.txt.bz2 On Wed, Mar 20, 2019 at 6:36 PM Andrew Haley wrote: > > On 3/20/19 2:08 PM, Moritz Str=C3=BCbe wrote: > > > > Ok, I played around a bit. Interestingly, if I set > > -fsanitize=3Dudefined 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 =3D start; i < limit; i++) { > foo(i * 5); > } > > Should GCC be entitled to turn it into > > int limit_tmp =3D i * 5; > for (int i =3D start * 5; i < limit_tmp; i +=3D 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? I assume i is signed int. Even then GCC may not do this unless it knows the loop is entered (start < limit). Richard. > > -- > Andrew Haley > Java Platform Lead Engineer > Red Hat UK Ltd. > EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671