On 2/4/20 2:34 AM, Richard Biener wrote:
On Tue, Feb 4, 2020 at 1:44 AM Martin Sebor <mse...@gmail.com> wrote:

PR 93519 reports a false positive -Wrestrict issued for an inlined call
to strcpy that carefully guards against self-copying.  This is caused
by the caller's arguments substituted into the call during inlining and
before dead code elimination.

The attached patch avoids this by removing -Wrestrict from the folder
and deferring folding perfectly overlapping (and so undefined) calls
to strcpy (and mempcpy, but not memcpy) until much later.  Calls to
perfectly overlapping calls to memcpy are still folded early.

Why do we bother to warn at all for this case?  Just DWIM here.  Warnings like
this can be emitted from the analyzer?

That is, I suggest to simply remove the bogus warning code from folding
(and _not_ fail the folding).

The overlapping copy is ultimately folded into a no-op but the warning
points out that code that relies on it is undefined.  The code should
be fixed.  This is in line with one of the strategies we discussed and
(at least those of us in the room) agreed on for undefined behavior
back in Manchester: try to do the least harm but warn.

Martin

Reply via email to