Bug 41144 - [4.5 Regression] ice for legal code with -O2 in get_alias_set
Summary: [4.5 Regression] ice for legal code with -O2 in get_alias_set
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-08-21 19:58 UTC by David Binderman
Modified: 2009-09-06 16:50 UTC (History)
2 users (show)

See Also:
Host: x86_64-suse-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-08-24 10:29:36


Attachments
C++ source code (61.43 KB, text/plain)
2009-08-21 20:00 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2009-08-21 19:58:45 UTC
I just tried to compile Suse Linux package agg-2.5-158.64
with the g++ 4.5 mainline snapshot 20090820
and the compiler said

In file included from aa_test.cpp:13:0:
../include/agg_span_gouraud_rgba.h: In member function 'void agg::span_gouraud_rgba<ColorT>::prepare() [with ColorT = agg::rgba8]':
../include/agg_span_gouraud_rgba.h:127:31: internal compiler error: in get_alias_set, at alias.c:694
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Preprocessed source attached. Flag -O2 required.
Comment 1 David Binderman 2009-08-21 20:00:01 UTC
Created attachment 18409 [details]
C++ source code
Comment 2 Richard Biener 2009-08-24 09:26:33 UTC
Reducing.
Comment 3 Richard Biener 2009-08-24 10:29:36 UTC
Confirmed.  Mine.

struct rgba8;
template<class ColorT> class span_gouraud     {
public:
    struct coord_type { };
    coord_type m_coord[3];
};
template<class ColorT> class span_gouraud_rgba : public span_gouraud<ColorT>     {
    typedef ColorT color_type;
    typedef span_gouraud<color_type> base_type;
    typedef typename base_type::coord_type coord_type;
public:
    void prepare()         {
        coord_type coord[3];
    }
};
void the_application() {
    typedef span_gouraud_rgba<rgba8> gouraud_span_gen_type;
    gouraud_span_gen_type span_gouraud;
    span_gouraud.prepare();
}

ICEs at -fstrict-aliasing.
Comment 4 Richard Biener 2009-08-24 12:53:21 UTC
We're layouting an array with incomplete element type and get into

        if (!TYPE_SIZE (element))
          /* We don't know the size of the underlying element type, so
             our alignment calculations will be wrong, forcing us to
             fall back on structural equality. */
          SET_TYPE_STRUCTURAL_EQUALITY (type);

later re-using this type when building the same array type with complete
element type as the canonical variant.

IMHO the above is simply bogus.

To test patch:

Index: stor-layout.c
===================================================================
--- stor-layout.c       (revision 151050)
+++ stor-layout.c       (working copy)
@@ -2020,11 +2020,6 @@ layout_type (tree type)
 #else
        TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
 #endif
-       if (!TYPE_SIZE (element))
-         /* We don't know the size of the underlying element type, so
-            our alignment calculations will be wrong, forcing us to
-            fall back on structural equality. */
-         SET_TYPE_STRUCTURAL_EQUALITY (type);
        TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element);
        SET_TYPE_MODE (type, BLKmode);
        if (TYPE_SIZE (type) != 0
Comment 5 Richard Biener 2009-08-25 10:35:13 UTC
/space/rguenther/trunk/gcc/testsuite/g++.old-deja/g++.pt/spec26.C:11:36: internal compiler error: canonical types differ for identical types const X [] and const X []^M
Please submit a full bug report,^M
with preprocessed source if appropriate.^M
See <http://gcc.gnu.org/bugs.html> for instructions.^M

FAIL: g++.old-deja/g++.pt/spec26.C (internal compiler error)
FAIL: g++.old-deja/g++.pt/spec26.C (test for excess errors)

bah.
Comment 6 Richard Biener 2009-09-06 14:04:29 UTC
The future canonical type with structual equality set is built from

#0  0x089afcf4 in build_array_type (elt_type=0xb7d75620, index_type=0xb7d734d0)
    at /home/richard/src/trunk/gcc/tree.c:6906
#1  0x082ecaa7 in build_cplus_array_type_1 (elt_type=0xb7d75620, 
    index_type=0xb7d734d0) at /home/richard/src/trunk/gcc/cp/tree.c:649
#2  0x082ecd0b in build_cplus_array_type (elt_type=0xb7d75620, 
    index_type=0xb7d734d0) at /home/richard/src/trunk/gcc/cp/tree.c:669
