public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "nicolas.werner at hotmail dot de" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-111710-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111710

            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=56063&action=edit
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) = 
      [](int value) { return value; };
  };

}


When compiling this example with "g++ -std=c++23  -fmodules-ts  -x c++ -o
argparse.ixx.o -c argparse.ixx" it produces the following crash:

0x5583c3e758bb crash_signal
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/toplev.cc:314
0x7f2a9658041f ???
       
/usr/src/debug/sys-libs/glibc-2.38-r5/glibc-2.38/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x5583c3627ea5 trees_out::key_mergeable(int, merge_kind, tree_node*,
tree_node*, tree_node*, depset*)
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/module.cc:10651
0x5583c36220e8 trees_out::decl_value(tree_node*, depset*)
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/module.cc:7786
0x5583c362abd2 depset::hash::find_dependencies(module_state*)
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/module.cc:13328
0x5583c362ba29 module_state::write_begin(elf_out*, cpp_reader*,
module_state_config&, unsigned int&)
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/module.cc:17895
0x5583c362d0b4 finish_module_processing(cpp_reader*)
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/module.cc:20241
0x5583c35af85d c_parse_final_cleanups()
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/cp/decl2.cc:5255
0x5583c381d2fd c_common_parse_file()
       
/usr/src/debug/sys-devel/gcc-14.0.0_pre20231001/gcc-14-20231001/gcc/c-family/c-opts.cc:1296

This is because the lambda is treated as a field by trees_out::get_merge_kind,
but the corresponding case in trees_out::key_mergeable can't find such a field
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 right
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 code
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.

             reply	other threads:[~2023-10-05 18:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 18:48 nicolas.werner at hotmail dot de [this message]
2023-10-05 18:53 ` [Bug c++/111710] " pinskia at gcc dot gnu.org
2023-10-05 18:59 ` nicolas.werner at hotmail dot de
2024-02-29  5:04 ` cvs-commit at gcc dot gnu.org
2024-02-29  5:09 ` nshead at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111710-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).