Bug 31339 - [4.3 regression] ICE on invalid use of complex constant
Summary: [4.3 regression] ICE on invalid use of complex constant
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: error-recovery, ice-on-invalid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2007-03-24 23:21 UTC by Volker Reichelt
Modified: 2007-05-29 00:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-04-03 07:28:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2007-03-24 23:21:51 UTC
The following invalid code snippet triggers an ICE on mainline:

===========================
bool b = --0i == 0;
===========================

bug.cc:1: error: lvalue required as decrement operand
bug.cc:1: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in fold_comparison, at fold-const.c:8459
Please submit a full bug report, [etc.]
Comment 1 Andrew Pinski 2007-03-25 07:21:31 UTC
  if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))

I think we are just checking TYPE_OVERFLOW_UNDEFINED too early.
Comment 2 Andrew Pinski 2007-04-03 07:28:40 UTC
Confirmed.
Comment 3 Andrew Pinski 2007-05-23 00:29:49 UTC
I have a patch for the C and C++ front-ends, we don't have to change fold at all.
Comment 4 Andrew Pinski 2007-05-23 00:48:54 UTC
The patch which I am testing:
Index: testsuite/gcc.dg/boolcomplex-1.c
===================================================================
--- testsuite/gcc.dg/boolcomplex-1.c    (revision 0)
+++ testsuite/gcc.dg/boolcomplex-1.c    (revision 0)
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+_Bool b = --0i == 0; /* { dg-error "lvalue required as decrement operand" } */
Index: testsuite/g++.dg/ext/boolcomplex-1.c
===================================================================
--- testsuite/g++.dg/ext/boolcomplex-1.c        (revision 0)
+++ testsuite/g++.dg/ext/boolcomplex-1.c        (revision 0)
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+bool b = --0i == 0; /* { dg-error "lvalue required as decrement operand" } */
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 124926)
+++ cp/typeck.c (working copy)
@@ -4221,8 +4221,11 @@ build_unary_op (enum tree_code code, tre
          arg = stabilize_reference (arg);
          real = build_unary_op (REALPART_EXPR, arg, 1);
          imag = build_unary_op (IMAGPART_EXPR, arg, 1);
+         real = build_unary_op (code, real, 1);
+         if (real == error_mark_node || imag == error_mark_node)
+           return error_mark_node;
          return build2 (COMPLEX_EXPR, TREE_TYPE (arg),
-                        build_unary_op (code, real, 1), imag);
+                        real, imag);
        }

       /* Report invalid types.  */
Index: c-typeck.c
===================================================================
--- c-typeck.c  (revision 124926)
+++ c-typeck.c  (working copy)
@@ -2908,8 +2908,11 @@ build_unary_op (enum tree_code code, tre
          arg = stabilize_reference (arg);
          real = build_unary_op (REALPART_EXPR, arg, 1);
          imag = build_unary_op (IMAGPART_EXPR, arg, 1);
+         real = build_unary_op (code, real, 1);
+         if (real == error_mark_node || imag == error_mark_node)
+           return error_mark_node;
          return build2 (COMPLEX_EXPR, TREE_TYPE (arg),
-                        build_unary_op (code, real, 1), imag);
+                        real, imag);
        }

       /* Report invalid types.  */




Instead of ever creating a COMPLEX_EXPR with an error_mark, just return an error_mark_node.
Comment 5 Andrew Pinski 2007-05-29 00:25:36 UTC
Subject: Bug 31339

Author: pinskia
Date: Tue May 29 00:25:25 2007
New Revision: 125156

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125156
Log:
2007-05-28  Andrew Pinski  <Andrew_pinski@playstation.sony.com>

        PR c/31339
        * c-typeck.c (build_unary_op <case PREINCREMENT_EXPR,
        case POSTINCREMENT_EXPR, case PREDECREMENT_EXPR,
        case POSTDECREMENT_EXPR>): Return the error_mark_node
        if either the real or imaginary parts would an
        error_mark_node.

2007-05-28  Andrew Pinski  <Andrew_pinski@playstation.sony.com>

        PR c++/31339
        * typeck.c (build_unary_op <case PREINCREMENT_EXPR,
        case POSTINCREMENT_EXPR, case PREDECREMENT_EXPR,
        case POSTDECREMENT_EXPR>): Return the error_mark_node
        if either the real or imaginary parts would an
        error_mark_node.

2007-05-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR c/31339
        * gcc.dg/boolcomplex-1.c: New test.

        PR c++/31339
        * g++.dg/ext/boolcomplex-1.c: New test



Added:
    trunk/gcc/testsuite/g++.dg/ext/boolcomplex-1.c
    trunk/gcc/testsuite/gcc.dg/boolcomplex-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Andrew Pinski 2007-05-29 00:25:39 UTC
Fixed.