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

            Bug ID: 127084
           Summary: [MIPS] Segfault at emit_insn_after with -mips16
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: saaadhu at gcc dot gnu.org
  Target Milestone: ---

Both 16.1.0 and master ICE with a segfault when compiling the below code with
-mips16.

$ cat repro.cc
class A {};

struct Node
{
  static A d1;
  static A d2;
  static Node* head();
};

A&
get_tzdb_list()
{
  if (!Node::head())
        return Node::d1;
  return Node::d2;
}

$ mips-unknown-elf-g++ --version
mips-unknown-elf-g++ (GCC) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ mips-unknown-elf-g++ -mips16 repro.cc -std=gnu++20 
during RTL pass: expand
repro.cc: In function 'A& get_tzdb_list()':
repro.cc:14:22: internal compiler error: Segmentation fault
   14 |         return Node::d1;
      |                      ^~
0x2c2b0fd internal_error(char const*, ...)
        /opt/developer/oss/src/gcc/gcc/diagnostic-global-context.cc:787
0x1a95c68 crash_signal
        /opt/developer/oss/src/gcc/gcc/toplev.cc:325
0x150f744 add_insn_after(rtx_insn*, rtx_insn*, basic_block_def*)
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:4372
0x151044d emit_pattern_after_noloc
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:4830
0x15108e2 emit_pattern_after
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:5007
0x151093e emit_insn_after(rtx_def*, rtx_insn*)
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:5021
0x1eeca69 mips16_gp_pseudo_reg
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3413
0x1eecbe3 mips_pic_base_register(rtx_def*)
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3438
0x1eed01e mips_split_symbol(rtx_def*, rtx_def*, machine_mode, rtx_def**)
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3561
0x1eee2fe mips_legitimize_const_move
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3866
0x1eee5bc mips_legitimize_move(machine_mode, rtx_def*, rtx_def*)
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3924
0x2850480 gen_movsi(rtx_def*, rtx_def*)
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.md:5006
0x13bbe16 rtx_insn* insn_gen_fn::operator()<rtx_def*, rtx_def*>(rtx_def*,
rtx_def*) const
        /opt/developer/oss/src/gcc/gcc/recog.h:472
0x155deaa emit_move_insn_1(rtx_def*, rtx_def*)
        /opt/developer/oss/src/gcc/gcc/expr.cc:4581
0x155e950 emit_move_insn(rtx_def*, rtx_def*)
        /opt/developer/oss/src/gcc/gcc/expr.cc:4751
0x1565cc5 store_expr(tree_node*, rtx_def*, int, bool, bool)
        /opt/developer/oss/src/gcc/gcc/expr.cc:6992
0x1563f2b expand_assignment(tree_node*, tree_node*, bool)
        /opt/developer/oss/src/gcc/gcc/expr.cc:6499
0x13e44e2 expand_gimple_stmt_1
        /opt/developer/oss/src/gcc/gcc/cfgexpand.cc:4309
0x13e4793 expand_gimple_stmt
        /opt/developer/oss/src/gcc/gcc/cfgexpand.cc:4390
0x13eb487 expand_gimple_basic_block
        /opt/developer/oss/src/gcc/gcc/cfgexpand.cc:6507
/opt/developer/install/libexec/gcc/mips-unknown-elf/16.1.0/cc1plus -quiet
-imultilib mips16 repro.cc -quiet -dumpdir a- -dumpbase repro.cc -dumpbase-ext
.cc -mips16 -std=gn
u++20 -o /tmp/nix-shell.bv8ibM/ccfdXy7i.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

$ mips-unknown-elf-g++ --version
mips-unknown-elf-g++ (GCC) 17.0.0 20260825 (experimental)
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ mips-unknown-elf-g++ -mips16 repro.cc -std=gnu++20
during RTL pass: expand
repro.cc: In function 'A& get_tzdb_list()':
repro.cc:14:22: internal compiler error: Segmentation fault
   14 |         return Node::d1;
      |                      ^~
0x363d9d9 internal_error(char const*, ...)
        /opt/developer/oss/src/gcc/gcc/diagnostic-global-context.cc:787
0x1ee3e65 crash_signal
        /opt/developer/oss/src/gcc/gcc/toplev.cc:325
0x185156f add_insn_after(rtx_insn*, rtx_insn*, basic_block_def*)
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:4375
0x185229e emit_pattern_after_noloc
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:4833
0x1852759 emit_pattern_after
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:5010
0x18527b5 emit_insn_after(rtx_def*, rtx_insn*)
        /opt/developer/oss/src/gcc/gcc/emit-rtl.cc:5024
0x24344b9 mips16_gp_pseudo_reg
        /opt/developer/oss/src/gcc/gcc/config/mips/mips.cc:3414
<snip>

Reply via email to