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/35748: ICE with cast to unions with invalid fields


The following patch fixes an ICE with casting to unions with invalid
fields. When casting to a union, build_c_cast iterates over all fields
of the union to find a suitable one for the cast.
However, this test crashes if a field with invalid type is encountered.
Fixed by skipping these invalid fields.

Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline?

Regards,
Volker

:ADDPATCH C:


2008-03-30  Volker Reichelt  <v.reichelt@netcologne.de>

	PR c/35748
	* c-typeck.c (build_c_cast): Skip invalid fields in unions.

===================================================================
--- gcc/c-typeck.c	2008-03-20 17:13:55 +0100
+++ gcc/c-typeck.c	2008-03-29 20:45:36 +0100
@@ -3628,8 +3628,9 @@ build_c_cast (tree type, tree expr)
       tree field;
 
       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
-	if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
-		       TYPE_MAIN_VARIANT (TREE_TYPE (value))))
+	if (TREE_TYPE (field) != error_mark_node
+	    && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
+			  TYPE_MAIN_VARIANT (TREE_TYPE (value))))
 	  break;
 
       if (field)
===================================================================

2008-03-30  Volker Reichelt  <v.reichelt@netcologne.de>

	PR c/35748
	* gcc.dg/union-cast-4.c: New test.

===================================================================
--- gcc/testsuite/gcc.dg/union-cast-4.c     2003-09-23 19:59:22 +0200
+++ gcc/testsuite/gcc.dg/union-cast-4.c     2008-03-29 21:11:39 +0100
@@ -0,0 +1,8 @@
+/* PR c/35748 */
+
+union U { void x[1]; }; /* { dg-error "array of voids" } */
+
+void foo()
+{
+  (union U)0; /* { dg-error "type not present" } */
+}
===================================================================


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