From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.web.de (mout.web.de [212.227.15.14]) by sourceware.org (Postfix) with ESMTPS id DEE19387087F for ; Sun, 7 Mar 2021 14:05:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DEE19387087F X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from platinum.fritz.box ([217.11.147.117]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LZvw5-1m29oM05VN-00loGn for ; Sun, 07 Mar 2021 15:04:59 +0100 Date: Sun, 7 Mar 2021 15:04:58 +0100 From: Alexander Motzkau To: gcc-help@gcc.gnu.org Subject: Re: Question about -Wstrict-overflow=2 Message-ID: <20210307140458.GA6897@platinum.motzkau> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <73a14b39-fca0-0b2a-d31c-942658e8940a@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Provags-ID: V03:K1:3uL01XNtpM2nOIlgtWQJkkuDrohTZM/G0TnBPeOmLWu0iCN4jYZ nMJOerVwRUnyvd+QFL9o3anGFTqvCFqek4AfW5zwlPlGhBjM4zMY0bKNs7DtqVIQwoONlY1 uV53RcFmsntSgwjn6jU6zzXSWVsqrZ87lD6hOg0Q3aGGxTXfxLyqKztpd1Lyr0TyHgOEqQa EsXhLQeZGDmJuY9FYfE0g== X-UI-Out-Filterresults: notjunk:1;V03:K0:pn7iEw/uIdU=:BYLc8kN5hAzJhrwEYnz5Jz DW6uyCD9qO7ZWKRC/Ga19xwu26WA70aT20u/g5Hz5xP1wupjFCQqkWD8+YY6yRrTKEbr4blEa rCpzWLfwOKGchDBpS8rpfRCbbOFgI56pqbs4SCTVbrc6ZhrAifCxDkA5XzZ6kOayj9a1VVwuZ bXa5XViVFJK56ZofyqOgLdOKyjHUJO7fGdgzcq8knh54GbyiME9AU2glI+6H1tnWclkHARtOv ipD2a3C+7AJG+uAuTnat3sXTzZV7fDG12kekpWzqAAZOTPedj5O9pB/pwCBSZKIVLRN85som+ s6e0Op9vyI54YUemJ/Yig84cb23QWz3mJFHrYi5J1ITdnK3trBMUQbT2duR64LAIDqxLi3ajj 7twvTASUTacA4ceMKgSaOBaajGrPiIW4FGWfNK7QYuyuqD6/QjhBXBK9aI8os0JixbpgwSeQb WkoJZe1ovhBp3Diq1s6YM/cOAT0c8we8oojQ23FQ8Wm7c+nPAqJRoolYZH46ye+rx5ZKNcWuW PYow+A3H+Zo8BTDpyldtw2mZVzIG4oGUIDlU7F4F2qU2LZ/MSHz/9rgbtORYttxHbOVRxwHpO Iy+Ld4k0bkTzLc2tWLS1b2MUMsYZf/sp9pfijBXGhZX/NUmhJudY8hlwsbVLnpwXIugx1qTYc QnTvetA8fKDePynPj7ztKcChOz6wZkjzvDIO0jox/k3T/dEma7PSaI5AjToMIeP+9hhBYdyN3 r1lzLi+FT7ELcMZlEyoGdcB+sfjMltMAzxvfn/0dkrVwRv+Tpks1GW2qGsI/Cqz9TjyMwxFJx 9da2gn7QjJbg1VvxbT3b1OzcqfOwNK/6u+sjg6wNxnf+ebpgBjJj1GpmXUoF0m4bEeJyRy+vd fD8ioaSTowZNxj5TFKeg== Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FAKE_REPLY_C, FREEMAIL_FROM, KAM_NUMSUBJECT, 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 14:05:02 -0000 Andrew Haley wrote: > -Wstrict-overflow=3D2 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() If this is the case I can see the merit of the warning, because that can b= e reduced to 120 > 0, which is a constant. But my problem ist, that I don't see where this expression comes from? The condition in question is argptr >=3D endbuf which can be written as expbuf + i >=3D expbuf + 120 which can be reduced to i >=3D 120 which is not a constant, and therefore not a cause for this warning. This could get constant if gcc does some loop unrolling, for the first loo= p this would result in the expression you quoted. But then I would have hope= d that gcc doesn't warn about constants or dead code when unrolling a loop, because they naturally happen then. And I can't do anything against it except unrolling manually and this would make it less readable. > I doubt that it ever was. -Wstrict-overflow=3D2 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. If an originally non-constant if-expression is reduced to a constant one that is for me something to worry about, where a warning/error is appropriate. It means that the following block is always or never executed= , something the programmer usually didn't intend, otherwise he wouldn't have written the if-condition. And this reduction to a constant is what differentiates -Wstrict-overflow= =3D2 from -Wstrict-overflow=3D3 (according to gcc's documentation). For the lat= er I would accept your description as it being purely informative. > 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. I understand and I welcome better analysis and optimization techniques. And I changed several parts due to new warnings. But in this case I don't see any possibility that wouldn't make the code worse except deactivating the warning. Which is sad and normally beside the point of a warning. Thank you for your patience and best regards, Alex