[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-05-19 Thread nshead at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

Nathaniel Shead  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #12 from Nathaniel Shead  ---
Fixed for 15.2, thanks for the report!

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-05-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #11 from GCC Commits  ---
The releases/gcc-15 branch has been updated by Nathaniel Shead
:

https://gcc.gnu.org/g:2d1244a5b2dca62b97656cdfa28cd99af583aaa8

commit r15-9714-g2d1244a5b2dca62b97656cdfa28cd99af583aaa8
Author: Nathaniel Shead 
Date:   Sat May 17 23:51:07 2025 +1000

c++/modules: Fix ICE on merge of instantiation with partial spec [PR120013]

When we import a pending instantiation that matches an existing partial
specialisation, we don't find the slot in the entity map because for
partial specialisations we register the TEMPLATE_DECL but for normal
implicit instantiations we instead register the inner TYPE_DECL.

Because the DECL_MODULE_ENTITY_P flag is set we correctly realise that
it is in the entity map, but ICE when attempting to use that slot in
partition handling.

This patch fixes the issue by detecting this case and instead looking
for the slot for the TEMPLATE_DECL.  It doesn't matter that we never add
a slot for the inner decl because we're about to discard it anyway.

PR c++/120013

gcc/cp/ChangeLog:

* module.cc (trees_in::install_entity): Handle re-registering
the inner TYPE_DECL of a partial specialisation.

gcc/testsuite/ChangeLog:

* g++.dg/modules/partial-8.h: New test.
* g++.dg/modules/partial-8_a.C: New test.
* g++.dg/modules/partial-8_b.C: New test.
* g++.dg/modules/partial-8_c.C: New test.
* g++.dg/modules/partial-8_d.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 
(cherry picked from commit b0de7297f2b5670386472229ab795a577c288ecf)

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-05-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #10 from GCC Commits  ---
The master branch has been updated by Nathaniel Shead :

https://gcc.gnu.org/g:b0de7297f2b5670386472229ab795a577c288ecf

commit r16-752-gb0de7297f2b5670386472229ab795a577c288ecf
Author: Nathaniel Shead 
Date:   Sat May 17 23:51:07 2025 +1000

c++/modules: Fix ICE on merge of instantiation with partial spec [PR120013]

When we import a pending instantiation that matches an existing partial
specialisation, we don't find the slot in the entity map because for
partial specialisations we register the TEMPLATE_DECL but for normal
implicit instantiations we instead register the inner TYPE_DECL.

Because the DECL_MODULE_ENTITY_P flag is set we correctly realise that
it is in the entity map, but ICE when attempting to use that slot in
partition handling.

This patch fixes the issue by detecting this case and instead looking
for the slot for the TEMPLATE_DECL.  It doesn't matter that we never add
a slot for the inner decl because we're about to discard it anyway.

PR c++/120013

gcc/cp/ChangeLog:

* module.cc (trees_in::install_entity): Handle re-registering
the inner TYPE_DECL of a partial specialisation.

gcc/testsuite/ChangeLog:

* g++.dg/modules/partial-8.h: New test.
* g++.dg/modules/partial-8_a.C: New test.
* g++.dg/modules/partial-8_b.C: New test.
* g++.dg/modules/partial-8_c.C: New test.
* g++.dg/modules/partial-8_d.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-05-17 Thread nshead at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

Nathaniel Shead  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |nshead at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-30 Thread nshead at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #9 from Nathaniel Shead  ---
*** Bug 120016 has been marked as a duplicate of this bug. ***

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-30 Thread nshead at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #8 from Nathaniel Shead  ---
*** Bug 120014 has been marked as a duplicate of this bug. ***

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-30 Thread nshead at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

Nathaniel Shead  changed:

   What|Removed |Added

 CC||nshead at gcc dot gnu.org
 Status|WAITING |NEW
   Keywords||ice-on-valid-code
 Blocks||103524

--- Comment #7 from Nathaniel Shead  ---
Confirmed.  All three test cases do indeed seem to be the same underlying cause
(I'll close the others as duplicates); here's a reduction:

  // array.hpp
  template  struct tuple_element;
  template  struct tuple;
  template 
tuple_element<__i, tuple<_Elements>> get();

  // a.cpp
  module;
  #include "array.hpp"
  template 
struct tuple_element<__i, tuple<_Types>>;
  module m:a;
  template  void a(T t) { ::get(t); }

  // b.cpp
  module;
  #include "array.hpp"
  module m:b;
  template  void b(T t) { ::get(t); }

  // c.cpp
  export module m;
  import :a;
  import :b;

$ g++-15 -S -fmodules -Wno-global-module *.cpp
c.cpp:3:11: internal compiler error: Segmentation fault
3 | import :b;
  |   ^
0x22a2ef6 internal_error(char const*, ...)
../../gcc-15/gcc/diagnostic-global-context.cc:517
0xfe2de3 crash_signal
../../gcc-15/gcc/toplev.cc:322
0x7fa720c6d32f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x78c87a install_entity
../../gcc-15/gcc/cp/module.cc:8109
0x78c87a decl_value
../../gcc-15/gcc/cp/module.cc:8657
0x8fa81f tree_node
../../gcc-15/gcc/cp/module.cc:10062
0x8ff363 module_state::read_cluster(unsigned int)
../../gcc-15/gcc/cp/module.cc:16673
0x8ffe0d module_state::load_section(unsigned int, binding_slot*)
../../gcc-15/gcc/cp/module.cc:20217
0x903cb3 module_state::read_language(bool)
../../gcc-15/gcc/cp/module.cc:20146
0x903e07 module_state::read_language(bool)
../../gcc-15/gcc/cp/module.cc:21206
0x903e07 direct_import
../../gcc-15/gcc/cp/module.cc:21208
0x981a3a cp_parser_translation_unit
../../gcc-15/gcc/cp/parser.cc:5434
0x981a3a c_parse_file()
../../gcc-15/gcc/cp/parser.cc:53961
0xa8a8d9 c_common_parse_file()
../../gcc-15/gcc/c-family/c-opts.cc:1379
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.

The crash occurs in 'install_entity' here:

  tree not_tmpl = STRIP_TEMPLATE (decl);
  if (!DECL_LANG_SPECIFIC (not_tmpl)
  || !DECL_MODULE_ENTITY_P (not_tmpl))
{
  retrofit_lang_decl (not_tmpl);
  DECL_MODULE_ENTITY_P (not_tmpl) = true;

  /* Insert into the entity hash (it cannot already be there).  */
  bool existed;
  unsigned &slot = entity_map->get_or_insert (DECL_UID (decl), &existed);
  gcc_checking_assert (!existed);
  slot = ident;
}
  else if (state->is_partition ())
{
  /* The decl is already in the entity map, but we see it again now from a
 partition: we want to overwrite if the original decl wasn't also from
 a (possibly different) partition.  Otherwise, for things like template
 instantiations, make_dependency might not realise that this is also
 provided from a partition and should be considered part of this module
 (and thus always emitted into the primary interface's CMI).  */
  unsigned *slot = entity_map->get (DECL_UID (decl));
! module_state *imp = import_entity_module (*slot);  // segfault here, slot
is null
  if (!imp->is_partition ())
*slot = ident;
}

This seems to be because we get confused since 'DECL_MODULE_ENTITY_P' is only
set on the 'DECL_TEMPLATE_RESULT' of an entity, while here we're importing
first a TEMPLATE_DECL and then the inner TYPE_DECL from a separate partition:
the latter thinks we've already added it to the entity_map, when we actually
haven't (we've only added the TEMPLATE_DECL).

Also adding the DECL_TEMPLATE_RESULT to the entity map when we first see it
fixes this ICE, but doesn't seem like the correct solution (as two separate
decls will get the same ID), and I imagine could cause other issues down the
line.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread miuna.oshino at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #6 from Amber Ehrlich  ---
Ahh I can't edit, well, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120014 and
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120016 are crash 2 and 3
respectively

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread miuna.oshino at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #5 from Amber Ehrlich  ---
Ehh he's not sure so I'll do it anyways. Removing the other 2 cases from this
post

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #4 from Sam James  ---
If one of the GCC modules folks are on the Discord and said that, then that's
fine. Thanks.

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread miuna.oshino at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #3 from Amber Ehrlich  ---
I was told by a maintainer on modules that the 3 issues seem to be the same
one; I'll ask again & create 3 separate issues if not

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread miuna.oshino at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

