https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100402
Bug ID: 100402 Summary: Crash in longjmp Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: ssbssa at yahoo dot de Target Milestone: --- The following example: ---------------------------------- >8 -------------------------------------- // gcc -O1 test.c #include <setjmp.h> static jmp_buf buf; static bool stop = false; void call_func(void(*func)(void)) { func(); } void func() { stop = true; longjmp(buf, 1); } int main() { setjmp(buf); while (!stop) call_func(func); return 0; } ---------------------------------- >8 -------------------------------------- Crashes deep in longjmp(): Starting program: C:\src\tests\a.exe gdb: unknown target exception 0xc0000028 at 0x779dd7e8 Program received signal ?, Unknown signal. 0x00000000779dd7e8 in ntdll!RtlRaiseStatus () from C:\Windows\SYSTEM32\ntdll.dll (gdb) bt #0 0x00000000779dd7e8 in ntdll!RtlRaiseStatus () from C:\Windows\SYSTEM32\ntdll.dll #1 0x000000007797f4ec in ntdll!RtlIsDosDeviceName_U () from C:\Windows\SYSTEM32\ntdll.dll #2 0x000007fefe11e5a3 in msvcrt!longjmp () from C:\Windows\system32\msvcrt.dll #3 0x000000013fe61620 in func () #4 0x000000013fe61627 in call_func () #5 0x000000013fe61664 in main () #6 0x000000013fe61431 in __tmainCRTStartup () at C:/gcc/src/mingw-w64-v8.0.0/mingw-w64-crt/crt/crtexe.c:345 #7 0x000000013fe615b6 in mainCRTStartup () at C:/gcc/src/mingw-w64-v8.0.0/mingw-w64-crt/crt/crtexe.c:220 Note: Doesn't crash with -O0, or if I change `while (!stop)` to `if (!stop)`. And it also works fine with gcc-10.2, or if I revert both fixes [1] [2] of PR99234. [1] https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=49a714e59194a7c549aa6657676a1b4be4520650 [2] https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=2939b358936bb824330888def98ad848dea41483