[Bug c++/103534] [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Dec 10 16:53:38 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103534

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
We discussed before (e.g., in PR 93971) the idea of annotating std::string with
some attribute telling the optimizer the internal pointer doesn't alias with
anything except for the this->_M_local_buf or the result of operator new(). 
Richi seemed open to it but was concerned about correctness.

I'm experimenting with two things to improve the context of all these warnings.
 One is to print the folded condition under which the warning triggers.  This
would include the conditions involved in all the ranges used to make decisions.
 I posted the result for this warning here (I'm not sure it's complete, it's
just a POC):

  https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586524.html

Another is to print the path through the code (the CFG actually) leading up to
the warning site, like the static analyzer does.  This will show each
GIMPLE_COND after optimization, so it won't correspond exactly to the original
source.  For libstdc++ code it will show libstdc++ internal conditions that may
not be of much use to users.  I'll have to see how bad it is to decide if it's
a viable approach.


More information about the Gcc-bugs mailing list