[Bug tree-optimization/119148] Inconsistent -Wstringop-truncation warning when using strncpy
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 7 08:11:19 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119148
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2025-03-07
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The diagnostic says that the copy truncates "123456" which is true. The
diagnostic is emitted via gimple_fold_builtin_strncpy during CCP.
The difference seems to be that in once case we succeed in hitting
/* Look for dst[i] = '\0'; after the stxncpy() call and if found
avoid the truncation warning. */
gsi_next_nondebug (&gsi);
gimple *next_stmt = gsi_stmt (gsi);
if (!next_stmt)
but in the other case not because in one case we have
arr[l_5] = 0;
but in the other
_1 = ptr_7 + l_6;
*_1 = 0;
the code should possibly skip a stmt computing an offset but then it
would need to do more analysis on the deref.
The issue is we fold this quite early and CCP only substitutes/folds
the following stmts _after_ it, so this code doesn't really work reliably.
More information about the Gcc-bugs
mailing list