This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84468] [gcc 8] Inconsistent -Wstringop-truncation warnings with -O2
- From: "romain.geissler at amadeus dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 19 Feb 2018 22:01:39 +0000
- Subject: [Bug tree-optimization/84468] [gcc 8] Inconsistent -Wstringop-truncation warnings with -O2
- Auto-submitted: auto-generated
- References: <bug-84468-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468
--- Comment #3 from Romain Geissler <romain.geissler at amadeus dot com> ---
Ok there maybe a problem with the optimizer as you describe it in bug 84470.
However why does variant 3 from comment #0 yields a warning too ?
if (iCString)
{
strncpy(_cstring, iCString, 3);
_cstring[3] = '\0';
}
_cstring[3] = '\0';
It is because the optimizer finds out that "_cstring[3] = '\0';" is both in the
"if branch" and also after, thus eliminates the one from the "if branch", then
the strncpy silencing warning mechanism doesn't work properly anymore ? I don't
know very well what is the internal gcc IR, but do you think it would be
possible to go beyond branches and basic block separation to find out that the
next statement in
if (iCString)
{
strncpy(_cstring, iCString, 3);
}
_cstring[3] = '\0';
really is "_cstring[3] = '\0';" (ie crossing basic block boundaries) ?