Bug 39754 - [4.5 Regression] ICE: tree check: accessed elt 2 of tree_vec with 1 elts in tsubst, at cp/pt.c:9248
Summary: [4.5 Regression] ICE: tree check: accessed elt 2 of tree_vec with 1 elts in t...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P1 normal
Target Milestone: 4.5.0
Assignee: Dodji Seketeli
URL:
Keywords: ice-on-valid-code
: 39980 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-04-13 19:32 UTC by Andreas Beckmann
Modified: 2009-05-28 12:42 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.4.0
Known to fail: 4.5.0
Last reconfirmed: 2009-04-14 06:59:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Beckmann 2009-04-13 19:32:32 UTC
The following code produces an ICE in 4.5.0 while previous versions reported an incomplete type error:

========== 8< ==========
template < typename > struct A ;
template < typename U , typename > struct B
{
        typedef U V ;
        A < V * > a ;
} ;
template < typename W > struct C
{
        A < W * > a ;
} ;
C < int > c ;
========== >8 ==========

---------- 4.5.0 ----------
$ x86_64-linux-gnu-g++-trunk -v -c ice-accessed-elt-2-of-tree_vec.ii

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/opt/software/gcc-x86_64/gcc-trunk --program-suffix=-trunk --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20090410 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic'
 /opt/software/gcc-x86_64/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/cc1plus -fpreprocessed ice-accessed-elt-2-of-tree_vec.ii -quiet -dumpbase ice-accessed-elt-2-of-tree_vec.ii -mtune=generic -auxbase ice-accessed-elt-2-of-tree_vec -version -o /tmp/ccSsFbFa.s
GNU C++ (GCC) version 4.5.0 20090412 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.5.0 20090410 (experimental), GMP version 4.2.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: b13346d60276f3352c4b7dd22e3889d7
ice-accessed-elt-2-of-tree_vec.ii: In instantiation of ‘C<int>’:
ice-accessed-elt-2-of-tree_vec.ii:11:   instantiated from here
ice-accessed-elt-2-of-tree_vec.ii:9: internal compiler error: tree check: accessed elt 2 of tree_vec with 1 elts in tsubst, at cp/pt.c:9248
--------------------

---------- 4.4.0 ----------
$ x86_64-linux-gnu-g++-4.4.x -v -c ice-accessed-elt-2-of-tree_vec.ii

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4_4-branch/configure --prefix=/opt/software/gcc-x86_64/gcc-4.4.x --program-suffix=-4.4.x --enable-languages=c,c++ --enable-checking
Thread model: posix
gcc version 4.4.0 20090413 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic'
 /opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/cc1plus -fpreprocessed ice-accessed-elt-2-of-tree_vec.ii -quiet -dumpbase ice-accessed-elt-2-of-tree_vec.ii -mtune=generic -auxbase ice-accessed-elt-2-of-tree_vec -version -o /tmp/ccEdsa3a.s
GNU C++ (GCC) version 4.4.0 20090413 (prerelease) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.0 20090413 (prerelease), GMP version 4.2.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4c95a5cf24794a394976148039ecc611
ice-accessed-elt-2-of-tree_vec.ii: In instantiation of ‘C<int>’:
ice-accessed-elt-2-of-tree_vec.ii:11:   instantiated from here
ice-accessed-elt-2-of-tree_vec.ii:9: error: ‘C<W>::a’ has incomplete type
ice-accessed-elt-2-of-tree_vec.ii:1: error: declaration of ‘struct A<int*>’
--------------------
Comment 1 H.J. Lu 2009-04-13 21:26:38 UTC
It is caused by revision 145440:

http://gcc.gnu.org/ml/gcc-cvs/2009-04/msg00060.html
Comment 2 Andreas Beckmann 2009-04-14 07:04:00 UTC
An updated testcase that compiles without errors on 4.4.0:

