From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23082 invoked by alias); 28 Oct 2016 08:12:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 23073 invoked by uid 89); 28 Oct 2016 08:12:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 spammy=indicator, H*r:0200, H*RU:sk:mrelaye, H*r:sk:mrelaye X-HELO: mout.kundenserver.de From: Arnd Bergmann To: libc-alpha@sourceware.org Cc: Jeff Law , Florian Weimer , Carlos O'Donell Subject: Re: [PATCH] Fix -Os related -Werror failures. Date: Fri, 28 Oct 2016 08:12:00 -0000 Message-ID: <20863164.XNWC5rYB1g@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <9d58289e-07fb-4bae-d7d3-8055a6c96a3a@redhat.com> References: <6eac682f-26fa-6a47-9497-357206266ba1@redhat.com> <6be7dce5-bfa7-32c7-5bac-6c3b79776683@redhat.com> <9d58289e-07fb-4bae-d7d3-8055a6c96a3a@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-UI-Out-Filterresults: notjunk:1;V01:K0:mUppjSrDg98=:5wI1Xu9gCC/D2lEgFSyh2J tRwLWR353PZeCBVo7dEBf/1GUXb3fTK0w6o9g8mWXXTAY1SqDXjqsuKdTo4NVNkXWHlTCOt9d /aF6ewSL3RBylHB6BEmiskhYSYGInEWgftR8KurKiNBS0bz4K1l3/jybouG7Xs1x9BVKzoIHW nm/2r8mCKg8D4IaWIkNddvl38FFalo8d4SyLbEZAgQ8f6LguLfy4aBWAVaCVZexkkMwa3TBON EkLACZEY8bE356LVDpYQpzUao16qM9o1jsiEFjSind+uvtiQE30ZmyqpoV+c1ZttbyO7jLky0 sS+xhp4UxLzT5ir/MWta4GVYkpmc1ZqD9J3WCXu2lR4MtI9x0xfNW0U3oVvdTB8HxXtsWfnnx hIEVpenpHPPqHEpDY74aKMX8BFH5iUqwEYp8965fURKi99m7JJozsXlZmAcPDj1vWVbeEiaoo UvNikrwBZTx/cUjrWTKDh7CfFK2aJ/ZYNChjgIa2jHwXY41BdBKGapAFLwX7lUXu4CKypi6PA mkUen/tgDpWJM/6SGz9J+4Hu+uvoU81x7TA5DECjP8gqz2+NyMl/Ic61vq89iueV5cymNnDau eUQlrok1k8OCB7ZkzpPt0+xFYirViM49lwrhIbL+0jzUETqg4K9LBFLkEWMsOiXkEKwuH43dn 3U5JXNNZjtpINoVQBmwd/70/x6ImneCMBDVXNTfy0O39cYEp+T7ZitOGqZmAEi7CUeL3C2KTw PpSJZBxmbk9/43dh X-SW-Source: 2016-10/txt/msg00511.txt.bz2 On Friday, October 28, 2016 12:44:32 AM CEST Jeff Law wrote: > On 10/28/2016 12:32 AM, Florian Weimer wrote: > > On 10/28/2016 06:46 AM, Carlos O'Donell wrote: > >> +/* With GCC 5.3 when compiling with -Os the compiler emits a warning > >> + that buf[0] and buf[1] may be used uninitialized. This can only > >> + happen in the case where tmpbuf[3] is used, and in that case the > >> + write to the tmpbuf[1] and tmpbuf[2] was assured because > >> + ucs4_to_cns11643 would have filled in those entries. The difficulty > >> + is in getting the compiler to see this logic because tmpbuf[0] is > >> + involved in determining the code page and is the indicator that > >> + tmpbuf[2] is initialized. */ > >> +DIAG_PUSH_NEEDS_COMMENT; > >> +DIAG_IGNORE_NEEDS_COMMENT (5.3, "-Wmaybe-uninitialized"); > > > > This hides the warning for -O2 builds as well, so I don't think this is > > a good idea. > > > > Those who want to build with -Os or other special compiler flags should > > just configure with --disable-werror. We can't account for every > > optimization someone might want to disable in their build. > That'd be my recommendation. > > What often happens in these cases is the compiler in its default mode of > operation is able to statically eliminate a conditional branch on a > particular path. However, to do so the compiler has to duplicate code. > > Not surprisingly, there's a cost/benefit tradeoff here and the > heuristics are largely driven by the real or estimated profile data as > well as the coarser "optimize for code space". So changing flags > changes the output of those heuristics and ultimately can result in > leaving paths in the CFG that can not be executed -- and that often > leads to false positive may-be-uninitialized warnings and such. > > Long term I would like to find a good way to mark paths that are not > executable, but are not profitable to eliminate, then utilize that > information to prune various "may" warnings. That would make those kind > of warnings more stable across different optimization levels as well as > more stable release-to-release. But that's definitely in the "future > work" area. I've spent a lot of time trying to eliminate -Wmaybe-uninitialized warnings from the Linux kernel. Here are some data points that you may find useful too: - Building with -Os causes many false positives starting with gcc-4.9, and I have disabled the warning for this specific flag. I believe this is due to the lack of the "-fschedule-insns" optimization step - Building with -O3 apparently also causes some false positives, but we don't normally do that in the kernel, and the only architecture port that does it also disables the warnings - Two more gcc options that cause false positives are -fprofile-arcs and some of the -fsanitize=... options - overall, gcc-4.9 improved much over gcc-4.8 in these warnings, but they have a different set of false-positives. As gcc-4.8 is getting old, I'm pushing a patch to also disable the warning for all 4.8 builds. Prior to v4.8, there was no option to disable maybe-uninitialized warnings. - gcc-5 and gcc-6 appear to be slightly better than gcc-4.9 but also introduce a small number of additional false-positive warnings, apparently this happens mostly because they make different inlining decisions, not because something fundamentally changed. Generally speaking, if any of 4.9, 4.x or 5.x produce a warning in some configurations, it's likely that the other ones will do the same, depending on a combination target architecture and optimization flags that impact inlining. - I found that most often when gcc is confused about whether a variable is uninitialized or not, the source code tends to be confusing to a human reader as well and rewriting it differently results in better readability and better object code while avoiding the warning. There are always other cases in which this is not possible though. Arnd