[Bug tree-optimization/84474] Unexpected -Wstringop-truncation on strncpy with string literal
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Feb 20 03:21:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84474
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |RESOLVED
CC| |msebor at gcc dot gnu.org
Resolution|--- |WONTFIX
Summary|Unexpected |Unexpected
|-Wstringop-truncation |-Wstringop-truncation on
| |strncpy with string literal
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
This is among the unavoidable cases I was referring to in bug 84468. The
strcpy call with constant arguments is folded into memcpy too early to see the
subsequent assignment of the NUL. I argued to defer this early folding because
it tends to defeat downstream optimizations but I lost.
I would make the argument (and have) that in the test case, strncpy is being
misused and strcpy (or other string functions if strcpy is not acceptable)
would be more appropriate.
If you have a test case with the inlining please open a new bug. It may not
get fixed for GCC 8 but it might serve as an argument for deferring folding
these calls until more context is available, or for other solutions.
More information about the Gcc-bugs
mailing list