在 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


If we insist on use of `volatile` I'd expect the pointer itself is volatile:

    char * volatile p = NULL;


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to