re PR c/35748 (ICE with cast to invalid union)
authorVolker Reichelt <v.reichelt@netcologne.de>
Sun, 30 Mar 2008 21:58:43 +0000 (21:58 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Sun, 30 Mar 2008 21:58:43 +0000 (21:58 +0000)
PR c/35748
* c-typeck.c (build_c_cast): Skip invalid fields in unions.

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

From-SVN: r133737

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/union-cast-4.c [new file with mode: 0644]

index a0e29ccedb18a5662d58bc53c118dd8fe8af6979..d278b6c555f9646e59ca0b8ff50fab0bd20611ab 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-30  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       PR c/35748
+       * c-typeck.c (build_c_cast): Skip invalid fields in unions.
+
 2008-03-30  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/35757
index 4d476c5d4dd5f7397e46ecb67d04f45aa8218aed..a457f6a22835a9863846c2d70de3d04adb074cc3 100644 (file)
@@ -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)
index 3f8205a65fb2c926e08b865661836ea0656038b2..e7e4b30824bbcac553af10da628657a9b3a4c5e7 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-30  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       PR c/35748
+       * gcc.dg/union-cast-4.c: New test.
+
 2008-03-30  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/35757
diff --git a/gcc/testsuite/gcc.dg/union-cast-4.c b/gcc/testsuite/gcc.dg/union-cast-4.c
new file mode 100644 (file)
index 0000000..a1c98ba
--- /dev/null
@@ -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" } */
+}