[Bug c++/124958] GCC 16: wrong code at `-O3` — IPA-SRA-cloned lambda body reads uninitialized stack slot when its captured pointer is `do_not_optimize`-clobbered and the called method has a `pre()` contract precondition

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Apr 21 04:08:38 GMT 2026


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

--- Comment #10 from Drea Pinski <pinskia at gcc dot gnu.org> ---
The reason why this inline-asm is broken:
    asm volatile("" : "+m,r"(p) : : "memory")

Is because it is not what you think it does.

It does:
    asm volatile("" : "+m,r"(p) : "m,0"(p) : "memory");

So it basically does:
  pp = &p;
  __asm__ __volatile__("" : "=m,r" pp : "m,0" &p : "memory");

So it uses a temp for the assignment. While for the rhs it is not a temp.
When the m constraint is choosen then it will be address of pp passed to the
inline-asm and also the address of a temp to &p. There is no restoring of pp
happening.


More information about the Gcc-bugs mailing list