========== 8< ==========
template < typename > struct A ;
template < typename T , typename = A < T > > struct B
{ } ;
template < class W , class > struct D
{
        typedef W X ;
        A < X * > a ;
} ;
template < class Y > struct E
{
        B < Y * > b ;
} ;
E < int > e ;
========== >8 ==========
Comment 3 Richard Biener 2009-04-14 10:14:27 UTC
I also see this.
Comment 4 Jason Merrill 2009-04-14 14:07:17 UTC
Subject: Re:  [4.5 Regression] ICE: tree check: accessed elt
 2 of tree_vec with 1 elts in tsubst, at cp/pt.c:9248

I wonder if it only works on 4.4 because tree checking is disabled on 
release branches.

Jason
Comment 5 Andreas Beckmann 2009-04-16 14:28:47 UTC
It does compile successfully using 4.4.0 built with --enable-checking. Is there anyting else to enable these tree checks?

$ x86_64-linux-gnu-g++-4.4.x -v -c PR39754.min.ii && echo SUCCESS

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4_4-branch/configure --prefix=/opt/software/gcc-x86_64/gcc-4.4.x --program-suffix=-4.4.x --enable-languages=c,c++ --enable-checking
Thread model: posix
gcc version 4.4.0 20090413 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic'
 /opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/cc1plus -fpreprocessed PR39754.min.ii -quiet -dumpbase PR39754.min.ii -mtune=generic -auxbase PR39754.min -version -o /tmp/ccH60tOe.s
GNU C++ (GCC) version 4.4.0 20090413 (prerelease) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.0 20090413 (prerelease), GMP version 4.2.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4c95a5cf24794a394976148039ecc611
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic'
 as -V -Qy -o PR39754.min.o /tmp/ccH60tOe.s
GNU assembler version 2.19.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.19.1
COMPILER_PATH=/opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/:/opt/software/gcc-x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/software/gcc-x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/opt/software/gcc-x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/software/gcc-x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/software/gcc-x86_64/gcc-4.4.x/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=generic'
SUCCESS
Comment 6 Dodji Seketeli 2009-04-21 14:40:42 UTC
In this test case (the last one), the short description of the problem is that we fail at getting canonical types of template arguments when said arguments have composed types.

Let me give the longer description as well, so that I don't forget :)

1/  During the instantiation of E<int>, we try to instantiate the default argument A<T> of the template B with T=int*.

2/ At that point, lookup_template_class selects the A<X*> specialization that was first seen in struct D. There, X was a typedef of W, W being a template parameter of struct D.

3/In the context of 1/, we try to tsubst  A<T> with T=int* - actually we try to tsubst the A<X*> specialization of A<T>.  In tsubst, we then try to reuse the typedef declaration of T, if T is a typedef.

A problem arises in 3/ because T is seen as a typedef of W (remember 2/) but W doesn't have any meaning in the context of 1/, hence the crash.

Normally, template arguments are converted to their "canonical type variant" before the stubst-ing process starts. The canonical type variant of a typedef type variant is basically its qualified main type variant.
E.g. in typedef const int Foo, the canonical type variant of Foo is const int.
The function doing that conversion is canonical_type_variant.

The root cause of the problem is that canonical_type_variant doesn't give us canonical variants of composed types.
E.g. in typedef int Foo; The canoniacl type variant of Foo* should be int*.
The current implementation of canonical_type_variant returns Foo* instead of int* in that case.

So I am testing some patches that change the implementation of canonical_type_variant atm.
Comment 7 Richard Biener 2009-05-01 20:03:59 UTC
*** Bug 39980 has been marked as a duplicate of this bug. ***
Comment 8 Dodji Seketeli 2009-05-26 16:58:08 UTC
A patch was submitted at http://gcc.gnu.org/ml/gcc-patches/2009-05/msg01655.html.
Comment 9 Dodji Seketeli 2009-05-28 11:24:35 UTC
Subject: Bug 39754

Author: dodji
Date: Thu May 28 11:24:18 2009
New Revision: 147951

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147951
Log:
Fix for PR c++/PR39754

