Bug 50618 - [4.4/4.5/4.6/4.7 Regression] Virtual inheritance segfault
Summary: [4.4/4.5/4.6/4.7 Regression] Virtual inheritance segfault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.1
: P2 normal
Target Milestone: 4.4.7
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks: 51331
  Show dependency treegraph
 
Reported: 2011-10-04 20:11 UTC by Tom Boshoven
Modified: 2011-12-16 23:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.5, 4.6.3, 4.7.0
Known to fail: 4.4.1, 4.5.1, 4.6.1
Last reconfirmed: 2011-10-04 00:00:00


Attachments
A small program using multiple inheritance, segfaults when run. (272 bytes, text/plain)
2011-10-04 20:11 UTC, Tom Boshoven
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Boshoven 2011-10-04 20:11:26 UTC
Created attachment 25417 [details]
A small program using multiple inheritance, segfaults when run.

Affected GCC Versions:
4.6.1 20110819 (prerelease)   (Arch Linux package)
4.5.3    (Compiled using Arch defaults, --march=core2)
Both x64.

GCC 4.2 does not seem to be affected.


The attached source code, when compiled without any additional flags, segfaults when executed.
The segfault occurs within the ostream.

I tried to further minimize the code, but all components of this code seem to be required.
Comment 1 Andrew Pinski 2011-10-04 20:45:50 UTC
Here is a simplier testcase:
struct Base
{
	const int text;
	Base():text(1) {}
	Base(int aText)
	: text(aText) {}
};
struct SubA : public virtual Base
{
protected:
  int x;
public:
  SubA(int aX)
  : x(aX) {}
};
class SubB : public virtual Base
{};
struct Diamond : public SubA, public SubB
{
	Diamond(int text)
	: Base(text), SubA(5), SubB() {}

	void printText()
	{
		if(text != 2)
		  __builtin_abort();
		if(x!=5)
		  __builtin_abort();
	}
};

int main(int, char**)
{
	Diamond x(2);
	x.printText();
}
Comment 2 Jason Merrill 2011-10-13 18:01:58 UTC
Author: jason
Date: Thu Oct 13 18:01:51 2011
New Revision: 179934

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179934
Log:
	PR c++/50618
	* init.c (expand_aggr_init_1): Don't zero-initialize virtual
	bases of a base subobject.

Added:
    trunk/gcc/testsuite/g++.dg/init/vbase1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-10-13 18:02:15 UTC
Author: jason
Date: Thu Oct 13 18:02:10 2011
New Revision: 179935

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179935
Log:
	PR c++/50618
	* init.c (expand_aggr_init_1): Don't zero-initialize virtual
	bases of a base subobject.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/init/vbase1.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/init.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2011-10-13 18:02:34 UTC
Author: jason
Date: Thu Oct 13 18:02:27 2011
New Revision: 179936

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179936
Log:
	PR c++/50618
	* init.c (expand_aggr_init_1): Don't zero-initialize virtual
	bases of a base subobject.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/g++.dg/init/vbase1.C
Modified:
    branches/gcc-4_5-branch/gcc/cp/ChangeLog
    branches/gcc-4_5-branch/gcc/cp/init.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Comment 5 Jason Merrill 2011-10-13 18:03:13 UTC
Author: jason
Date: Thu Oct 13 18:03:06 2011
New Revision: 179938

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179938
Log:
	PR c++/50618
	* init.c (expand_aggr_init_1): Don't zero-initialize virtual
	bases of a base subobject.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/init/vbase1.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/init.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Comment 6 Jason Merrill 2011-10-13 18:05:57 UTC
Fixed for 4.4.7.
Comment 7 Andrew Pinski 2011-11-29 05:01:12 UTC
*** Bug 51331 has been marked as a duplicate of this bug. ***