https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88971
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-09-05 Status|UNCONFIRMED |NEW CC| |marxin at gcc dot gnu.org Ever confirmed|0 |1 Component|middle-end |ipa --- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is just an inlining problem: #include <iostream> #include <string> struct Data { int i; int j; }; class Test { public: template <typename T> void CheckAndPrint(const T &t); }; template <typename T> inline void Test::CheckAndPrint(const T &t) { asm volatile ("mfence" ::: "memory"); if (t.j > 0) { std::string a = "<"; std::string b = "<"; } asm volatile ("mfence" ::: "memory"); } int main() { Data data; std::cin >> data.i; std::cin >> data.j; Test t; t.CheckAndPrint(data); return 0; } ------- CUT ---- If we get rid of one of the std::string in Test::CheckAndPrint, we are able to inline the constructor (std::__cxx11::basic_string<char>::basic_string<> ) and everything goes away. One thing I noticed is: <bb 3> [local count: 1073612976]: _24 = __builtin_strlen (__s_7(D)); ... if (_24 > 15) I wonder if we could have an IPA pass which clones this function based on the strlen that gets pass to the second argument and such.