Bug 99769

Summary: [modules] internal compiler error: in tree_node, at cp/module.cc:9105 when compile module partitions
Product: gcc Reporter: owent <owt5008137>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: johelegp, mpolacek, oleg, ppalka, tortoise_74, webrown.cpp
Priority: P3 Keywords: ice-on-valid-code
Version: 11.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2022-07-26 00:00:00
Bug Depends on:    
Bug Blocks: 103524    

Description owent 2021-03-25 12:11:26 UTC
Compiling modules with partitions always failed.The commands and files to reproduce this are below:

$ /opt/gcc-latest/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/opt/gcc-latest/bin/g++
COLLECT_LTO_WRAPPER=/opt/gcc-latest/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-latest --enable-languages=c,c++ --enable-libstdcxx-debug --disable-bootstrap --disable-multilib --disable-libvtv --with-system-zlib --without-isl --enable-multiarch
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.1 20210321 (experimental) (GCC)

$ cat foo-types.ixx
module;

export module foo:types;
export class CDerived;

$ cat foo-test.ixx
module;
#include <iostream>
#include <typeinfo>

export module foo:test;
import :types;

export class Bar {
public:
    virtual ~Bar() = default;
    virtual void visit() {
        std::cout << "Bar::visit -> "<< typeid(*this).name() << std::endl;
    }
};

$ cat foo.ixx
module;

export module foo;

export import :types;
export import :test;

$ /opt/gcc-latest/bin/g++ -fmodules-ts -std=c++20 -x c++ -c foo-types.ixx -o foo-types.o
$ /opt/gcc-latest/bin/g++ -fmodules-ts -std=c++20 -x c++ -c foo-test.ixx -o foo-test.o
$ /opt/gcc-latest/bin/g++ -fmodules-ts -std=c++20 -x c++ -c foo.ixx -o foo.o
foo.ixx:3:8: internal compiler error: in tree_node, at cp/module.cc:9105
    3 | export module foo;
      |        ^~~~~~
0x8af602 trees_out::tree_node(tree_node*)
        ../../gcc/cp/module.cc:9105
0x8b0460 trees_out::core_vals(tree_node*)
        ../../gcc/cp/module.cc:5908
0x8b5009 trees_out::tree_node_vals(tree_node*)
        ../../gcc/cp/module.cc:7049
0x8b5009 trees_out::tree_value(tree_node*)
        ../../gcc/cp/module.cc:8936
0x8af522 trees_out::tree_node(tree_node*)
        ../../gcc/cp/module.cc:9134
0x8b0460 trees_out::core_vals(tree_node*)
        ../../gcc/cp/module.cc:5908
0x8b5009 trees_out::tree_node_vals(tree_node*)
        ../../gcc/cp/module.cc:7049
0x8b5009 trees_out::tree_value(tree_node*)
        ../../gcc/cp/module.cc:8936
0x8af522 trees_out::tree_node(tree_node*)
        ../../gcc/cp/module.cc:9134
0x8b0460 trees_out::core_vals(tree_node*)
        ../../gcc/cp/module.cc:5908
0x8b5009 trees_out::tree_node_vals(tree_node*)
        ../../gcc/cp/module.cc:7049
0x8b5009 trees_out::tree_value(tree_node*)
        ../../gcc/cp/module.cc:8936
0x8af522 trees_out::tree_node(tree_node*)
        ../../gcc/cp/module.cc:9134
0x8b0460 trees_out::core_vals(tree_node*)
        ../../gcc/cp/module.cc:5908
0x8b5009 trees_out::tree_node_vals(tree_node*)
        ../../gcc/cp/module.cc:7049
0x8b5009 trees_out::tree_value(tree_node*)
        ../../gcc/cp/module.cc:8936
0x8af522 trees_out::tree_node(tree_node*)
        ../../gcc/cp/module.cc:9134
0x8b0460 trees_out::core_vals(tree_node*)
        ../../gcc/cp/module.cc:5908
0x8b5009 trees_out::tree_node_vals(tree_node*)
        ../../gcc/cp/module.cc:7049
0x8b5009 trees_out::tree_value(tree_node*)
        ../../gcc/cp/module.cc:8936
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 Marek Polacek 2021-03-30 01:29:50 UTC
Reproduced.
Comment 2 Marek Polacek 2021-03-30 01:32:26 UTC
We have __dynamic_cast without DECL_CONTEXT and so ICE in

 9050       if (!DECL_CONTEXT (t))
 9051         {
 9052           /* There are a few cases of decls with no context.  We'll write
 9053              these by value, but first assert they are cases we expect.  */
 9054           gcc_checking_assert (ref == WK_normal);
 9055           switch (TREE_CODE (t))
 9056             {
 9057             default: gcc_unreachable ();
Comment 3 Jonathan Wakely 2022-07-26 10:04:40 UTC
PR 106304 has a much simpler single-file reproducer that ICEs at the same line.
Comment 4 Bruce Adams 2022-10-09 11:11:08 UTC
I had a issue I believed to be related but in attempting to create a reproducer got several different ICEs so I have submitted a separate ticket - see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107191
Comment 5 Patrick Palka 2022-10-14 13:22:45 UTC
Same issue as the recently fixed PR106304

*** This bug has been marked as a duplicate of bug 106304 ***