gcc/cp/ChangeLog:
    PR c++/39754
    * cp-tree.h (canonical_type_variant): Remove this function declaration.
    (strip_typedefs): New function declaration.
    * tree.c (strip_typedefs): New function definition.
    (canonical_type_variant): Remove function definition.
    * cvt.c (convert_from_reference): No need to use
    canonical_type_variant.
    * typeck.c (cp_build_indirect_ref): Likewise.
    * error.c (dump_template_bindings): Use strip_typedefs instead of
    canonical_type_variant.
    * pt.c (convert_template_argument, unify): Likewise.
    * mangle.c (canonicalize_for_substitution): Don't use
    canonical_type_variant.

gcc/testsuite/ChangeLog:
    PR c++/39754
    * g++.dg/template/canon-type-1.C: New test.
    * g++.dg/template/canon-type-2.C: Likewise.
    * g++.dg/template/canon-type-3.C: Likewise.
    * g++.dg/template/canon-type-4.C: Likewise.
    * g++.dg/template/canon-type-5.C: Likewise.
    * g++.dg/template/canon-type-6.C: Likewise.
    * g++.dg/template/canon-type-7.C: Likewise.


Added:
    trunk/gcc/testsuite/g++.dg/template/canon-type-1.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-2.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-3.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-4.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-5.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-6.C
    trunk/gcc/testsuite/g++.dg/template/canon-type-7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/cvt.c
    trunk/gcc/cp/error.c
    trunk/gcc/cp/mangle.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Dodji Seketeli 2009-05-28 12:42:39 UTC
Fixed in gcc 4.5.
Comment 11 hjl@gcc.gnu.org 2009-05-30 13:50:06 UTC
Subject: Bug 39754

Author: hjl
Date: Sat May 30 13:49:33 2009
New Revision: 148004

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148004
Log:
2009-05-30  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:

	2009-05-28  Dodji Seketeli  <dodji@redhat.com>

	PR c++/39754
	* g++.dg/template/canon-type-1.C: New test.
	* g++.dg/template/canon-type-2.C: Likewise.
	* g++.dg/template/canon-type-3.C: Likewise.
	* g++.dg/template/canon-type-4.C: Likewise.
	* g++.dg/template/canon-type-5.C: Likewise.
	* g++.dg/template/canon-type-6.C: Likewise.
	* g++.dg/template/canon-type-7.C: Likewise.

	2009-05-28  Ira Rosen  <irar@il.ibm.com>

	PR tree-optimization/40254
	* gcc.dg/vect/pr40254.c: New test.

	2009-05-26  Richard Guenther  <rguenther@suse.de>

	PR middle-end/40252
	* gcc.c-torture/compile/pr40252.c: New testcase.

	2009-05-26  Dodji Seketeli  <dodji@redhat.com>

	PR c++/40007
	* g++.dg/template/typedef18.C: New test.
	* g++.dg/template/typedef19.C: Likewise.
	* g++.dg/template/typedef20.C: Likewise.

	2009-05-25  Ira Rosen  <irar@il.ibm.com>

	PR tree-optimization/40238
	* gcc.dg/vect/pr40238.c: New test.

	2009-05-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/40233
	* gcc.c-torture/compile/pr40233.c: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-1.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-1.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-2.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-2.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-3.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-3.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-4.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-4.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-5.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-5.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-6.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-6.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/canon-type-7.C
      - copied unchanged from r148002, trunk/gcc/testsuite/g++.dg/template/canon-type-7.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/typedef18.C
      - copied unchanged from r148003, trunk/gcc/testsuite/g++.dg/template/typedef18.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/typedef19.C
      - copied unchanged from r148003, trunk/gcc/testsuite/g++.dg/template/typedef19.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/typedef20.C
      - copied unchanged from r148003, trunk/gcc/testsuite/g++.dg/template/typedef20.C
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr40233.c
      - copied unchanged from r148003, trunk/gcc/testsuite/gcc.c-torture/compile/pr40233.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr40252.c
      - copied unchanged from r148003, trunk/gcc/testsuite/gcc.c-torture/compile/pr40252.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/pr40238.c
      - copied unchanged from r148003, trunk/gcc/testsuite/gcc.dg/vect/pr40238.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/vect/pr40254.c
      - copied unchanged from r148003, trunk/gcc/testsuite/gcc.dg/vect/pr40254.c
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog