This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Is this a bug?
- From: Per Bothner <per at bothner dot com>
- To: martin dot kahlert at infineon dot com
- Cc: java at gcc dot gnu dot org
- Date: Wed, 04 Sep 2002 13:18:38 -0700
- Subject: Re: Is this a bug?
- References: <20020904145921.A9334@keksy.muc.infineon.com>
The attached patch appears to fix the problem. However, I don't
know if it breaks anything else, partly because I don't quite
understand to comment in java_complete_tree, and I haven't tried
whatever testcase it is supposed to fix. However, it looks like
there's a good chance this patch will fix it.
The patch isn't quite right, because it doesn't complain about
the following:
public final static long a = 1000000000;
public final static long b = 1000.0 * a;
I'll figure out a more correct patch, one that also does the
necesary type-checking.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.393
diff -u -p -r1.393 parse.y
--- parse.y 26 Aug 2002 23:30:02 -0000 1.393
+++ parse.y 4 Sep 2002 20:09:06 -0000
@@ -11514,22 +11514,9 @@ java_complete_tree (node)
&& DECL_INITIAL (node) != NULL_TREE
&& !flag_emit_xref)
{
- tree value = DECL_INITIAL (node);
- DECL_INITIAL (node) = NULL_TREE;
- value = fold_constant_for_init (value, node);
- DECL_INITIAL (node) = value;
+ tree value = fold_constant_for_init (node, node);
if (value != NULL_TREE)
- {
- /* fold_constant_for_init sometimes widens the original type
- of the constant (i.e. byte to int). It's not desirable,
- especially if NODE is a function argument. */
- if ((TREE_CODE (value) == INTEGER_CST
- || TREE_CODE (value) == REAL_CST)
- && TREE_TYPE (node) != TREE_TYPE (value))
- return convert (TREE_TYPE (node), value);
- else
- return value;
- }
+ return value;
}
return node;
}
@@ -16089,6 +16076,8 @@ fold_constant_for_init (node, context)
/* Guard against infinite recursion. */
DECL_INITIAL (node) = NULL_TREE;
val = fold_constant_for_init (val, node);
+ if (val != NULL_TREE)
+ val = convert (TREE_TYPE (node), val);
DECL_INITIAL (node) = val;
return val;