Bug 71515 - [6 Regression] ICE on valid C++ code on x86_64-linux-gnu: Segmentation fault (program cc1plus)
Summary: [6 Regression] ICE on valid C++ code on x86_64-linux-gnu: Segmentation fault ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 6.5
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2016-06-13 06:21 UTC by Zhendong Su
Modified: 2017-10-11 10:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.4
Known to fail:
Last reconfirmed: 2016-06-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2016-06-13 06:21:07 UTC
The following C++ code causes an ICE when compiled with the current GCC trunk on x86_64-linux-gnu in both 32-bit and 64-bit modes.  

It also affects 4.7.x and later, and is accepted by 4.6.x. 

It might be related to PR 70776, which also crashes 4.6.x (and at least as early as 4.4.x.). 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160612 (experimental) [trunk revision 237336] (GCC) 
$ 
$ g++-4.6 -c small.cpp
$ 
$ g++-trunk -c small.cpp
g++-trunk: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 


---------------------------------------------------------------


template < typename, typename = int > struct A;

template < typename T > struct A < T, typename A < T >::type >
{
  A < int > *a;
};
Comment 1 Martin Liška 2016-06-13 07:56:06 UTC
Confirmed on current trunk, 5.3.1 and 6.1.1 with following back-trace:

#152 0x00000000007bd9c8 in structural_comptypes (t1=0x7ffff69e8690, t2=0x7ffff69e8e70, strict=<optimized out>) at ../../gcc/cp/typeck.c:1286
#153 0x0000000000735b87 in currently_open_class (t=t@entry=0x7ffff69e8e70) at ../../gcc/cp/class.c:7674
#154 0x00000000006f9938 in resolve_typename_type (type=0x7ffff69e8f18, only_current_p=only_current_p@entry=true) at ../../gcc/cp/pt.c:23590
#155 0x00000000007bca62 in structural_comptypes (t1=0x7ffff69e8f18, t2=0x7ffff69e8c78, strict=0) at ../../gcc/cp/typeck.c:1200
#156 0x00000000006be280 in template_args_equal (ot=ot@entry=0x7ffff69e8f18, nt=nt@entry=0x7ffff69e8c78) at ../../gcc/cp/pt.c:7903
#157 0x00000000006bddb3 in comp_template_args (oldargs=0x7ffff69fb028, newargs=newargs@entry=0x7ffff69dfde8, oldarg_ptr=oldarg_ptr@entry=0x0, newarg_ptr=newarg_ptr@entry=0x0) at ../../gcc/cp/pt.c:7950
#158 0x00000000007bd9c8 in structural_comptypes (t1=0x7ffff69e8690, t2=0x7ffff69e8d20, strict=<optimized out>) at ../../gcc/cp/typeck.c:1286
#159 0x0000000000735b87 in currently_open_class (t=t@entry=0x7ffff69e8d20) at ../../gcc/cp/class.c:7674
#160 0x00000000006f5f0b in lookup_template_class_1 (complain=3, entering_scope=0, context=0x0, in_decl=0x0, arglist=0x7ffff69fb190, d1=<optimized out>) at ../../gcc/cp/pt.c:8329
#161 lookup_template_class (d1=d1@entry=0x7ffff69fa000, arglist=arglist@entry=0x7ffff69f79e0, in_decl=in_decl@entry=0x0, context=context@entry=0x0, entering_scope=entering_scope@entry=0, complain=complain@entry=35)
    at ../../gcc/cp/pt.c:8654
#162 0x000000000080e33e in finish_template_type (name=name@entry=0x7ffff69fa000, args=args@entry=0x7ffff69f79e0, entering_scope=0) at ../../gcc/cp/semantics.c:3133
#163 0x0000000000797aaf in cp_parser_template_id (parser=parser@entry=0x7ffff7fedab0, template_keyword_p=template_keyword_p@entry=false, check_dependency_p=<optimized out>, tag_type=tag_type@entry=none_type, 
    is_declaration=is_declaration@entry=true) at ../../gcc/cp/parser.c:14914
#164 0x0000000000797d5f in cp_parser_class_name (parser=parser@entry=0x7ffff7fedab0, typename_keyword_p=typename_keyword_p@entry=false, template_keyword_p=template_keyword_p@entry=false, tag_type=none_type, 
    check_dependency_p=<optimized out>, class_head_p=<optimized out>, is_declaration=true, enum_ok=true) at ../../gcc/cp/parser.c:21218
#165 0x0000000000789247 in cp_parser_qualifying_entity (is_declaration=true, type_p=false, check_dependency_p=true, template_keyword_p=false, typename_keyword_p=false, parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:6245
#166 cp_parser_nested_name_specifier_opt (parser=parser@entry=0x7ffff7fedab0, typename_keyword_p=false, check_dependency_p=check_dependency_p@entry=true, type_p=type_p@entry=false, is_declaration=is_declaration@entry=true)
    at ../../gcc/cp/parser.c:5929
