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]

[JAVA, PATCH] PR java/8923: ICE when modifying a variable decleared "final static"


Hi all.

The attached patch fixes the following test case, given in comment #6, by 
checking, in the parser, that the operand to ++ or -- is not a constant.

=== cut here ===
class gcjbug {
    public static void main (String [] p) {
        System.out.println(1++);
    }
}
=== cut here ===

The patched source tree has been successfully bootstrapped and regtested on 
i686-pc-linux-gnu. Is it OK? If so, could someone commit it for me (I don't 
have write access).


I haven't figured a fix for the initial test case yet:

=== cut here ===
public class myBug
{
        final static int myConst = 200;

        public static void bug() { myConst++;   /* ICE */ }
}
=== cut here ===

A good place to emit an error would be in check-init.c(check_init), because 
that's there that we get an error if myConst is not declared static. From my 
investigation, it looks like we currently don't see that myConst is final 
because it has been constant fold, and we get an INTEGER_CST. Is there a 
way to get back to the declaration from there? I guess that adding a check 
for INTEGER_CST in check_init would fix the problem, but I wonder if it's a 
"good" solution...

Thanks in advance for your feedback on the patch and for your advice on the 
rest of the problem.

Best regards,
Simon
Index: java/parse.y
===================================================================
--- java/parse.y	(revision 115763)
+++ java/parse.y	(working copy)
@@ -14223,6 +14223,14 @@ build_incdec (int op_token, int op_locat
   /* Store the location of the operator, for better error report. The
      string of the operator will be rebuild based on the OP value. */
   EXPR_WFL_LINECOL (node) = op_location;
+
+  /* Report an error if the operand is a constant. */
+  if (TREE_CONSTANT (op1)) {
+    parse_error_context (node, "%qs cannot be used with a constant",
+                         operator_string (node));
+    return error_mark_node;
+  }
+
   return node;
 }
 
@@ -14377,7 +14385,7 @@ patch_unaryop (tree node, tree wfl_op)
 	  error_found = 1;
 	}
 
-      /* From now on, we know that op if a variable and that it has a
+      /* From now on, we know that op is a variable and that it has a
          valid wfl. We use wfl_op to locate errors related to the
          ++/-- operand. */
       if (!JNUMERIC_TYPE_P (op_type))
class pr8929
{
    public pr8929()
    {
        1++;
        1--;
    }
}

Attachment: CL_8923
Description: Text document


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