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]

Patch: RFA: Fix PR java/21540


This patch fixes PR java/21540.

The immediate bug is shown in the new test case.  This is valid java
code which is incorrectly rejected by gcj.  Among other places it
appears in the eclipse java compiler (so we need this fix to build
it).

However, fixing this revealed a couple of other problems.
(And note that there are still bugs in this area.)

- In patch_binop we were not lowering URSHIFT_EXPR to RSHIFT_EXPR in
  all situations; in particular we need to do this when doing constant
  folding as fold() does not understand URSHIFT_EXPR.

- Longstanding bug in COND_EXPR handling in fold_constant_for_init.
  The test was backward.

This patch is a bit hacky in a couple of ways:

- New ad-hoc argument to patch_binop
- Calls fold_constant_for_init with a NULL context argument, which is
  "known to work" in this one particular context.
- The new NOP_EXPR case in patch_unop is weird (but I added an
  assertion to catch things we aren't expecting)


Tested on x86 FC2; rebuilt libgcj, ran test suite including jacks.
This fixes a number of jacks fails, jacks.xfail patch included.

Tom

Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR java/21540:
	* testsuite/libjava.compile/pr21540.java: New file.
	* testsuite/libjava.jacks/jacks.xfail: Updated.

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR java/21540:
	* parse.y (java_complete_lhs) <CASE_EXPR>: Use
	fold_constant_for_init.
	(patch_binop): Added 'folding' argument.  Updated all callers.
	(patch_unaryop) <NOP_EXPR>: New case.
	(fold_constant_for_init) <NOP_EXPR>: Likewise.
	(fold_constant_for_init) <COND_EXPR>: Fix sense of test.

Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.539
diff -u -r1.539 parse.y
--- gcc/java/parse.y 13 Jun 2005 19:20:22 -0000 1.539
+++ gcc/java/parse.y 22 Jun 2005 17:49:30 -0000
@@ -161,7 +161,7 @@
 static tree build_assignment (int, int, tree, tree);
 static tree build_binop (enum tree_code, int, tree, tree);
 static tree patch_assignment (tree, tree);
-static tree patch_binop (tree, tree, tree);
+static tree patch_binop (tree, tree, tree, int);
 static tree build_unaryop (int, int, tree);
 static tree build_incdec (int, int, tree, int);
 static tree patch_unaryop (tree, tree);
@@ -11795,8 +11795,13 @@
 
       /* First, the case expression must be constant. Values of final
          fields are accepted. */
+      nn = fold_constant_for_init (cn, NULL_TREE);
+      if (nn != NULL_TREE)
+	cn = nn;
+
       cn = fold (cn);
-      if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn) == COMPONENT_REF)
+      if ((TREE_CODE (cn) == COMPOUND_EXPR
+	   || TREE_CODE (cn) == COMPONENT_REF)
 	  && JDECL_P (TREE_OPERAND (cn, 1))
 	  && FIELD_FINAL (TREE_OPERAND (cn, 1))
 	  && DECL_INITIAL (TREE_OPERAND (cn, 1)))
@@ -12307,12 +12312,12 @@
 
           TREE_OPERAND (node, 1) = nn;
         }
-      return patch_binop (node, wfl_op1, wfl_op2);
+      return patch_binop (node, wfl_op1, wfl_op2, 0);
 
     case INSTANCEOF_EXPR:
       wfl_op1 = TREE_OPERAND (node, 0);
       COMPLETE_CHECK_OP_0 (node);
-      return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
+      return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1), 0);
 
     case UNARY_PLUS_EXPR:
     case NEGATE_EXPR:
@@ -13446,7 +13451,7 @@
    of remaining nodes and detects more errors in certain cases.  */
 
 static tree
-patch_binop (tree node, tree wfl_op1, tree wfl_op2)
+patch_binop (tree node, tree wfl_op1, tree wfl_op2, int folding)
 {
   tree op1 = TREE_OPERAND (node, 0);
   tree op2 = TREE_OPERAND (node, 1);
@@ -13628,7 +13633,7 @@
 			    build_int_cst (NULL_TREE, 0x3f)));
 
       /* The >>> operator is a >> operating on unsigned quantities */
