This is the mail archive of the
mailing list for the Java project.
[PATCH] Fix java/13733
- From: Jeff Sturm <jsturm at one-point dot com>
- To: java-patches at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 Jan 2004 19:08:09 -0500 (EST)
- Subject: [PATCH] Fix java/13733
Gcj currently compiles incorrect java code such as:
String c = "";
a = (b = c);
whereas other java compilers (javac, jikes) rightly complain.
I traced it to this odd statement in patch_assignment:
lhs_type = promote_type (rhs_type);
JLS 15.26 says "The type of the assignment expression is the type of the
variable" (where "variable" is the LHS of the assignment). So the above
is clearly wrong, though it has existed in patch_assignment since
revision 1.1, when the Java FE was first merged into the EGCS repository!
I have no way to tell why this was done. It may have been simply a typo
all along, since promoting the RHS by itself would make sense.
(This bug may have gone unnoticed forever were it not for the strict type
checking of the gimplifier in tree-ssa, which currently prevents Eclipse
from compiling on the branch. There doesn't even seem to be a Jacks test
for this language requirement. This patch should also fix the ICE on
tree-ssa, which was my real motivation to work on it.)
Tested on i686-pc-linux-gnu, no regressions in libjava, mauve or jacks.
OK for mainline?
2004-01-21 Jeff Sturm <firstname.lastname@example.org>
* parse.y (patch_assignment): Don't modify lhs_type for
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.464
diff -u -r1.464 parse.y
--- parse.y 9 Jan 2004 17:08:44 -0000 1.464
+++ parse.y 21 Jan 2004 02:13:55 -0000
@@ -12652,8 +12652,8 @@
new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
/* 5.2 If it failed, try a reference conversion */
- if (!new_rhs && (new_rhs = try_reference_assignconv (lhs_type, rhs)))
- lhs_type = promote_type (rhs_type);
+ if (!new_rhs)
+ new_rhs = try_reference_assignconv (lhs_type, rhs);
/* 15.25.2 If we have a compound assignment, convert RHS into the
type of the LHS */