From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EC2903858C5F; Thu, 5 Oct 2023 18:48:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC2903858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696531705; bh=rzloGCA3jcYrR+Z8sA9q7xaknv50djM7J0+v37uCZmw=; h=From:To:Subject:Date:From; b=q8KOCNUv1u5MWCs0Uqr6+e11VUEISPlhV4oFiTw+cbHkhqsfVleJmRbzQO4z9OfeY UaSElHLrqBCxLj8G0Xmb9kW6lSai1PC763HNnesKMBnJFDYTNoQEovBoO0xCUxXhjU lq7FjDOCEDoDy4AXsusWPNm/scv0zwus6oT0BEXE= From: "nicolas.werner at hotmail dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111710] New: [modules] ICE when compiling module where a lambda is assigned to a field in an exported class Date: Thu, 05 Oct 2023 18:48:25 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nicolas.werner at hotmail dot de 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 attachments.created 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=3D111710 Bug ID: 111710 Summary: [modules] ICE when compiling module where a lambda is assigned to a field in an exported class Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nicolas.werner at hotmail dot de Target Milestone: --- Created attachment 56063 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56063&action=3Dedit Patch which prevents the ICE when assigning a lambda to a field inside an exported entity Reduced minimal example: export module argparse; export { struct Argument { int (*i)(int) =3D=20 [](int value) { return value; }; }; } When compiling this example with "g++ -std=3Dc++23 -fmodules-ts -x c++ -o argparse.ixx.o -c argparse.ixx" it produces the following crash: 0x5583c3e758bb crash_signal =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/toplev.= cc:314 0x7f2a9658041f ??? =20=20=20=20=20=20=20 /usr/src/debug/sys-libs/glibc-2.38-r5/glibc-2.38/signal/../sysdeps/unix/sys= v/linux/x86_64/libc_sigaction.c:0 0x5583c3627ea5 trees_out::key_mergeable(int, merge_kind, tree_node*, tree_node*, tree_node*, depset*) =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/modu= le.cc:10651 0x5583c36220e8 trees_out::decl_value(tree_node*, depset*) =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/modu= le.cc:7786 0x5583c362abd2 depset::hash::find_dependencies(module_state*) =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/modu= le.cc:13328 0x5583c362ba29 module_state::write_begin(elf_out*, cpp_reader*, module_state_config&, unsigned int&) =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/modu= le.cc:17895 0x5583c362d0b4 finish_module_processing(cpp_reader*) =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/modu= le.cc:20241 0x5583c35af85d c_parse_final_cleanups() =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/decl= 2.cc:5255 0x5583c381d2fd c_common_parse_file() =20=20=20=20=20=20=20 /usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/c-famil= y/c-opts.cc:1296 This is because the lambda is treated as a field by trees_out::get_merge_ki= nd, but the corresponding case in trees_out::key_mergeable can't find such a fi= eld and then runs over the end of the linked list and dereferences a nullptr. I am not sure, what the proper mergeable kind is for such a lambda. I tried changing it to be MK_unique, which seems to fix the crash, but I don't know what the consequences of that would be. I would assume MK_keyed to be the r= ight value, however I couldn't make that work. Alternatively possibly the key_mergeable needs to be adapted to handle such fields properly, but since this is my first time touching the gcc codebase, I find that part of the co= de to be a bit hard to wrap my head around. I have attached the patch, which changes the mergekind to demonstrate the problem area as well as included a test case in that patch. Maybe that can = help solving that issue properly. I tested this with 13.2.1_p20230826 and 14.0.0_pre20231001.=