This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Counter intuitively, asserts hurt gcc static dataflow analysis.
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Mason <slash dot tmp at free dot fr>
- Cc: John Carter <john dot carter at taitradio dot com>, GCC help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 4 May 2018 08:34:40 -0500
- Subject: Re: Counter intuitively, asserts hurt gcc static dataflow analysis.
- References: <CAFD1m3FNaL4_T=hwUSi6Li+8P3+WiV8jL=2H_QuziqsE2MX6Ug@mail.gmail.com> <da589209-ee80-5135-1b63-103f4ebaabf2@free.fr>
On Fri, May 04, 2018 at 03:16:14PM +0200, Mason wrote:
> On 04/05/2018 01:03, John Carter wrote:
>
> > But compile with ...
> > gcc -O3 -W -Wall -Wextra -o a a.c
> > ...now results in NO warnings!
> >
> > ie. Although gcc _knows_ the assert _will_ trigger at run time... it can't
> > tell me at compile time anymore.
> >
> > ie. Counter intuitively, adding asserts and error checks to my code has
> > made me less safe.
>
> In the first version, gcc inlines the function call, which enables
> further analysis. In the second version, the assert() call makes
> gcc decide not to inline the function call, thus later analysis passes
> are no longer able to spot the out-of-bounds access.
No, that's not it. In the second version there *is* no out of bounds
access!
Segher