https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107840
Bug ID: 107840 Summary: ICE when compiling cursed setjmp/longjmp that uses __builtin_call_with_static_chain Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- typedef __UINT16_TYPE__ uint16_t; typedef __UINT32_TYPE__ uint32_t; typedef __INTPTR_TYPE__ intptr_t; #define unreachable __builtin_unreachable typedef struct{ const uint16_t mov1; const uint32_t addr; const uint16_t mov2; const void * const chain; } __attribute__((packed)) thunk_struct; #define NESTED_CHAIN(p) ({ \ thunk_struct *__t = (void*)p; \ __t->chain; \ }) #define NESTED_ADDR(p) ({ \ auto __p = (p); \ thunk_struct *__t = (void*)__p; \ (typeof(__p))(intptr_t)__t->addr; \ }) #define NESTED_UPGRADE(self, ptr, args) ({ \ if(self != ptr) \ __builtin_call_with_static_chain( \ NESTED_ADDR((typeof(self)*)ptr) args, \ NESTED_CHAIN(ptr) \ ); \ }) typedef struct{ // can't apply standard [[noreturn]] to function pointers [[gnu::noreturn]] void(*fun)(void*, int); }xjmp_buf[1]; #define xsetjmp(env) ({ \ __label__ trgt; \ int __xsetjmp_ret = 0; \ [[noreturn]] void __jmp(void *self, int r){ \ NESTED_UPGRADE(__jmp, self, (self, r)); \ __xsetjmp_ret = r ?: 1; \ goto trgt; \ } \ env[0].fun = __jmp; \ trgt:; \ int tmp = __xsetjmp_ret; \ __xsetjmp_ret = 0; \ tmp; \ }) [[noreturn, gnu::always_inline]] inline void xlongjmp(xjmp_buf env, int r){ ((void(*)(void*, int))NESTED_ADDR(env[0].fun))(env[0].fun, r); unreachable(); } int main(){ int a = 0; xjmp_buf test; void foo(xjmp_buf ctx){ if(!xsetjmp(ctx)){ (volatile void)0; } } foo(test); xlongjmp(test, ++a); } Compiling this code with `-std=c2x` results in the following error: <source>: In function 'foo': <source>:60:14: error: label '({anonymous})' has incorrect context in bb 4 60 | void foo(xjmp_buf ctx){ | ^~~ during GIMPLE pass: cfg dump file: /app/output.c.015t.cfg <source>:60:14: internal compiler error: verify_flow_info failed 0x2008dee internal_error(char const*, ...) ???:0 0xaf90d7 verify_flow_info() ???:0 0x10447c7 cleanup_tree_cfg(unsigned int) ???:0 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. Compiler returned: 1 (PS: I cannot seem to get more of the necessary information from Godbolt, although the bug seems simple enough to reproduce without it. Still, this link to the setup I got the bug in might help: https://godbolt.org/z/cd7f4Mdzd)