This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c/27718: ICE with sizeof of incomplete type


The C frontend stumbles over the following invalid code snippet since
GCC 4.0.0:

  int i = sizeof(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_expr_sizeof_type, at c-typeck.c:2136
Please submit a full bug report, [etc.]

The problem is that C_TYPE_VARIABLE_SIZE in the statement
  pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
in c_expr_sizeof_type cannot handle error_mark_nodes.

The patch fixes this by checking for error_mark_node and passing false
to pop_maybe_used in this case. Btw, error_mark_nodes are handled
similarly in c_expr_sizeof_expr a couple of lines above c_expr_sizeof_type.

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

Regards,
Volker

:ADDPATCH C:


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

	PR c/27718
	* c-typeck.c (c_expr_sizeof_type): Handle invalid types.

===================================================================
--- gcc/gcc/c-typeck.c	2006-05-08 22:57:52 +0200
+++ gcc/gcc/c-typeck.c	2006-05-22 00:49:44 +0200
@@ -2133,7 +2133,8 @@ c_expr_sizeof_type (struct c_type_name *
   type = groktypename (t);
   ret.value = c_sizeof (type);
   ret.original_code = ERROR_MARK;
-  pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
+  pop_maybe_used (type != error_mark_node ? C_TYPE_VARIABLE_SIZE (type)
+					  : false);
   return ret;
 }
 
===================================================================

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

	PR c/27718
	* gcc.dg/sizeof-1.c: New test.

===================================================================
--- gcc/gcc/testsuite/gcc.dg/sizeof-1.c	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/gcc.dg/sizeof-1.c	2006-05-21 16:27:57 +0200
@@ -0,0 +1,4 @@
+/* PR c/27718 */
+/* { dg-do compile } */
+
+int i = sizeof(struct A[]);  /* { dg-error "incomplete" } */
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]