This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Resurrecting -Wunreachable
- From: Florian Weimer <fweimer at redhat dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC <gcc at gcc dot gnu dot org>
- Date: Wed, 07 May 2014 14:28:46 +0200
- Subject: Re: Resurrecting -Wunreachable
- Authentication-results: sourceware.org; auth=none
- References: <5368ED25 dot 7090901 at redhat dot com> <CAFiYyc0+1TwHdez4hiop=PVyebTArswFKfebDPwAn_xpoad=qQ at mail dot gmail dot com> <536A1F83 dot 5050703 at redhat dot com> <CAFiYyc3U8SjqBFcEf9WKTyi3r1rmLdEagL=q=DJk65fHMS9iKg at mail dot gmail dot com> <536A2213 dot 9020104 at redhat dot com> <CAFiYyc3CUivZGc+fmZqMuYLPbNjA0t0HS5mRbEap3J8GuTWobg at mail dot gmail dot com>
On 05/07/2014 02:11 PM, Richard Biener wrote:
Precisely. But optimizing this:
int main()
{
if (0)
foo ();
else
throw std::logic_error ("error");
bar ();
}
to:
int main()
{
throw std::logic_error ("error");
bar ();
}
would cause the code to issue such unwanted warnings. That's why I need
access to these trivial if statements.
I don't think it would. bar () would be gone already as throw doesn't return.
Fair point. So here's a different example:
int main()
{
if (0)
foo ();
else
throw std::logic_error ("always reachable");
throw std::logic_error ("maybe reachable (no warning)");
throw std::logic_error ("not reachable, warning required");
}
I think this also applies to other warnings such as missing null pointer
checks. We still want to report them for code unreachable after (some)
optimization, just like we report type errors there.
The more challenging issue with early GIMPLE is that loops have already
been lowered to gotos, so adopting the syntax-based Java reachability
rules is impossible. Oh dear.
--
Florian Weimer / Red Hat Product Security Team