From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3F8E8138334 for ; Fri, 14 Sep 2018 23:08:05 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C47D8E0AAD; Fri, 14 Sep 2018 23:08:01 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 75160E0A9C for ; Fri, 14 Sep 2018 23:08:01 +0000 (UTC) Received: from sf (trofi-1-pt.tunnel.tserv1.lon2.ipv6.he.net [IPv6:2001:470:1f1c:a0f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id C5205335D03 for ; Fri, 14 Sep 2018 23:07:58 +0000 (UTC) Date: Sat, 15 Sep 2018 00:07:53 +0100 From: Sergei Trofimovich To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] Changing policy about -Werror Message-ID: <20180915000753.19a8715f@sf> In-Reply-To: References: <20180909143221.21d784d02f51623e8c57c545@gentoo.org> <1536510660.863.9.camel@gentoo.org> <20180910074539.GA6512@baraddur.perfinion.com> <0d8b7f02-9c38-969c-413b-69d4dee6ca89@gentoo.org> <20180912085649.GA16516@baraddur.perfinion.com> <6c18c6bd-4cf3-dff6-2f20-c021063e01fa@gentoo.org> <20180913160347.GC26329@gentoo.org> <4FCF42AC-6B48-40F6-8B98-79CF71789A6A@gentoo.org> <3A8A39E8-91DF-40B2-8958-F046FA58622B@gentoo.org> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archives-Salt: a45dfc76-9292-48ff-8534-bd2738889e14 X-Archives-Hash: 351977a57356586d8048c9cc6c7205e9 On Fri, 14 Sep 2018 11:54:57 -0400 Richard Yao wrote: > >> My read of this is that the warning occurs regardless of optimization level, but it could somehow be improved by optimization. > >> > >> As for the last, it is for uninitialized variable reads. However, I think you are misinterpreting the claim. The way that optimization level could affect warning generation would be if the warning generation came after optimization passes that could hide reads. That means that -O3 would prevent the warning. ... > Either provide code examples that generate warnings in a way that demonstrates that I am incorrect To make code behave differently it needs substantial amount of code to provide you an example. You need to him O2<->O3 behaviour delta after all. But I will try (for a different warning, it should not matter much). Below is a reduced example of a larger C++ program. Many thanks to Ulya for providing recent example! In this example -O3 manages to inline/const-propagate deep enough and find out potential null-deref. -O2 was not able to do it. $ bash -x ./mk_.sh + LANG=C + g++-8.2.0 -O2 -c 1.cc -Wnull-dereference + g++-8.2.0 -O3 -c 1.cc -Wnull-dereference 1.cc: In function 'bool foo(std::vector)': 1.cc:3:22: warning: null pointer dereference [-Wnull-dereference] typename h = e - d >> *g; ~~~~~~^~~~~ 1.cc:3:22: warning: null pointer dereference [-Wnull-dereference] typename h = e - d >> *g; ~~~~~~^~~~~ $ cat 1.cc #include template a c(a d, a e, b f, int *g) { typename h = e - d >> *g; for (; h;) if (f(*d)) if (f(*d)) return d; return d; } template i o(i d, i e, b f, int *g) { return c(d, e, f, g); } template i oo(i d, i e, b f, int *g) { return c(d, e, f, g); } template j k(j d, j e, b f, int *g) { return o(d, e, f, g); } template j kk(j d, j e, b f, int *g) { return oo(d, e, f, g); } bool cmpp(int); bool foo(std::vector l) { std::vector::const_iterator ib, ie = l.end(), m, n = k(ib, ie, cmpp, 0) = kk(m, ie, cmpp, 0); return m == n; } -- Sergei