#3  0x0818fa4a in tsubst (t=0xb7d73540, args=0xb7d62d58, complain=3, 
    in_decl=0xb7d68540) at /home/richard/src/trunk/gcc/cp/pt.c:9909
#4  0x08188473 in tsubst_decl (t=0xb7d68540, args=0xb7d62d58, complain=3)
    at /home/richard/src/trunk/gcc/cp/pt.c:8859
#5  0x0818affd in tsubst (t=0xb7d68540, args=0xb7d62d58, complain=3, 
    in_decl=0x0) at /home/richard/src/trunk/gcc/cp/pt.c:9382
#6  0x0817bce9 in instantiate_class_template (type=0xb7d75460)
    at /home/richard/src/trunk/gcc/cp/pt.c:7523
#7  0x0826dea8 in complete_type (type=0xb7d75460)
    at /home/richard/src/trunk/gcc/cp/typeck.c:130
#8  0x0826dec4 in complete_type_or_else (type=0xb7d75460, value=0x0)
    at /home/richard/src/trunk/gcc/cp/typeck.c:142
#9  0x081313c8 in xref_basetypes (ref=0xb7d752a0, base_list=0xb7d62dac)
    at /home/richard/src/trunk/gcc/cp/decl.c:10770
#10 0x0817aeeb in instantiate_class_template (type=0xb7d752a0)
    at /home/richard/src/trunk/gcc/cp/pt.c:7411
#11 0x0826dea8 in complete_type (type=0xb7d753f0)
    at /home/richard/src/trunk/gcc/cp/typeck.c:130
#12 0x08109ed7 in start_decl_1 (decl=0xb7d68600, initialized=0 '\0')
    at /home/richard/src/trunk/gcc/cp/decl.c:4299
#13 0x08109c8a in start_decl (declarator=0x8ff42d8, declspecs=0xbfffef28, 
    initialized=0, attributes=0x0, prefix_attributes=0x0, 
    pushed_scope_p=0xbfffee90) at /home/richard/src/trunk/gcc/cp/decl.c:4262
#14 0x082503a1 in cp_parser_init_declarator (parser=0xb7fde6b4, 
...

with element type

 <record_type 0xb7d75620 coord_type type_5 VOID
    align 8 symtab 0 alias set -1 canonical type 0xb7d75620 context <record_type 0xb7d75460 span_gouraud>
    full-name "struct span_gouraud<rgba8>::coord_type"
    no-binfo use_template=1 interface-unknown
    chain <type_decl 0xb7d75690 coord_type>>

thus layout_type() re-sets the original TYPE_CANONICAL (t) == t to NULL.

Later the frontend completes that coord_type and thus following array
types using that element type are no longer falling back to structural
equality by default:

#0  finalize_record_size (rli=0x8fdbf98)
    at /home/richard/src/trunk/gcc/stor-layout.c:1482
#1  0x087a4005 in finish_record_layout (rli=0x8fdbf98, free_p=1)
    at /home/richard/src/trunk/gcc/stor-layout.c:1707
#2  0x081ff0ef in layout_class_type (t=0xb7d75620, virtuals_p=0xbfffdb00)
    at /home/richard/src/trunk/gcc/cp/class.c:5192
#3  0x08200198 in finish_struct_1 (t=0xb7d75620)
    at /home/richard/src/trunk/gcc/cp/class.c:5297
#4  0x0817c5cb in instantiate_class_template (type=0xb7d75620)
    at /home/richard/src/trunk/gcc/cp/pt.c:7704
#5  0x0826dea8 in complete_type (type=0xb7d75620)
    at /home/richard/src/trunk/gcc/cp/typeck.c:130
#6  0x0826da29 in complete_type (type=0xb7d75700)
    at /home/richard/src/trunk/gcc/cp/typeck.c:115
#7  0x0817be9f in instantiate_class_template (type=0xb7d75460)
    at /home/richard/src/trunk/gcc/cp/pt.c:7556
#8  0x0826dea8 in complete_type (type=0xb7d75460)
    at /home/richard/src/trunk/gcc/cp/typeck.c:130
#9  0x0826dec4 in complete_type_or_else (type=0xb7d75460, value=0x0)
    at /home/richard/src/trunk/gcc/cp/typeck.c:142
