[patch] Fix PR c/28136: ICE with incomplete array type

Volker Reichelt reichelt@igpm.rwth-aachen.de
Thu Jun 22 12:07:00 GMT 2006


The C frontend crashes on the following line of invalid code:

  int i = (struct A[]) {};

bug.c:1: error: array type has incomplete element type
bug.c:1: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in c_parser_postfix_expression_after_paren_type, at c-parser.c:5432
Please submit a full bug report, [etc.]

This is because groktypename called from
c_parser_postfix_expression_after_paren_type
returns an error_mark_node. This triggers an ICE when
C_TYPE_VARIABLE_SIZE is applied to the result.

The patch fixes this by guarding the latter with a check for
error_mark_node.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline and 4.1 branch?

Regards,
Volker

:ADDPATCH C:


2006-06-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/28136
	* c-parser.c (c_parser_postfix_expression_after_paren_type): Robustify.

===================================================================
--- gcc/gcc/c-parser.c	2006-06-20 23:58:38 +0200
+++ gcc/gcc/c-parser.c	2006-06-20 23:55:32 +0200
@@ -5429,7 +5429,7 @@ c_parser_postfix_expression_after_paren_
   struct c_expr expr;
   start_init (NULL_TREE, NULL, 0);
   type = groktypename (type_name);
-  if (C_TYPE_VARIABLE_SIZE (type))
+  if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
     {
       error ("compound literal has variable size");
       type = error_mark_node;
===================================================================

2006-06-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/28136
	* gcc.dg/init-bad-5.c: New test.

===================================================================
--- gcc/gcc/testsuite/gcc.dg/init-bad-5.c	2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/gcc.dg/init-bad-5.c	2006-06-21 00:02:06 +0200
@@ -0,0 +1,5 @@
+/* PR c/28136 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int i = (struct A[]) {};  /* { dg-error "incomplete|empty|initialization" } */
===================================================================




More information about the Gcc-patches mailing list