--- Comment #2 from Amber Ehrlich  ---
Created attachment 61244
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61244&action=edit
Crash 1 project files + preprocessed source

Output:

/usr/local/bin/g++   -std=c++20 -freport-bug -Wall -Wextra -pedantic -MD -MT
CMakeFiles/meow.dir/owo.ixx.o -MF CMakeFiles/meow.dir/owo.ixx.o.d -fmodules-ts
-fmodule-mapper=CMakeFiles/meow.dir/owo.ixx.o.modmap -MD -fdeps-format=p1689r5
-x c++ -o CMakeFiles/meow.dir/owo.ixx.o -c /home/miuna/dev/crash-1/owo.ixx
/home/miuna/dev/crash-1/owo.ixx:12:25: internal compiler error: Segmentation
fault
   12 | export std::array owo;
  | ^
0x22cc84f internal_error(char const*, ...)
/home/miuna/dev/gcc/gcc/diagnostic-global-context.cc:517
0xfe115f crash_signal
/home/miuna/dev/gcc/gcc/toplev.cc:322
0x7f18f866b32f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x78419a install_entity
/home/miuna/dev/gcc/gcc/cp/module.cc:8109
0x78419a decl_value
/home/miuna/dev/gcc/gcc/cp/module.cc:8657
0x8e8a94 tree_node
/home/miuna/dev/gcc/gcc/cp/module.cc:10062
0x8ed09c module_state::read_cluster(unsigned int)
/home/miuna/dev/gcc/gcc/cp/module.cc:16673
0x8edb67 module_state::load_section(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:20217
0x8edc1e module_state::lazy_load(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:21063
0x8e98d9 tree_node
/home/miuna/dev/gcc/gcc/cp/module.cc:10629
0x8ed02b module_state::read_cluster(unsigned int)
/home/miuna/dev/gcc/gcc/cp/module.cc:16528
0x8edb67 module_state::load_section(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:20217
0x8edc1e module_state::lazy_load(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:21063
0x8e98d9 tree_node
/home/miuna/dev/gcc/gcc/cp/module.cc:10629
0x8ed02b module_state::read_cluster(unsigned int)
/home/miuna/dev/gcc/gcc/cp/module.cc:16528
0x8edb67 module_state::load_section(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:20217
0x8edc1e module_state::lazy_load(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:21063
0x8e98d9 tree_node
/home/miuna/dev/gcc/gcc/cp/module.cc:10629
0x8ed02b module_state::read_cluster(unsigned int)
/home/miuna/dev/gcc/gcc/cp/module.cc:16528
0x8edb67 module_state::load_section(unsigned int, binding_slot*)
/home/miuna/dev/gcc/gcc/cp/module.cc:20217
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See  for instructions.
Preprocessed source stored into /tmp/ccPuVzMx.out file, please attach this to
your bugreport.

[Bug c++/120013] SIGSEGV ICE with modules related to instantiation of templates across partition units

2025-04-29 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120013

Sam James  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2025-04-29

--- Comment #1 from Sam James  ---
Can you include the input files (as on godbolt) as attachments please, as well
as the crash output (along with the command used)?

(For multiple issues, it's preferred to have multiple bugs, and we can mark
them as duplicates as-required).