https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122610
--- Comment #6 from Alan Wu <gcc at alanwu dot email> --- On 16, just -O1 is enough to show the issue with code from comment #5. Issue goes away with -fno-ipa-pure-const. Looks like ipa-pure-const runs before ipa-modref, and makes the first mistake: local analysis of RSTRING_PTR/4 scanning: D.3009 = rbimpl_rstring_getmem (str_2(D)); [return slot optimization] scanning: _4 = D.3009.as.heap.ptr; scanning: return _4; Function is locally const. Compiler Explorer: https://godbolt.org/z/YfEToPddh
