This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/84468] [gcc 8] Inconsistent -Wstringop-truncation warnings with -O2


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) ?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]