https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105453
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #1) > There is no issue here as there is no atomic barrier as required by the c11 > and c++11 standards in their memory model I agree that GCC's output is allowed by the memory model. If another thread is changing either of those globals then func_1 needs to be synchronised with it to avoid data races, i.e. it would have undefined behaviour anyway, whatever code GCC generated.