diff mbox

Fix for PR c/43082

Message ID 1295405455.754426125@192.168.4.58
State New
Headers show

Commit Message

Nicola Pero Jan. 19, 2011, 2:50 a.m. UTC
This patch fixes PR c/43082 ("[4.3/4.4/4.5/4.6 Regression] ICE in tree check:
expected class 'type', have 'exceptional' (error_mark) in useless_type_conversion_p").

Andrew Pinski had already produced a reduced testcase, and a working
patch --

  http://gcc.gnu.org/ml/gcc-patches/2010-03/msg00198.html

the patch was good, but it didn't get applied as Joseph recommended
a different approach (I guess Andrew didn't have time to follow up ?).

Here is a new patch that uses Joseph's recommended approach.

Bootstrapped and tested on i686-pc-linux-gnu.

Ok to commit to trunk (4.6) ?

Thanks

PS: C++ does not have this problem and does not seem to need fixing; it produces the error

  test.cc:4:32: error: could not convert ‘0’ to ‘bool’

without ICEing.

Comments

Joseph Myers Jan. 25, 2011, 11:32 p.m. UTC | #1
This patch is OK.
diff mbox

Patch

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 168968)
+++ ChangeLog   (working copy)
@@ -1,3 +1,10 @@ 
+2011-01-19  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       PR c/43082
+       * c-typeck.c (c_objc_common_truthvalue_conversion): If we are
+       passed a VOID_TYPE expression, immediately emit an error and
+       return error_mark_node.
+
 2011-01-18  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR middle-end/46894
Index: testsuite/gcc.dg/pr43082.c
===================================================================
--- testsuite/gcc.dg/pr43082.c  (revision 0)
+++ testsuite/gcc.dg/pr43082.c  (revision 0)
@@ -0,0 +1,10 @@ 
+/* Test that the compiler does not crash when void expressions are
+   found inside conditional expressions.  PR c/43082.  */
+/* { dg-do compile } */
+
+void
+foo (int x)
+{
+  if (x ? (void)(0) : (void)(1)) /* { dg-error "void value not ignored as it ought to be" } */
+    ;
+}
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (revision 168968)
+++ testsuite/ChangeLog (working copy)
@@ -1,3 +1,9 @@ 
+2011-01-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+           Andrew Pinski  <pinskia@gmail.com>
+
+       PR c/43082
+       * gcc.dg/pr43082.c: New.
+
 2011-01-18  Dominique d'Humieres  <dominiq@lps.ens.fr>
 
        PR testsuite/41146
Index: c-typeck.c
===================================================================
--- c-typeck.c  (revision 168968)
+++ c-typeck.c  (working copy)
@@ -10270,6 +10270,10 @@  c_objc_common_truthvalue_conversion (location_t lo
       error_at (location, "used union type value where scalar is required");
       return error_mark_node;
 
+    case VOID_TYPE:
+      error_at (location, "void value not ignored as it ought to be");
+      return error_mark_node;
+
     case FUNCTION_TYPE:
       gcc_unreachable ();
 
@@ -10282,8 +10286,8 @@  c_objc_common_truthvalue_conversion (location_t lo
   if (int_operands)
     expr = remove_c_maybe_const_expr (expr);
 
-  /* ??? Should we also give an error for void and vectors rather than
-     leaving those to give errors later?  */
+  /* ??? Should we also give an error for vectors rather than leaving
+     those to give errors later?  */
   expr = c_common_truthvalue_conversion (location, expr);
 
   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)