-      if (code == URSHIFT_EXPR && ! flag_emit_class_files)
+      if (code == URSHIFT_EXPR && (folding || ! flag_emit_class_files))
 	{
 	  tree to_return;
           tree utype = java_unsigned_type (prom_type);
@@ -13637,6 +13642,8 @@
           TREE_OPERAND (node, 0) = op1;
           TREE_OPERAND (node, 1) = op2;
           TREE_TYPE (node) = utype;
+	  if (folding)
+	    node = fold (node);
 	  to_return = convert (prom_type, node);
 	  /* Copy the original value of the COMPOUND_ASSIGN_P flag */
 	  COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
@@ -14417,6 +14424,12 @@
 	  return value;
 	}
       break;
+
+    case NOP_EXPR:
+      /* This can only happen when the type is already known.  */
+      gcc_assert (TREE_TYPE (node) != NULL_TREE);
+      prom_type = TREE_TYPE (node);
+      break;
     }
 
   if (error_found)
@@ -16218,13 +16231,14 @@
       if (val == NULL_TREE || ! TREE_CONSTANT (val))
 	return NULL_TREE;
       TREE_OPERAND (node, 1) = val;
-      return patch_binop (node, op0, op1);
+      return patch_binop (node, op0, op1, 1);
 
     case UNARY_PLUS_EXPR:
     case NEGATE_EXPR:
     case TRUTH_NOT_EXPR:
     case BIT_NOT_EXPR:
     case CONVERT_EXPR:
+    case NOP_EXPR:
       op0 = TREE_OPERAND (node, 0);
       val = fold_constant_for_init (op0, context);
       if (val == NULL_TREE || ! TREE_CONSTANT (val))
@@ -16250,8 +16264,8 @@
       if (val == NULL_TREE || ! TREE_CONSTANT (val))
 	return NULL_TREE;
       TREE_OPERAND (node, 2) = val;
-      return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
-	: TREE_OPERAND (node, 2);
+      return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 2)
+	: TREE_OPERAND (node, 1);
 
     case VAR_DECL:
     case FIELD_DECL:
Index: libjava/testsuite/libjava.compile/pr21540.java
===================================================================
RCS file: libjava/testsuite/libjava.compile/pr21540.java
diff -N libjava/testsuite/libjava.compile/pr21540.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/pr21540.java 22 Jun 2005 17:49:30 -0000
@@ -0,0 +1,15 @@
+public class pr21540
+{
+    public static final long xxx = 555;
+    
+    public boolean fn (int v)
+    {
+	switch (v)
+	    {
+	    case ((int) xxx >>> 32):
+		return true;
+	    default:
+		return false;
+	    }
+    }
+}
Index: libjava/testsuite/libjava.jacks/jacks.xfail
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.jacks/jacks.xfail,v
retrieving revision 1.24
diff -u -r1.24 jacks.xfail
--- libjava/testsuite/libjava.jacks/jacks.xfail 27 May 2005 05:11:44 -0000 1.24
+++ libjava/testsuite/libjava.jacks/jacks.xfail 22 Jun 2005 17:49:30 -0000
@@ -274,9 +274,7 @@
 15.28-null-1
 15.28-null-3
 15.28-primitive-15
-15.28-primitive-16
 15.28-primitive-17
-15.28-primitive-9
 15.28-qualified-name-10
 15.28-qualified-name-5
 15.28-qualified-name-6
@@ -294,7 +292,6 @@
 15.28-simple-namestr-4
 15.28-string-11
 15.28-string-15
-15.28-string-16
 15.28-string-17
 15.28-string-18
 15.28-string-2
@@ -456,27 +453,11 @@
 5.1.2-btf-1
 5.1.2-btf-3
 5.1.2-btf-5
-5.1.2-bti-1
-5.1.2-bti-3
-5.1.2-bti-5
-5.1.2-btl-1
-5.1.2-btl-3
-5.1.2-btl-5
-5.1.2-bts-1
-5.1.2-bts-2
-5.1.2-bts-3
-5.1.2-bts-4
-5.1.2-bts-5
 5.1.2-std-3
 5.1.2-std-5
 5.1.2-stf-1
 5.1.2-stf-3
 5.1.2-stf-5
-5.1.2-sti-1
-5.1.2-sti-5
-5.1.2-stl-1
-5.1.2-stl-3
-5.1.2-stl-5
 6.3-1
 6.5.1-type-15
 6.5.1-type-16


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