#167 0x0000000000799a42 in cp_parser_nested_name_specifier (is_declaration=true, type_p=false, check_dependency_p=true, typename_keyword_p=false, parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:6168
#168 cp_parser_using_declaration (parser=parser@entry=0x7ffff7fedab0, access_declaration_p=access_declaration_p@entry=true) at ../../gcc/cp/parser.c:17757
#169 0x00000000007a7bc9 in cp_parser_member_declaration (parser=parser@entry=0x7ffff7fedab0) at ../../gcc/cp/parser.c:22322
#170 0x00000000007835ef in cp_parser_member_specification_opt (parser=<optimized out>) at ../../gcc/cp/parser.c:22182
#171 cp_parser_class_specifier_1 (parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:21360
#172 cp_parser_class_specifier (parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:21596
#173 cp_parser_type_specifier (parser=parser@entry=0x7ffff7fedab0, flags=flags@entry=1, decl_specs=decl_specs@entry=0x7fffffffd7d0, is_declaration=is_declaration@entry=true, 
    declares_class_or_enum=declares_class_or_enum@entry=0x7fffffffd760, is_cv_qualifier=is_cv_qualifier@entry=0x7fffffffd75f) at ../../gcc/cp/parser.c:15836
#174 0x0000000000798435 in cp_parser_decl_specifier_seq (parser=parser@entry=0x7ffff7fedab0, flags=flags@entry=1, decl_specs=decl_specs@entry=0x7fffffffd7d0, declares_class_or_enum=declares_class_or_enum@entry=0x7fffffffd7cc)
    at ../../gcc/cp/parser.c:12758
#175 0x00000000007a69e6 in cp_parser_single_declaration (parser=parser@entry=0x7ffff7fedab0, checks=checks@entry=0x0, member_p=member_p@entry=false, explicit_specialization_p=explicit_specialization_p@entry=false, 
    friend_p=friend_p@entry=0x7fffffffd8af) at ../../gcc/cp/parser.c:25782
#176 0x00000000007a6d6d in cp_parser_template_declaration_after_parameters (parser=parser@entry=0x7ffff7fedab0, parameter_list=parameter_list@entry=0x7ffff69f7900, member_p=member_p@entry=false) at ../../gcc/cp/parser.c:25477
#177 0x00000000007a77a9 in cp_parser_explicit_template_declaration (member_p=false, parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:25709
#178 cp_parser_template_declaration_after_export (parser=parser@entry=0x7ffff7fedab0, member_p=<optimized out>) at ../../gcc/cp/parser.c:25727
#179 0x00000000007a79b9 in cp_parser_template_declaration (parser=parser@entry=0x7ffff7fedab0, member_p=member_p@entry=false) at ../../gcc/cp/parser.c:14097
#180 0x00000000007af7da in cp_parser_declaration (parser=parser@entry=0x7ffff7fedab0) at ../../gcc/cp/parser.c:12092
#181 0x00000000007ae027 in cp_parser_declaration_seq_opt (parser=parser@entry=0x7ffff7fedab0) at ../../gcc/cp/parser.c:12022
#182 0x00000000007ae34d in cp_parser_translation_unit (parser=0x7ffff7fedab0) at ../../gcc/cp/parser.c:4324
#183 c_parse_file () at ../../gcc/cp/parser.c:37486
#184 0x000000000090d063 in c_common_parse_file () at ../../gcc/c-family/c-opts.c:1064
#185 0x0000000000d89fff in compile_file () at ../../gcc/toplev.c:465
#186 0x000000000065ae84 in do_compile () at ../../gcc/toplev.c:1998
#187 toplev::main (this=this@entry=0x7fffffffda90, argc=argc@entry=15, argv=argv@entry=0x7fffffffdb98) at ../../gcc/toplev.c:2127
#188 0x000000000065d0d7 in main (argc=15, argv=0x7fffffffdb98) at ../../gcc/main.c:39
Comment 2 Jakub Jelinek 2016-06-13 12:51:23 UTC
I bet this started with r148915 (at least, r148906 works, and r148977 ICEs with infinite recursion).
Comment 3 Jason Merrill 2016-07-24 23:40:37 UTC
Author: jason
Date: Sun Jul 24 23:40:05 2016
New Revision: 238696

URL: https://gcc.gnu.org/viewcvs?rev=238696&root=gcc&view=rev
Log:
	PR c++/71515 - typename in partial specialization

	* pt.c (resolve_typename_type): Try to avoid calling
	currently_open_class.

Added:
    trunk/gcc/testsuite/g++.dg/template/typename22.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 4 Jason Merrill 2016-07-25 21:09:26 UTC
Fixed for gcc 7 so far.
Comment 5 Richard Biener 2016-08-03 12:03:54 UTC
GCC 4.9 branch is being closed
Comment 6 Jason Merrill 2016-12-06 18:52:23 UTC
Author: jason
Date: Tue Dec  6 18:51:50 2016
New Revision: 243313

URL: https://gcc.gnu.org/viewcvs?rev=243313&root=gcc&view=rev
Log:
	PR c++/71515 - typename in partial specialization

	* pt.c (resolve_typename_type): Try to avoid calling
	currently_open_class.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/template/typename22.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/pt.c
Comment 7 Jakub Jelinek 2017-10-10 13:27:01 UTC
GCC 5 branch is being closed
Comment 8 Jakub Jelinek 2017-10-11 10:23:35 UTC
Should be fixed in 6.3+ and 7+.