This was reported in RHBZ #1796688 (and previously for memcpy in bug 83456). The warning is obviously incorrect here:
static char *
str_numth(char *dest, char *num, int type)
if (dest != num)
DCH_to_char(char *in, char *out, int collid)
char *s = out;
str_numth(s, s, 42);
$ gcc -Wall -c -O2 wtest.c
wtest.c: In function 'DCH_to_char':
wtest.c:7:3: warning: 'strcpy' source argument is the same as destination [-Wrestrict]
7 | strcpy(dest, num);
Started with r8-5363-gcc8bea0aeeeeb6ed8046ede1a577ee681da2ca6a
I'd say the bug is in trying to do this from whenever we try to fold such a call, because there is no way to cleanup the cfg after inlining before it happens.
So, it would be much better to do this only in specific well chosen passes, say one among early opts, but sufficiently after einline so that unreachable code there could be optimized away, and once or twice in late opts.
The overlapping arguments is UB, so I don't really think it is neccessary to fold it immediately.
Another option is to turn it into IFN_WARNING and defer the diagnostics after some cleanups.
Fixed on trunk sofar.
The master branch has been updated by Richard Guenther <email@example.com>:
Author: Richard Biener <firstname.lastname@example.org>
Date: Fri Feb 7 12:56:18 2020 +0100
middle-end/93519 - avoid folding stmts in obviously unreachable code
The inliner folds stmts delayed, the following arranges things so
to not fold stmts that are obviously not reachable to avoid warnings
from those code regions.
2020-02-07 Richard Biener <email@example.com>
* tree-inline.c (fold_marked_statements): Do a PRE walk,
skipping unreachable regions.
(optimize_inline_calls): Skip folding stmts when we didn't
* gcc.dg/Wrestrict-21.c: New testcase.
GCC 8.4.0 has been released, adjusting target milestone.
GCC 8 branch is being closed.
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Fixed in GCC 10.