Bug 27640 - [4.2 Regression] segfault, related to constructor instantiation and virtual base case and templates and new operator
Summary: [4.2 Regression] segfault, related to constructor instantiation and virtual b...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.2.0
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code, monitored, rejects-valid
Depends on:
Blocks:
 
Reported: 2006-05-17 12:32 UTC by Martin Michlmayr
Modified: 2006-06-16 02:11 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail: 4.2.0
Last reconfirmed: 2006-05-18 04:25:04


Attachments
test case (906 bytes, text/plain)
2006-05-17 12:32 UTC, Martin Michlmayr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2006-05-17 12:32:28 UTC
I get the following segfault with gcc 4.2.0 20060419.  4.0/4.1 work.

14640:tbm@deprecation: ~] /usr/lib/gcc-snapshot/bin/g++ -c mini.c
mini.c: In constructor 'refcounted<T, scalar>::refcounted(const A1&) [with A1 = ref<nfsserv>, T = nfsserv_ac]':
mini.c:88:   instantiated from 'void sfsserver_cache_alloc(sfsprog*, ref<nfsserv>, int, sfscd_mountarg*, ref<callback<void, const nfs_fh3*, void, void> >) [with T = server]'
mini.c:102:   instantiated from here
mini.c:28: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Martin Michlmayr 2006-05-17 12:32:52 UTC
Created attachment 11483 [details]
test case
Comment 2 Andrew Pinski 2006-05-17 16:28:40 UTC
Back trace:
#0  0x001a2758 in expand_virtual_init (binfo=0xd8c0c0, decl=0xd92840) at ../../gcc/cp/init.c:781
#1  0x0019fb7c in dfs_initialize_vtbl_ptrs (binfo=0xd8c0c0, data=0xdb63c0) at ../../gcc/cp/init.c:112
#2  0x001bccd0 in dfs_walk_once_r (binfo=0xd8c0c0, pre_fn=0x19f8fc <dfs_initialize_vtbl_ptrs>, post_fn=0, data=0xdb63c0) at ../../gcc/cp/search.c:1576
#3  0x001bd3f8 in dfs_walk_once (binfo=0xd8c0c0, pre_fn=0x19f8fc <dfs_initialize_vtbl_ptrs>, post_fn=0, data=0xdb63c0) at ../../gcc/cp/search.c:1659
#4  0x0019fc74 in initialize_vtbl_ptrs (addr=0xd92840) at ../../gcc/cp/init.c:134
#5  0x001a2394 in emit_mem_initializers (mem_inits=0x0) at ../../gcc/cp/init.c:713
#6  0x001cac54 in finish_mem_initializers (mem_inits=0xdb2ae0) at ../../gcc/cp/semantics.c:1332
#7  0x000a7fb4 in tsubst_expr (t=0x434eb7c0, args=0xd8eda0, complain=tf_warning_or_error, in_decl=0xd89c40) at ../../gcc/cp/pt.c:8195
Comment 3 Andrew Pinski 2006-05-18 04:01:04 UTC
Reducing, I have it down to 43 lines.
Comment 4 Andrew Pinski 2006-05-18 04:25:04 UTC
Confirmed, reduced testcase:
template < class T > struct refcounted : 
virtual T
{
    template < class A1 > refcounted (const A1 & a1) : T () { }
};
struct nfsserv {};
template < class T >
void
sfsserver_cache_alloc (int *ns)
{
    new refcounted < nfsserv > (*ns);
}
void
usage ()
{
    sfsserver_cache_alloc < int > ( 0);
}

if we change sfsserver_cache_alloc to be a non template it works.
If we change the new ... to a local variable it works.
if we change the argument type of sfsserver_cache_alloc to nfsserv, we get a secondary bogus error message:
t.cc: In constructor 'refcounted<T>::refcounted(const A1&) [with A1 = nfsserv, T = nfsserv]':
t.cc:11:   instantiated from 'void sfsserver_cache_alloc(nfsserv*) [with T = int]'
t.cc:16:   instantiated from here
t.cc:4: error: could not convert 'a1' to 'bool'
Comment 5 Andrew Pinski 2006-05-21 21:24:34 UTC
Janis, could you regression hunt on this bug?

Thanks,
Andrew Pinski
Comment 6 Janis Johnson 2006-05-22 19:48:52 UTC
A regression hunt on powerpc-linux using the testcase from comment #4 identified this patch:

http://gcc.gnu.org/viewcvs?view=rev&rev=112869

r112869 | mmitchel | 2006-04-11 22:59:57 +0000 (Tue, 11 Apr 2006)
Comment 7 Mark Mitchell 2006-06-16 02:09:29 UTC
Subject: Bug 27640

Author: mmitchel
Date: Fri Jun 16 02:09:10 2006
New Revision: 114701

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114701
Log:
	PR c++/27640
	* pt.c (instantiate_template): Set processing_template_decl to
	zero while performing substitutions.
	PR c++/27640
	* g++.dg/template/ctor7.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/ctor7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Mark Mitchell 2006-06-16 02:11:47 UTC
Fixed in 4.2.0.