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

            Bug ID: 70621
           Summary: ICE on invalid code at -O1 and above on
                    x86_64-linux-gnu in record_reference, at
                    cgraphbuild.c:64
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

The following code causes an ICE when compiled with the current GCC trunk at
-O1 and above on x86_64-linux-gnu in both 32-bit and 64-bit modes.  

This is a regression from 5.3.x. 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 6.0.0 20160410 (experimental) [trunk revision 234869] (GCC) 
$ 
$ g++-trunk -O0 -c small.cpp
small.cpp:30:12: error: conflicting declaration ‘const B D::e’
 const B D::e = { 0, (fp) &E::foo };
            ^
small.cpp:20:12: note: previous declaration as ‘B D::e’
   static B e;
            ^
small.cpp:30:12: error: declaration of ‘B D::e’ outside of class is not
definition [-fpermissive]
 const B D::e = { 0, (fp) &E::foo };
            ^
$ 
$ g++-5.3 -O1 -c small.cpp
small.cpp:30:12: error: conflicting declaration ‘const B D::e’
 const B D::e = { 0, (fp) &E::foo }; 
            ^
small.cpp:20:12: note: previous declaration as ‘B D::e’
   static B e;
            ^
small.cpp:30:12: error: declaration of ‘B D::e’ outside of class is not
definition [-fpermissive]
 const B D::e = { 0, (fp) &E::foo }; 
            ^
$ 
$ g++-trunk -O1 -c small.cpp
small.cpp:30:12: error: conflicting declaration ‘const B D::e’
 const B D::e = { 0, (fp) &E::foo };
            ^
small.cpp:20:12: note: previous declaration as ‘B D::e’
   static B e;
            ^
small.cpp:30:12: error: declaration of ‘B D::e’ outside of class is not
definition [-fpermissive]
 const B D::e = { 0, (fp) &E::foo };
            ^
cc1plus: internal compiler error: in record_reference, at cgraphbuild.c:64
0x95ef53 record_reference
        ../../gcc-source-trunk/gcc/cgraphbuild.c:64
0x100fec4 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc-source-trunk/gcc/tree.c:11531
0x1010474 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc-source-trunk/gcc/tree.c:11848
0x1010474 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc-source-trunk/gcc/tree.c:11848
0x96008a record_references_in_initializer(tree_node*, bool)
        ../../gcc-source-trunk/gcc/cgraphbuild.c:404
0x1051957 varpool_node::analyze()
        ../../gcc-source-trunk/gcc/varpool.c:526
0x966359 analyze_functions
        ../../gcc-source-trunk/gcc/cgraphunit.c:1133
0x966f98 symbol_table::finalize_compilation_unit()
        ../../gcc-source-trunk/gcc/cgraphunit.c:2542
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 


------------------------------------------


class A; 

typedef void (A::*fp) (void);

struct B
{
  int n; 
  fp f;
};

struct C
{
  const C *c;
  const B b; 
};

class D 
{
public: 
  static B e;
  static C m;
};

class E : public D 
{
public: 
  void foo (); 
};

// OK: B D::e = { 0, (fp) &E::foo }; 
const B D::e = { 0, (fp) &E::foo }; 

C D::m = { &D::m, E::e };

Reply via email to