Bug 90108 - ICE: Segmentation fault (in c_tree_chain_next)
Summary: ICE: Segmentation fault (in c_tree_chain_next)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 7.5
Assignee: Jakub Jelinek
URL:
Keywords: GC
Depends on:
Blocks:
 
Reported: 2019-04-16 02:05 UTC by Arseny Solokha
Modified: 2019-08-30 13:33 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.4, 8.3.1, 9.0
Known to fail: 5.5.0, 6.3.0, 7.4.0, 8.3.0
Last reconfirmed: 2019-04-16 00:00:00


Attachments
gcc9-pr90108.patch (700 bytes, patch)
2019-04-17 07:34 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arseny Solokha 2019-04-16 02:05:50 UTC
g++-9.0.0-alpha20190414 snapshot (r270355), 8.3, 7.4, 6.3, 5.5 all ICE when compiling gcc/testsuite/c-c++-common/pr89933.c w/ --param ggc-min-heapsize=0:

% g++-9.0.0-alpha20190414 --param ggc-min-heapsize=0 -c gcc/testsuite/c-c++-common/pr89933.c
gcc/testsuite/c-c++-common/pr89933.c:5:71: internal compiler error: Segmentation fault
    5 | typedef unsigned int a __attribute__ ((__aligned__(8), __may_alias__));
      |                                                                       ^
0xf780df crash_signal
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/toplev.c:326
0xa3c507 c_tree_chain_next
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/c-family/c-common.h:1197
0xa3c507 gt_ggc_mx_lang_tree_node(void*)
	./gt-cp-tree.h:110
0xa3d7a2 gt_ggc_mx_lang_tree_node(void*)
	./gt-cp-tree.h:441
0xa3d6e9 gt_ggc_mx_lang_tree_node(void*)
	./gt-cp-tree.h:420
0xa3d47a gt_ggc_mx_lang_tree_node(void*)
	./gt-cp-tree.h:336
0xcbaf04 ggc_mark_root_tab
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/ggc-common.c:77
0xcbb10c ggc_mark_roots()
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/ggc-common.c:94
0xae542f ggc_collect()
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/ggc-page.c:2201
0x91e775 c_parse_final_cleanups()
	/var/tmp/portage/sys-devel/gcc-9.0.0_alpha20190414/work/gcc-9-20190414/gcc/cp/decl2.c:4819
Comment 1 Martin Liška 2019-04-16 07:17:37 UTC
Confirmed.
Comment 2 Richard Biener 2019-04-16 08:04:12 UTC
So we have a non-GCed INTEGER_TYPE that has a GCed TYPE_NAME.  IIRC changes
there recently, PR89933.

We free that TYPE_NAME here (as expected...):

#1  0x00000000009584ee in duplicate_decls (
    newdecl=<type_decl 0x7ffff6988720 a>, 
    olddecl=<type_decl 0x7ffff6988688 a>, newdecl_is_friend=false)
    at /space/rguenther/src/svn/trunk2/gcc/cp/decl.c:2793
2793      ggc_free (newdecl);

Jakub - you fiddled here, can you look at this one, too?
Comment 3 Jakub Jelinek 2019-04-17 07:34:07 UTC
Created attachment 46184 [details]
gcc9-pr90108.patch

Untested fix.
Comment 4 Jakub Jelinek 2019-04-19 08:24:59 UTC
Author: jakub
Date: Fri Apr 19 08:24:05 2019
New Revision: 270453

URL: https://gcc.gnu.org/viewcvs?rev=270453&root=gcc&view=rev
Log:
	PR c++/90108
	* c-decl.c (merge_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* decl.c (duplicate_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* c-c++-common/pr90108.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr90108.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2019-04-19 12:00:12 UTC
Fixed on the trunk.
Comment 6 Jakub Jelinek 2019-04-30 21:08:08 UTC
Author: jakub
Date: Tue Apr 30 21:07:37 2019
New Revision: 270754

URL: https://gcc.gnu.org/viewcvs?rev=270754&root=gcc&view=rev
Log:
	Backported from mainline
	2019-04-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/90108
	* c-decl.c (merge_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* decl.c (duplicate_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* c-c++-common/pr90108.c: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/c-c++-common/pr90108.c
Modified:
    branches/gcc-8-branch/gcc/c/ChangeLog
    branches/gcc-8-branch/gcc/c/c-decl.c
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/decl.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2019-05-01 07:19:10 UTC
Fixed for 8.4+ too.
Comment 8 Marek Polacek 2019-08-11 14:05:04 UTC
Jakub, do you plan to backport it to 7?  If not, let's close it.
Comment 9 Jakub Jelinek 2019-08-30 12:39:02 UTC
Author: jakub
Date: Fri Aug 30 12:38:31 2019
New Revision: 275150

URL: https://gcc.gnu.org/viewcvs?rev=275150&root=gcc&view=rev
Log:
	Backported from mainline
	2019-04-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/90108
	* c-decl.c (merge_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* decl.c (duplicate_decls): If remove is main variant and
	DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
	variant that has newdecl as TYPE_NAME if any.

	* c-c++-common/pr90108.c: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/c-c++-common/pr90108.c
Modified:
    branches/gcc-7-branch/gcc/c/ChangeLog
    branches/gcc-7-branch/gcc/c/c-decl.c
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/decl.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2019-08-30 13:33:31 UTC
Fixed.