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

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
The Asan warning is much clearer because it's based on actually observed
values.  This instance of the -Wrestrict warning is based on a heuristic: "we
think the copy may overlap because it is within the same object and we can't
prove that the offsets and the size assure it doesn't happen."

There may be a way to reword the warning to make things a little bit clearer
but I don't think we can match the Asan form.  When the offsets and the size
are completely unbounded we could just avoid printing them altogether.  That
would make it:

  'strcpy' accessing the same array may overlap [-Werror=restrict]

When the size is known it would give us:

  'strcpy' accessing N bytes of the same array may overlap [-Werror=restrict]

and when the offsets are known but the size isn't:

  'strcpy' accessing the same array at offsets [O1, O2] and [O3, O4] may
overlap [-Werror=restrict]

and so on.

There are many forms of the -Wrestrict warning already: singular size (1 byte)
vs plural size (bytes) vs closed range (between X and Y bytes) vs open range (X
or more bytes), constant offsets vs closed ranges ([X, Y]), definitely overlaps
vs may overlap, and others, and because of internationalization most have to be
hardcoded and can't be easily parameterized, so adding a new form into the mix
isn't completely straightforward.

Reply via email to