On Wednesday 25 June 2025 19:45:56 LIU Hao wrote: > 在 2025-6-25 16:08, Martin Storsjö 写道: > > The null pointer access in itself is UB, and Clang would previously > > optimize based on that being UB, assuming that that code is > > unreachable, so it would assume that the printf function never > > returns and not generate any code after that call. > > > > Change the pointer into a volatile char, which makes Clang not > > infer things about it in the same way, and actually retain the > > null pointer write. > > > > This fixes hangs in this testcase on armv7 with msvcrt. > > > In order to inhibit this optimization, I think this might be better? > > char *p = NULL; > __asm__ ("" : "+m"(p)); // pretend `p` is being modified
Maybe this could be another trick to prevent compilers doing some optimizations. > > If we insist on use of `volatile` I'd expect the pointer itself is volatile: > > char * volatile p = NULL; > We are dereferencing the pointer, so I think that the pointer value has to be marked as volatile, as Martin did it. But whether the variable (on stack) has to be volatile too, I'm not sure. _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public