Hi!

Doing copy_node on error_mark_node doesn't work too well, lots of spots
in the compiler assume there is just a single error_mark_node and compare
it using pointer comparison, rather than checking for TREE_CODE () ==
ERROR_MARK.  The testcase ICEs in particular during gimplification,
the CONST_DECL's DECL_INITIAL is not error_mark_node, but some other
ERROR_MARK and gimplify_expr doesn't like that.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2017-03-07  Jakub Jelinek  <ja...@redhat.com>

        PR c++/79896
        * decl.c (finish_enum_value_list): If value is error_mark_node,
        don't copy it and change its type.
        * init.c (constant_value_1): Return error_mark_node if DECL_INITIAL
        of CONST_DECL is error_mark_node.

        * g++.dg/ext/int128-5.C: New test.

--- gcc/cp/decl.c.jj    2017-03-01 09:31:48.000000000 +0100
+++ gcc/cp/decl.c       2017-03-07 12:31:23.055294773 +0100
@@ -14323,9 +14323,12 @@ finish_enum_value_list (tree enumtype)
       input_location = saved_location;
 
       /* Do not clobber shared ints.  */
-      value = copy_node (value);
+      if (value != error_mark_node)
+       {
+         value = copy_node (value);
 
-      TREE_TYPE (value) = enumtype;
+         TREE_TYPE (value) = enumtype;
+       }
       DECL_INITIAL (decl) = value;
     }
 
--- gcc/cp/init.c.jj    2017-03-02 22:30:24.000000000 +0100
+++ gcc/cp/init.c       2017-03-07 12:41:08.724540062 +0100
@@ -2162,7 +2162,8 @@ constant_value_1 (tree decl, bool strict
       init = DECL_INITIAL (decl);
       if (init == error_mark_node)
        {
-         if (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
+         if (TREE_CODE (decl) == CONST_DECL
+             || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
            /* Treat the error as a constant to avoid cascading errors on
               excessively recursive template instantiation (c++/9335).  */
            return init;
--- gcc/testsuite/g++.dg/ext/int128-5.C.jj      2017-03-07 12:36:24.617301861 
+0100
+++ gcc/testsuite/g++.dg/ext/int128-5.C 2017-03-07 12:36:49.388973865 +0100
@@ -0,0 +1,10 @@
+// PR c++/79896
+// { dg-do compile { target { ilp32 && { ! int128 } } } }
+// { dg-options "" }
+
+enum E
+{
+  e1 = 0xffffffffffffffffULL,
+  e2,                  // { dg-error "overflow in enumeration values" }
+  e3
+} e = e3;

        Jakub

Reply via email to