https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103827
Bug ID: 103827 Summary: function which takes an argument via (hidden) reference should assume the argument does not escape or is only read from Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: alias, missed-optimization Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: #include <string> extern void foo (const std::string ); void bar () { foo ("abc"); foo (std::string("abc")); } ---- CUT ---- Right now we get: MEM[(struct _Alloc_hider *)&D.33220]._M_p = &D.33220.D.26223._M_local_buf; __builtin_memcpy (&D.33220.D.26223._M_local_buf, "abc", 3); D.33220._M_string_length = 3; MEM[(char_type &)&D.33220 + 19] = 0; foo (&D.33220); <bb 6> [local count: 1073741824]: _5 = D.33220._M_dataplus._M_p; if (&D.33220.D.26223._M_local_buf != _5) But the address of what was passed to foo cannot escape and foo cannot change the content of D.33220. So the read of D.33220._M_dataplus._M_p should always return &D.33220.D.26223._M_local_buf.