public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: GNU C Library <libc-alpha@sourceware.org>,
	Jeff Law <law@redhat.com>,  Florian Weimer <fweimer@redhat.com>,
	"Carlos O'Donell" <carlos@redhat.com>
Subject: Re: [PATCH] Fix -Os related -Werror failures.
Date: Fri, 28 Oct 2016 08:17:00 -0000	[thread overview]
Message-ID: <CA+=Sn1nbuq-BEMu5Xyz6m=t71WQ2YAX6U3mpkn7je1rzB7VKUw@mail.gmail.com> (raw)
In-Reply-To: <20863164.XNWC5rYB1g@wuerfel>

On Fri, Oct 28, 2016 at 1:12 AM, Arnd Bergmann <arnd@arndb.de> wrote:
> 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

No this is false.  It is usually due to jump threading is not as
aggressive at -O2 than -Os due to -Os not wanting to increase code
size.

Thanks,
Andrew

> - 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

  reply	other threads:[~2016-10-28  8:17 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-28  4:48 Carlos O'Donell
2016-10-28  6:25 ` Andreas Schwab
2016-10-28  6:32 ` Florian Weimer
2016-10-28  6:44   ` Jeff Law
2016-10-28  8:12     ` Arnd Bergmann
2016-10-28  8:17       ` Andrew Pinski [this message]
2016-10-28 13:28         ` Jeff Law
2016-10-28 20:10       ` Paul Eggert
2016-10-29  3:03         ` Jeff Law
2016-10-30  4:25           ` Paul Eggert
2016-10-28 12:09   ` Carlos O'Donell
2016-10-28 12:43     ` Florian Weimer
2016-10-28 13:04     ` Joseph Myers
2016-10-28 13:07     ` Carlos O'Donell
2016-10-28 12:49   ` Joseph Myers
2016-10-28 12:55     ` Florian Weimer
2016-10-28 13:18       ` Carlos O'Donell
2016-10-28 13:58         ` [PATCH v2] Fix -Os related build and test failures Carlos O'Donell
2016-10-28 14:17           ` Joseph Myers
2016-10-29  2:59             ` [PATCH v3] " Carlos O'Donell
2016-10-29  3:26               ` Carlos O'Donell
2016-10-29 17:35               ` Joseph Myers
2016-10-30  3:51                 ` [PATCH v4] " Carlos O'Donell
2016-10-31  8:33                   ` Andreas Schwab
2016-10-31  9:16                     ` Carlos O'Donell
2016-10-31  9:22                       ` Florian Weimer
2016-10-31 12:56                       ` David Miller
2016-10-31 19:56                         ` Carlos O'Donell
2016-11-01 22:59                           ` Joseph Myers
2016-11-02 12:52                             ` Carlos O'Donell
2016-11-01  9:17                   ` Andreas Schwab
2016-11-01 11:13                     ` Joseph Myers
2016-11-01 15:58                       ` Tamar Christina
2016-11-01 16:06                         ` David Miller
2016-11-01 16:15                           ` Tamar Christina
2016-11-02 11:53                           ` Carlos O'Donell
2016-11-02 17:03                             ` Carlos O'Donell
2016-11-02 13:22                       ` Carlos O'Donell
2016-10-31 18:38               ` [PATCH v3] " Steve Ellcey
2016-10-31 19:50                 ` Carlos O'Donell
2016-10-31 19:57                   ` Steve Ellcey
2016-10-31 20:50                     ` Carlos O'Donell
2016-10-31 21:00                       ` Steve Ellcey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+=Sn1nbuq-BEMu5Xyz6m=t71WQ2YAX6U3mpkn7je1rzB7VKUw@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=arnd@arndb.de \
    --cc=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=law@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).