http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60165

--- Comment #7 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Jakub Jelinek from comment #6)
> How can the compiler know that fn2 never returns 0, without inlining (not in
> this case), some attribute (not provided, gcc right now has returns_nonnull
> attribute but that is only for pointers) or some interprocedural analysis)?

It doesn't know with -O3, but it doesn't know either with -O2 as well. That's
my point (see below).

> For -O2 we don't warn, because then the compiler does see an opaque call
> that might be initializing what the arguments points to, might not, but
> warning in that case would just mean too many false positives as I've said
> before.

I think it should. Or you should avoid the false positives with -O3 too.

> Of course, if fn2 is guaranteed to return non-NULL, why do you even write if
> (fn2 (a, 0)) *p1 = b; rather than just
> fn2 (a, 0); *p1 = b; ?

That's because of creduce. But it seems that I've managed to make the warning
disappear with both -O2 and -O3 even when it is clear that the value is not
initialized. More later...

Reply via email to