Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1349201

Re: Q: why didn't GCC warn about this uninitialized variable? (was: Re: [PATCH] perf tests: initialize sa.sa_flags)

From Jakub Jelinek <jakub@redhat.com>
Newsgroups linux.kernel
Subject Re: Q: why didn't GCC warn about this uninitialized variable? (was: Re: [PATCH] perf tests: initialize sa.sa_flags)
Date 2016-03-03 15:20 +0100
Message-ID <r8CgH-8cy-33@gated-at.bofh.it> (permalink)
References (4 earlier) <r8f0K-89o-15@gated-at.bofh.it> <r8Aoy-6Zk-9@gated-at.bofh.it> <r8B1g-7eH-1@gated-at.bofh.it> <r8Buj-7F8-15@gated-at.bofh.it> <r8BNE-7MX-29@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Mar 03, 2016 at 02:47:16PM +0100, Ingo Molnar wrote:
> I tried to distill a testcase out of it, and the following silly hack seems to 
> trigger it:

...

This is a known issue, which we don't have a solution for yet.
The thing is, GCC has 2 uninitialized warning passes, one is done
very early, on fairly unoptimized code, which warns for -O and above
only about must be uninitialized cases in code that is executed
unconditionally (if the containing function is executed, and doesn't
have PHI handling code), and then a very late uninitialized pass,
that warns also about maybe-uninitialized cases, has predicate aware
handling in it, etc.; but this warns only about the cases where the
uninitialized uses survived through the optimizations until that phase.
In the testcase, the conditional uninitialized uses got optimized away,
passes seeing that you can get alt_idx initialized say to 2 from one branch
and uninitialized from another one just optimize it into 2.
Warning right away at that spot when the optimization pass performs this
might not be the right thing, as it could warn for stuff in dead code,
or couldn't be backed up by the predicate aware uninit analysis which is
costly and couldn't be done in every pass that just happens to optimize away
some uninitialized stuff.  Not to mention that it doesn't have to be always
even so obvious to the optimizing pass.  Say, when computing value ranges,
the uninitialized uses should be ignored, because they can't be used in
valid paths, so if say you have value range [2, 34] from one branch and
uninitialized use from another branch, the resulting value range will be
[2, 34].  Then later on, you just optimize based on this value range and
perhaps the uninitialized use will go away because of that.
We could handle the uninitialized uses pessimistically, by not optimizing
PHI <initialized_2, uninited_3(D)> into just initialized_2, etc., by
considering uninitialized uses as VARYING ([min, max] range) rather than
something that doesn't happen, etc., and then the late uninitialized pass
would warn here.  But then we'd trade the warning for less optimized code.
GCC is primarily an optimizing compiler, rather than static analyzer, so
that is why GCC chooses to do what it does.  Do you want us introduce
-Ow mode, which will prefer warnings over generated code quality?

BTW, as for false positives and new warnings, my experience is that
in the kernel generally such warnings are just disabled, even if they
helped discover severe errors in other packages.

	Jakub

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] perf tests: initialize sa.sa_flags Colin King <colin.king@canonical.com> - 2016-03-02 14:00 +0100
  Re: [PATCH] perf tests: initialize sa.sa_flags Peter Zijlstra <peterz@infradead.org> - 2016-03-02 14:00 +0100
    Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:10 +0100
      Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:30 +0100
        Q: why didn't GCC warn about this uninitialized variable? (was: Re:  [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 13:20 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? Colin Ian King <colin.king@canonical.com> - 2016-03-03 13:30 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? Måns Rullgård <mans@mansr.com> - 2016-03-03 13:40 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? Joe Perches <joe@perches.com> - 2016-03-03 13:50 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? Ingo Molnar <mingo@kernel.org> - 2016-03-03 13:50 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 14:00 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 14:30 +0100
              Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 14:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 15:20 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 15:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 16:00 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 16:10 +0100
              Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 14:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 15:10 +0100
      Re: [PATCH] perf tests: initialize sa.sa_flags Peter Zijlstra <peterz@infradead.org> - 2016-03-02 14:30 +0100
  Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:10 +0100

csiph-web