gcc crashed when compile the following example , and report "internal compiler error: Segmentation fault". //comandline: gcc -c a.c /* a.c */ int main() { void fun(a) int a[({void h(){}2;})]; { } return 0; }
Update : $ gcc-7-20170205 -c pr30552.c pr30552.c: In function 'fun': pr30552.c:6:5: internal compiler error: Segmentation fault int a[({void h(){}2;})]; ^~~ 0xbf633f crash_signal ../../gcc/toplev.c:333 0x670701 c_push_function_context() ../../gcc/c/c-decl.c:9504 0x6cf8a2 c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:2038 0x6d3ea2 c_parser_compound_statement_nostart ../../gcc/c/c-parser.c:4831 0x6af37a c_parser_postfix_expression ../../gcc/c/c-parser.c:7665 0x6b939a c_parser_unary_expression ../../gcc/c/c-parser.c:7052 0x6ba1a7 c_parser_cast_expression ../../gcc/c/c-parser.c:6881 0x6ba3c2 c_parser_binary_expression ../../gcc/c/c-parser.c:6690 0x6bb0a5 c_parser_conditional_expression ../../gcc/c/c-parser.c:6458 0x6bb800 c_parser_expr_no_commas ../../gcc/c/c-parser.c:6375 0x6ccebe c_parser_direct_declarator_inner ../../gcc/c/c-parser.c:3591 0x6cea04 c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:1797 0x6cf7ce c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:2073 0x6d3ea2 c_parser_compound_statement_nostart ../../gcc/c/c-parser.c:4831 0x6d44ce c_parser_compound_statement ../../gcc/c/c-parser.c:4740 0x6cf90c c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:2112 0x6d791b c_parser_external_declaration ../../gcc/c/c-parser.c:1468 0x6d8379 c_parser_translation_unit ../../gcc/c/c-parser.c:1348 0x6d8379 c_parse_file() ../../gcc/c/c-parser.c:18185 0x736892 c_common_parse_file() ../../gcc/c-family/c-opts.c:1107
Other test cases : $ cat z1.c void f() { void g() void a[( {void b} )]; } $ cat z2.c int f() { int g() int a[( {int b} )]; }
Confirmed that gcc still ICEs, although I'm not sure if the code is valid or not... I'll leave the "ice-on-valid-code" keyword for now; someone else more knowledgeable than me can change it if necessary.
It appears this is a case where ICEs are the result of poor error detection/recovery with statement expressions in these contexts. Has anyone else looked into this? If not, I'd like to investigate it further to verify what I'm seeing and come up with a solution.
(In reply to Dave Pagan from comment #4) > It appears this is a case where ICEs are the result of poor error > detection/recovery with statement expressions in these contexts. Has anyone > else looked into this? If not, I'd like to investigate it further to verify > what I'm seeing and come up with a solution. Not that I know of; please go ahead!
(In reply to Eric Gallager from comment #5) > (In reply to Dave Pagan from comment #4) > > It appears this is a case where ICEs are the result of poor error > > detection/recovery with statement expressions in these contexts. Has anyone > > else looked into this? If not, I'd like to investigate it further to verify > > what I'm seeing and come up with a solution. > > Not that I know of; please go ahead! Great. Thanks for the quick response, Eric.
Dave on it, then.
Patch submitted for review: https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00621.html
(In reply to Dave Pagan from comment #8) > Patch submitted for review: > > https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00621.html thanks; adding "patch" keyword
Author: law Date: Wed May 2 17:22:26 2018 New Revision: 259849 URL: https://gcc.gnu.org/viewcvs?rev=259849&root=gcc&view=rev Log: PR c/30552 * c-decl.c (old_style_parameter_scope): New function. * c-parser.c (c_parser_postfix_expression): Check for statement expressions in old-style function parameter list declarations. * c-parser.h (old_style_parameter_scope): New extern declaration. PR c/30552 * gcc.dg/noncompile/pr30552-1.c: New test. * gcc.dg/noncompile/pr30552-2.c: New test. * gcc.dg/noncompile/pr30552-3.c: New test. * gcc.dg/noncompile/pr30552-4.c: New test. Added: trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-1.c trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-2.c trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-3.c trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-4.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-decl.c trunk/gcc/c/c-parser.c trunk/gcc/c/c-parser.h trunk/gcc/testsuite/ChangeLog
(In reply to Jeffrey A. Law from comment #10) > Author: law > Date: Wed May 2 17:22:26 2018 > New Revision: 259849 > > URL: https://gcc.gnu.org/viewcvs?rev=259849&root=gcc&view=rev > Log: > PR c/30552 > * c-decl.c (old_style_parameter_scope): New function. > * c-parser.c (c_parser_postfix_expression): Check for statement > expressions in old-style function parameter list declarations. > * c-parser.h (old_style_parameter_scope): New extern declaration. > > PR c/30552 > * gcc.dg/noncompile/pr30552-1.c: New test. > * gcc.dg/noncompile/pr30552-2.c: New test. > * gcc.dg/noncompile/pr30552-3.c: New test. > * gcc.dg/noncompile/pr30552-4.c: New test. > > Added: > trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-1.c > trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-2.c > trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-3.c > trunk/gcc/testsuite/gcc.dg/noncompile/pr30552-4.c > Modified: > trunk/gcc/c/ChangeLog > trunk/gcc/c/c-decl.c > trunk/gcc/c/c-parser.c > trunk/gcc/c/c-parser.h > trunk/gcc/testsuite/ChangeLog So did this fix it?
Yes, it did. I had assumed the bug status would get updated, but it wasn't. I'll set it to resolved.
Fixed with patch noted in comments: https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00621.html
*** Bug 60085 has been marked as a duplicate of this bug. ***