From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3CC253857C48 for ; Sun, 7 Mar 2021 11:37:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3CC253857C48 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397--YV72I2MNs2aSAZW4M3q1Q-1; Sun, 07 Mar 2021 06:37:38 -0500 X-MC-Unique: -YV72I2MNs2aSAZW4M3q1Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31ABF1084C98 for ; Sun, 7 Mar 2021 11:37:37 +0000 (UTC) Received: from zarquon.pink (unknown [10.33.36.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97637179E6; Sun, 7 Mar 2021 11:37:36 +0000 (UTC) To: gcc-help@gcc.gnu.org References: <20210306120324.GA12119@platinum.motzkau> From: Andrew Haley Subject: Re: Question about -Wstrict-overflow=2 Message-ID: <73a14b39-fca0-0b2a-d31c-942658e8940a@redhat.com> Date: Sun, 7 Mar 2021 11:37:35 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210306120324.GA12119@platinum.motzkau> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2021 11:37:42 -0000 On 3/6/21 12:03 PM, Alexander Motzkau via Gcc-help wrote: > Andrew Haley wrote: >> The compiler is telling you that it's assuming that expbuf + 120 >> does not wrap around. There's nothing really mysterious about it. > > But should that warning only occur on -Wstrict-overflow=3 or higher? > Why does it occur on -Wstrict-overflow=2? -Wstrict-overflow=2 triggers when GCC encounters expressions that reduce to a constant, where that evaluation depends on overflow not occuring. In this case the expression is expbuf + 120 > get_buf() This exact phrase doesn't occur in your program, but GCC generates it while optimizing. > I usually compile my software with -Werror (so that warnings won't be > ignored anymore) and so this information from the compiler broke the build > when going from GCC 8 to GCC 9. It seems -Wstrict-overflow=2 there is not > fit to be used with -Werror anymore. Am I correct? I doubt that it ever was. -Wstrict-overflow=2 is informative, for the programmer. It doesn't suggest that anything is questionable about the program, and in this case it's difficult or impossible to avoid. Re upgrading: over time, GCC gets better and better at diagnosing and providing information. This inevitably means that programmers using -Werror with high levels of warnings have to change their programs when a new GCC is used. -- Andrew Haley (he/him) Java Platform Lead Engineer Red Hat UK Ltd. https://keybase.io/andrewhaley EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671