Bug 9629

Summary: [3.2/3.3/3.4 regression] virtual inheritance segfault
Product: gcc Reporter: stefan
Component: c++Assignee: Nathan Sidwell <nathan>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: ice-on-valid-code
Version: 3.2.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: gcc-3.2.2-virtual-inheritance-test.cc

Description stefan 2003-02-08 21:36:00 UTC
   Hi!

The following minimal testcase compiles and runs with gcc-2.95 and compiles and crashes with gcc-3.2.2. I am not sure whether it is a bug in the testcase or a bug in the compiler, but in any case I would appreciate hearing whats the problem with the testcase. Thanks.

    Cu... Stefan

Release:
gcc-3.2.2

Environment:
Debian unstable on i386
Comment 1 Wolfgang Bangerth 2003-02-14 20:46:18 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. Here's a very slightly reduced testcase:
    --------------------------
    struct A { };
    
    struct B {
    	B(A *) {}
    };
    
    struct C : virtual public A, public B {
    	C() : B(this) {}
    };
    
    struct D : virtual public C {};
    
    main() {
      new D();
    }
    ------------------------
    Executing this program segfaults with 3.2.2, 3.3, and 3.4.
    So it is a regression, assuming the code is legal.
    
    The problem is in casting this to A* in the constructor
    C::C. It's trying to cast to a virtual base, and it seems
    to me that this information is not available at the time
    we get to C::C, which then causes the segfault. But that's
    just a wild guess.
    
    W.
Comment 2 Nathan Sidwell 2003-02-21 16:08:06 UTC
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: fixing
Comment 3 Nathan Sidwell 2003-03-16 14:36:43 UTC
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9629
Date: 16 Mar 2003 14:36:43 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	nathan@gcc.gnu.org	2003-03-16 14:36:43
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h init.c class.c parser.c 
 	                 pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/init: ctor2.C 
 
 Log message:
 	cp:
 	PR c++/9629
 	* cp-tree.h (struct language_function): Add in_base_initializer.
 	(in_base_initializer): define it.
 	(expand_member_init): Remove INIT param.
 	* init.c (expand_member_init): Remove INIT param, return the member.
 	(emit_mem_initializers): Set in_base_initializer.
 	* class.c (build_base_path): Check in_base_initializer.
 	* parser.c (cp_parser_mem_initializer): Set in_base_initializer.
 	* pt.c (tsubst_initializer_list): Likewise.
 	testsuite:
 	PR c++/9629
 	* g++.dg/init/ctor2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3278&r2=1.3279
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.825&r2=1.826
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.314&r2=1.315
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.526&r2=1.527
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.51&r2=1.52
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.670&r2=1.671
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2511&r2=1.2512
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 

Comment 4 Nathan Sidwell 2003-03-16 14:36:43 UTC
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9629
Date: 16 Mar 2003 14:36:43 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	nathan@gcc.gnu.org	2003-03-16 14:36:43
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h init.c class.c parser.c 
 	                 pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/init: ctor2.C 
 
 Log message:
 	cp:
 	PR c++/9629
 	* cp-tree.h (struct language_function): Add in_base_initializer.
 	(in_base_initializer): define it.
 	(expand_member_init): Remove INIT param.
 	* init.c (expand_member_init): Remove INIT param, return the member.
 	(emit_mem_initializers): Set in_base_initializer.
 	* class.c (build_base_path): Check in_base_initializer.
 	* parser.c (cp_parser_mem_initializer): Set in_base_initializer.
 	* pt.c (tsubst_initializer_list): Likewise.
 	testsuite:
 	PR c++/9629
 	* g++.dg/init/ctor2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3278&r2=1.3279
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.825&r2=1.826
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.314&r2=1.315
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.526&r2=1.527
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.51&r2=1.52
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.670&r2=1.671
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2511&r2=1.2512
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 
Comment 5 Nathan Sidwell 2003-03-17 11:52:48 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: fixed on HEAD and 3.3
    2003-03-16  Nathan Sidwell  <nathan@codesourcery.com>
    
    	PR c++/9629
    	* cp-tree.h (struct language_function): Add in_base_initializer.
    	(in_base_initializer): define it.
    	(expand_member_init): Remove INIT param.
    	* init.c (expand_member_init): Remove INIT param, return the member.
    	(emit_mem_initializers): Set in_base_initializer.
    	* class.c (build_base_path): Check in_base_initializer.
    	* parser.c (cp_parser_mem_initializer): Set in_base_initializer.
    	* pt.c (tsubst_initializer_list): Likewise.
Comment 6 Nathan Sidwell 2003-03-17 12:00:32 UTC
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9629
Date: 17 Mar 2003 12:00:32 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	nathan@gcc.gnu.org	2003-03-17 12:00:31
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h init.c class.c parse.y pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/init: ctor2.C 
 
 Log message:
 	cp:
 	PR c++/9629
 	* cp-tree.h (struct language_function): Add in_base_initializer.
 	(in_base_initializer): define it.
 	(expand_member_init): Remove INIT param.
 	* init.c (expand_member_init): Remove INIT param, return the member.
 	(emit_mem_initializers): Set in_base_initializer.
 	* class.c (build_base_path): Check in_base_initializer.
 	* parse.y (begin_member_init): New reduction.
 	(member_init): Use it.
 	* pt.c (tsubst_initializer_list): Set in_base_initializer.
 	testsuite:
 	PR c++/9629
 	* g++.dg/init/ctor2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.85&r2=1.3076.2.86
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.12&r2=1.776.2.13
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.299.2.3&r2=1.299.2.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.9&r2=1.499.2.10
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.284.2.4&r2=1.284.2.5
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.14&r2=1.635.2.15
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.103&r2=1.2261.2.104
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
 

Comment 7 Nathan Sidwell 2003-03-17 12:00:32 UTC
From: nathan@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9629
Date: 17 Mar 2003 12:00:32 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	nathan@gcc.gnu.org	2003-03-17 12:00:31
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h init.c class.c parse.y pt.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/init: ctor2.C 
 
 Log message:
 	cp:
 	PR c++/9629
 	* cp-tree.h (struct language_function): Add in_base_initializer.
 	(in_base_initializer): define it.
 	(expand_member_init): Remove INIT param.
 	* init.c (expand_member_init): Remove INIT param, return the member.
 	(emit_mem_initializers): Set in_base_initializer.
 	* class.c (build_base_path): Check in_base_initializer.
 	* parse.y (begin_member_init): New reduction.
 	(member_init): Use it.
 	* pt.c (tsubst_initializer_list): Set in_base_initializer.
 	testsuite:
 	PR c++/9629
 	* g++.dg/init/ctor2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.85&r2=1.3076.2.86
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.12&r2=1.776.2.13
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.299.2.3&r2=1.299.2.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.9&r2=1.499.2.10
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.284.2.4&r2=1.284.2.5
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.14&r2=1.635.2.15
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.103&r2=1.2261.2.104
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1