Bug 54652 - [4.7/4.8/4.9 Regression] ICE with -g
Summary: [4.7/4.8/4.9 Regression] ICE with -g
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.1
: P2 normal
Target Milestone: 4.7.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2012-09-21 09:48 UTC by Jakub Jelinek
Modified: 2014-01-28 13:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail: 4.0.0, 4.1.0, 4.2.0, 4.3.0, 4.4.0, 4.5.0, 4.6.0, 4.7.0, 4.8.0, 4.9.0
Last reconfirmed: 2013-10-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2012-09-21 09:48:41 UTC
typedef unsigned long L __attribute__ ((aligned));
typedef unsigned long L __attribute__ ((aligned));

template <typename T>
struct S
{
  union U { L l; } u;
};

S <int> s;

ICEs with -g, TYPE_NAME seems to be garbage.
The problem is that handle_aligned_attribute first (with L as decl):
          tree tt = TREE_TYPE (decl);
          *type = build_variant_type_copy (*type);
          DECL_ORIGINAL_TYPE (decl) = tt;
          TYPE_NAME (*type) = decl;
          TREE_USED (*type) = TREE_USED (decl);
          TREE_TYPE (decl) = *type;
then duplicate_decls is called on the L olddecl (with new L as newdecl), where TYPE_NAME (TREE_TYPE (olddecl)) == olddecl and
TYPE_NAME (TREE_TYPE (newdecl)) == newdecl, in merge_types newdecl's type wins, and eventually ggc_free (newdecl);
So, either something should have changed TYPE_NAME (newtype) from newdecl to olddecl before ggc_free (I guess that would be preferred, but can't it be TYPE_NAME of other related types too?), or we shouldn't ggc_free TYPE_DECLs.
Jason, can you please look into this?
Comment 1 Volker Reichelt 2013-10-19 22:44:18 UTC
Confirmed. Even shorter testcase (which crashes since GCC 4.0.0):

=====================================================
typedef unsigned L __attribute__ ((aligned));
typedef unsigned L __attribute__ ((aligned));

L l;
=====================================================

bug.cc:4:4: internal compiler error: tree check: expected identifier_node, have <invalid tree code> in modified_type_die, at dwarf2out.c:10376
 L l;
    ^
0xd15bb4 tree_check_failed(tree_node const*, char const*, int, char const*, ...)
        ../../gcc/gcc/tree.c:9301
0x8844b0 tree_check
        ../../gcc/gcc/tree.h:2674
0x8844b0 modified_type_die
        ../../gcc/gcc/dwarf2out.c:10376
0x8859b9 add_type_attribute
        ../../gcc/gcc/dwarf2out.c:16717
0x892dd0 gen_variable_die
        ../../gcc/gcc/dwarf2out.c:18621
0x87eea1 gen_decl_die
        ../../gcc/gcc/dwarf2out.c:20294
0xb17633 emit_debug_global_declarations(tree_node**, int)
        ../../gcc/gcc/toplev.c:531
0x55a520 wrapup_globals_for_namespace(tree_node*, void*)
        ../../gcc/gcc/cp/decl.c:876
0x55759c walk_namespaces_r
        ../../gcc/gcc/cp/decl.c:843
0x625533 cp_write_global_declarations()
        ../../gcc/gcc/cp/decl2.c:4455
Please submit a full bug report, [etc.]
Comment 2 Richard Biener 2013-10-25 11:21:13 UTC
re-confirmed on trunk.
Comment 3 Jason Merrill 2014-01-28 04:32:02 UTC
Author: jason
Date: Tue Jan 28 04:31:30 2014
New Revision: 207169

URL: http://gcc.gnu.org/viewcvs?rev=207169&root=gcc&view=rev
Log:
	PR c++/54652
	* decl.c (duplicate_decls): Always use oldtype for TYPE_DECL.

Added:
    trunk/gcc/testsuite/g++.dg/ext/attrib48.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
Comment 4 Jason Merrill 2014-01-28 13:45:40 UTC
Author: jason
Date: Tue Jan 28 13:45:08 2014
New Revision: 207191

URL: http://gcc.gnu.org/viewcvs?rev=207191&root=gcc&view=rev
Log:
	PR c++/54652
	* decl.c (duplicate_decls): Always use oldtype for TYPE_DECL.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/ext/attrib48.C
Modified:
    branches/gcc-4_8-branch/gcc/cp/ChangeLog
    branches/gcc-4_8-branch/gcc/cp/decl.c
Comment 5 Jason Merrill 2014-01-28 13:51:38 UTC
Fixed.
Comment 6 Jason Merrill 2014-01-28 13:51:47 UTC
Author: jason
Date: Tue Jan 28 13:51:15 2014
New Revision: 207192

URL: http://gcc.gnu.org/viewcvs?rev=207192&root=gcc&view=rev
Log:
	PR c++/54652
	* decl.c (duplicate_decls): Always use oldtype for TYPE_DECL.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/ext/attrib48.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/decl.c