Patch: Don't modify constant tree node

Tom Tromey tromey@redhat.com
Mon Jun 10 20:50:00 GMT 2002


fold-const.c:fold_convert() can current modify its `arg1' argument if
we're casting a floating point constant to a different floating point
type.

This causes PR java/6520.  The problem in this case is that we have a
float constant value which is shared.  fold_convert() changes its type
to double, which the bytecode generator dutifully emits, leading to
unverifiable bytecode.

I came up with the appended fix, which works by unsharing the tree in
this case.  I think this approach makes sense because changing the
type of a constant seems strange.  Or, to put it another way, it seems
reasonable to me that constants should not change and should be
sharable.

I ran the gcc test suite against this patch on x86 Linux with no
regressions.

Ok to commit?

Tom

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

	For PR java/6520:
	* fold-const.c (fold_convert): Don't modify existing tree's type.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.209
diff -u -r1.209 fold-const.c
--- fold-const.c 7 Jun 2002 23:42:44 -0000 1.209
+++ fold-const.c 10 Jun 2002 21:26:51 -0000
@@ -1596,8 +1602,10 @@
 	{
 	  if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
 	    {
-	      t = arg1;
-	      TREE_TYPE (arg1) = type;
+	      /* We make a copy of ARG1 so that we don't modify an
+		 existing constant tree.  */
+	      t = copy_node (arg1);
+	      TREE_TYPE (t) = type;
 	      return t;
 	    }
 



More information about the Java-patches mailing list