Bug 30552 - gcc crashes when compiling examples with GNU statement expressions in VLAs (also involved: nested functions declared K&R-style)
Summary: gcc crashes when compiling examples with GNU statement expressions in VLAs (a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: 9.0
Assignee: Dave Pagan
URL:
Keywords: error-recovery, ice-on-invalid-code, patch
: 60085 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-01-23 01:41 UTC by Chen Wanjun
Modified: 2024-01-26 00:55 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3, 4.1.0, 4.2.0, 4.3.0, 8.0
Last reconfirmed: 2017-07-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chen Wanjun 2007-01-23 01:41:11 UTC
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;
}
Comment 1 Gerhard Steinmetz 2017-02-07 17:18:46 UTC
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
Comment 2 Gerhard Steinmetz 2017-02-07 17:19:41 UTC
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} )];
}
Comment 3 Eric Gallager 2017-07-31 02:54:05 UTC
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.
Comment 4 Dave Pagan 2017-12-18 23:35:15 UTC
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.
Comment 5 Eric Gallager 2017-12-19 13:00:31 UTC
(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!
Comment 6 Dave Pagan 2017-12-19 18:38:21 UTC
(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.
Comment 7 Paolo Carlini 2017-12-21 20:26:49 UTC
Dave on it, then.
Comment 8 Dave Pagan 2018-03-13 22:12:16 UTC
Patch submitted for review:

https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00621.html
Comment 9 Eric Gallager 2018-03-14 01:19:15 UTC
(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
Comment 10 Jeffrey A. Law 2018-05-02 17:22:58 UTC
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
Comment 11 Eric Gallager 2018-08-02 01:37:57 UTC
(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?
Comment 12 Dave Pagan 2018-08-02 17:45:42 UTC
Yes, it did. I had assumed the bug status would get updated, but it wasn't. I'll set it to resolved.
Comment 13 Dave Pagan 2018-08-02 17:48:26 UTC
Fixed with patch noted in comments:

https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00621.html
Comment 14 Andrew Pinski 2021-12-13 04:33:05 UTC
*** Bug 60085 has been marked as a duplicate of this bug. ***