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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |12.1.0, 13.0
             Blocks|                            |88443
           Keywords|                            |missed-optimization

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
There have been other reports of false positives due to the same issue (e.g.,
some or all of pr65461, pr92539, pr92955, pr95140, and pr96447).  Since the
unrolling pass uses the invalid access to decide to unroll the loop maybe it
could insert the __builtin_unreachable() call before it (or instead of it)
rather than after it.  That way the bad access would get eliminated and the
warning avoided.  Or, it could, in addition to inserting the
__builtin_unreachable() call after it, also suppress the access warning for the
bad statement.  Alternatively, these problems could be worked around in the
warning code by suppressing it in basic blocks that terminate by a call to
unreachable.  But this would cause false negatives where the unreachable call
is added after real problems in the user's source).

Until this is solved in GCC it can be dealt with in user code by asserting the
loop doesn't iterate more times than there are elements in the array.  In the
test case in comment #5 that might look like so:

  if (n >= sizeof s / sizeof *s)
    __builtin_unreachable ();


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
[Bug 88443] [meta-bug] bogus/missing -Wstringop-overflow warnings

Reply via email to