From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 603E53852C75; Wed, 23 Nov 2022 16:44:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 603E53852C75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669221851; bh=F974iqhSfgAgt3RSHYgCAVaEPcmykMBa32X189GByew=; h=From:To:Subject:Date:From; b=tzYdxSslHRXTi6vQRVU+8wbGJ4Oe+JLN1k2jVp0DVP1LlfqQeyD7l+ilr8uLdJ3NH wRsk07dcLBN2XHrRoTFap/02yrnGn3ytZJuzfVR8bAivUExX5DaJRIuF6cmdXcMdIH mZvwGdh+Ow5kWrl9vFB9hignSGgmxda81xYgfHgE= From: "gabravier at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107840] New: ICE when compiling cursed setjmp/longjmp that uses __builtin_call_with_static_chain Date: Wed, 23 Nov 2022 16:44:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gabravier at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107840 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 =3D (void*)p; \ __t->chain; \ }) #define NESTED_ADDR(p) ({ \ auto __p =3D (p); \ thunk_struct *__t =3D (void*)__p; \ (typeof(__p))(intptr_t)__t->addr; \ }) #define NESTED_UPGRADE(self, ptr, args) ({ \ if(self !=3D 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 =3D 0; \ [[noreturn]] void __jmp(void *self, int r){ \ NESTED_UPGRADE(__jmp, self, (self, r)); \ __xsetjmp_ret =3D r ?: 1; \ goto trgt; \ } \ env[0].fun =3D __jmp; \ trgt:; \ int tmp =3D __xsetjmp_ret; \ __xsetjmp_ret =3D 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 =3D 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=3Dc2x` results in the following error: : In function 'foo': :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 :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 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 l= ink to the setup I got the bug in might help: https://godbolt.org/z/cd7f4Mdzd)=