https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112783
Xi Ruoyao <xry111 at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |xry111 at gcc dot gnu.org --- Comment #10 from Xi Ruoyao <xry111 at gcc dot gnu.org> --- (In reply to Jiang ChuanGang from comment #9) > I've encountered the same bug, and your solution does fix it. > But strangely enough, I can't reproduce it with code like the following. > The inevitable condition of this bug still puzzles me. Do you have any > thoughts on this. If you invoke an undefined behavior then anything can happen. And the condition is not "inevitable", if you use a different compiler or use different compile options it may change as well. Do not try to predict the outcome of an undefined behavior. If you really want an explanation you can try to trace how the compiler optimizes the program (by adding -fdump-tree-all -fdump-rtl-all and investigating all the dumped files). But such an explanation will only apply for the specific GCC version you are using, with a different GCC release the optimization passes will just change. So I don't think such an explanation will be useful or worth to find out. If you want to catch such bugs more easily try things like -fsanitize=undefined or -fsanitize=address.