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

            Bug ID: 127672
           Summary: Segfault in decl_namespace_context: function type has
                    no TYPE_MAIN_DECL
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amacleod at redhat dot com
  Target Milestone: ---

I can't take credit for this.  I was using tree-ssa-forwprop.ii as part of a
performance suite, and it was segfaulting when I compiled it.

Claude Opus investigated why, and discovered that it worked with
-fpreprocessed, but not without.  in a matter of minutes, it reduced it to the
following testcase

// z.h
namespace { struct P { }; }
struct S { void (*f) (P *); };

// z.cc
#include "z.h"

Compile with  cc1plus z.cc
and you are presented with:

 ./cc1plus z.cc
In file included from z.cc:1:
z.h:2:8: internal compiler error: Segmentation fault
    2 | struct S { void (*f) (P *); };
      |        ^
0x381f6f0 internal_error(char const*, ...)
        /gcc/master/gcc/gcc/diagnostic-global-context.cc:787
0x1439523 crash_signal
        /gcc/master/gcc/gcc/toplev.cc:325
0x401bca contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        /gcc/master/gcc/gcc/tree.h:3976
0x98d908 decl_namespace_context(tree_node*)
        /gcc/master/gcc/gcc/cp/tree.cc:4062
0x98db40 decl_anon_ns_mem_p(tree_node*)
        /gcc/master/gcc/gcc/cp/tree.cc:4074
0x5e996d constrain_class_visibility(tree_node*)
        /gcc/master/gcc/gcc/cp/decl2.cc:3601
0x479a28 finish_struct_1(tree_node*)
        /gcc/master/gcc/gcc/cp/class.cc:8146
0x47ae7d finish_struct(tree_node*, tree_node*)
        /gcc/master/gcc/gcc/cp/class.cc:8349
0x79e7d1 cp_parser_class_specifier
        /gcc/master/gcc/gcc/cp/parser.cc:29961
0x78b9fc cp_parser_type_specifier
        /gcc/master/gcc/gcc/cp/parser.cc:22507
0x7847be cp_parser_decl_specifier_seq
        /gcc/master/gcc/gcc/cp/parser.cc:18986
0x781f8c cp_parser_simple_declaration
        /gcc/master/gcc/gcc/cp/parser.cc:18086
0x781f01 cp_parser_block_declaration
        /gcc/master/gcc/gcc/cp/parser.cc:18026
0x781910 cp_parser_declaration
        /gcc/master/gcc/gcc/cp/parser.cc:17827
0x7819ec cp_parser_toplevel_declaration
        /gcc/master/gcc/gcc/cp/parser.cc:17848
0x75f247 cp_parser_translation_unit
        /gcc/master/gcc/gcc/cp/parser.cc:5610
0x7fcbf6 c_parse_file()
        /gcc/master/gcc/gcc/cp/parser.cc:57948
0xac28f3 c_common_parse_file()
        /gcc/master/gcc/gcc/c-family/c-opts.cc:1442


If you instead copy the same code directly into a .cc file:

// z1.cc
namespace { struct P { }; }
struct S { void (*f) (P *); };

./cc1plus z1.cc

It compiles fine.

This is reproducible from GCC 13 onward.

Reply via email to