https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101830

--- Comment #4 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Bill Schmidt from comment #0)
> (1) linebuf and pos are global variables, and the compiler cannot tell
> whether or not there are problems with array bounds accesses here. Indeed,
> pos is only incremented by a function called "safe_inc_pos" that ensures we
> *don't* ever access beyond the end of linebuf.

Most warnings are heuristic, largely by need, and this is true here as well.
-Werror is a terrible idea.  You can use it during development if you don't
trust the programmers (which might be yourself) will see the messages, but
otherwise it is just a destructive hindrance.  That said...

> (2) The error message is far too certain of itself!  It says that we have
> definitely addressed out of bounds when that is certainly not known to be
> true.

And its language claims it is even more certain that this was linepos+1024,
which you say can never be true?

It is possible there is some other bug in your program, which combined with
aggressive optimisations elsewhere gives the access to that address, but :-/
(Looking at -fdump-tree-all-all dumps should tell).

More likely is the heuristic just gets the wrong result.  This happens so
often that this warning does not belong in -Wall, and not even in -W (since
there is no simple workaround for it at all, not even any reliable
workaround).

And yes, whenever some warning includes any heuristic (i.e. almost all
warnings), the warning message should not say "is wrong".  Diagnostics should
never lie.  Not ever.  This used to be a big strength of GCC's diagnostics.

All such messages should say something like "may be wrong".  This is a much
nicer, more respectful way to talk to the compiler user anyway, even if it
could not be wrong :-)


> This is holding up committing some approved patches, so I appreciate
> anything you can do to sort this out.

Configure with --disable-werror if you want more sanity.  Of course people
will then be angry with you if you commit something that triggers something
bad :-/  Maybe that builds character?

Reply via email to