#10 0x081313c8 in xref_basetypes (ref=0xb7d752a0, base_list=0xb7d62dac)
    at /home/richard/src/trunk/gcc/cp/decl.c:10770
#11 0x0817aeeb in instantiate_class_template (type=0xb7d752a0)
    at /home/richard/src/trunk/gcc/cp/pt.c:7411
#12 0x0826dea8 in complete_type (type=0xb7d753f0)
    at /home/richard/src/trunk/gcc/cp/typeck.c:130
#13 0x08109ed7 in start_decl_1 (decl=0xb7d68600, initialized=0 '\0')
    at /home/richard/src/trunk/gcc/cp/decl.c:4299

So either the C++ frontend should be more careful and completing the element
type first before building an array type or we need to not look up the
structual equality marked array type when building the canonical type for
our second array type we build (where the element type is not the canonical
type).  This 2nd version is easy enough to implement.
Comment 7 Richard Biener 2009-09-06 16:50:03 UTC
Subject: Bug 41144

Author: rguenth
Date: Sun Sep  6 16:49:48 2009
New Revision: 151461

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151461
Log:
2009-09-06  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41144
	* tree.c (build_array_type): Do not record types marked
	with structural equality in the canonical type hashtable.

	* g++.dg/torture/pr41144.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr41144.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c

Comment 8 Richard Biener 2009-09-06 16:50:34 UTC
Fixed.
Comment 9 hjl@gcc.gnu.org 2009-09-10 18:58:51 UTC
Subject: Bug 41144

Author: hjl
Date: Thu Sep 10 18:57:46 2009
New Revision: 151611

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

	Backport from mainline:
	2009-09-10  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41257
	* g++.dg/torture/pr41257-2.C: New testcase.

	2009-09-08  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/41229
	PR debug/41291
	PR debug/41300
	* gfortran.dg/pr41229.f90: New.

	2009-09-08  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/41232
	* gcc.dg/pr41232.c: New.

	2009-09-07  Martin Jambor  <mjambor@suse.cz>

	PR middle-end/41282
	* gcc.c-torture/compile/pr41282.c: New test.

	2009-09-06  Jakub Jelinek  <jakub@redhat.com>

	PR bootstrap/41241
	* gcc.dg/pr41241.c: New test.

	2009-09-06  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41144
	* g++.dg/torture/pr41144.C: New testcase.

	2009-09-06  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41261
	* gcc.dg/torture/pr41261.c: New testcase.

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

	PR middle-end/41181
	* gcc.c-torture/compile/pr41181.c: New testcase.

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

	PR debug/41273
	* g++.dg/torture/pr41273.C: New testcase.

	2009-09-04  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/41225
	* gfortran.dg/pr41225.f90: New.

	2009-09-04  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41257
	* g++.dg/torture/pr41257.C: New testcase.

	2009-09-04  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/41112
	* gnat.dg/array8.adb: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr41144.C
      - copied unchanged from r151610, trunk/gcc/testsuite/g++.dg/torture/pr41144.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr41257-2.C
      - copied unchanged from r151609, trunk/gcc/testsuite/g++.dg/torture/pr41257-2.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr41257.C
      - copied unchanged from r151610, trunk/gcc/testsuite/g++.dg/torture/pr41257.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr41273.C
      - copied unchanged from r151610, trunk/gcc/testsuite/g++.dg/torture/pr41273.C
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr41181.c
      - copied unchanged from r151610, trunk/gcc/testsuite/gcc.c-torture/compile/pr41181.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr41282.c
      - copied unchanged from r151609, trunk/gcc/testsuite/gcc.c-torture/compile/pr41282.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr41232.c
      - copied unchanged from r151609, trunk/gcc/testsuite/gcc.dg/pr41232.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr41241.c
      - copied unchanged from r151610, trunk/gcc/testsuite/gcc.dg/pr41241.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr41261.c
      - copied unchanged from r151610, trunk/gcc/testsuite/gcc.dg/torture/pr41261.c
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/pr41225.f90
      - copied unchanged from r151610, trunk/gcc/testsuite/gfortran.dg/pr41225.f90
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/pr41229.f90
      - copied unchanged from r151609, trunk/gcc/testsuite/gfortran.dg/pr41229.f90
    branches/gcc-4_4-branch/gcc/testsuite/gnat.dg/array8.adb
      - copied unchanged from r151610, trunk/gcc/testsuite/gnat.dg/array8.adb
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog