This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: RFA: Fix PR java/14853
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 06 Dec 2004 07:03:25 -0700
- Subject: Patch: RFA: Fix PR java/14853
- Reply-to: tromey at redhat dot com
This patch fixes PR java/14853, an old regression.
We correctly reject the test code when compiling to .class, but not
when compiling to .o. In the latter case, we generate trees that the
definite assignment code does not recognize. In particular a static
field reference is wrapped in a COMPOUND_EXPR whose LHS initializes
the target class.
This patch unwraps the COMPOUND_EXPR. I believe this is safe as this
is the only time we can create a COMPOUND_EXPR wrapping a variable
reference.
Tested on x86 FC2. Test case included.
Ok?
Tom
Index: gcc/java/ChangeLog
from Tom Tromey <tromey@redhat.com>
PR java/14853:
* check-init.c (get_variable_decl): Unwrap COMPOUND_EXPRs.
Index: gcc/java/check-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/check-init.c,v
retrieving revision 1.61
diff -u -r1.61 check-init.c
--- gcc/java/check-init.c 25 Nov 2004 03:46:39 -0000 1.61
+++ gcc/java/check-init.c 6 Dec 2004 13:52:12 -0000
@@ -164,6 +164,13 @@
static tree
get_variable_decl (tree exp)
{
+ /* A static field can be wrapped in a COMPOUND_EXPR where the first
+ argument initializes the class. This should be the only use of
+ COMPOUND_EXPR that is visible as an argument to a
+ MODIFY_EXPR. */
+ if (TREE_CODE (exp) == COMPOUND_EXPR)
+ exp = TREE_OPERAND (exp, 1);
+
if (TREE_CODE (exp) == VAR_DECL)
{
if (! TREE_STATIC (exp) || FIELD_FINAL (exp))
Index: libjava/ChangeLog
from Tom Tromey <tromey@redhat.com>
For PR java/14853:
* testsuite/libjava.compile/PR14853.java: New file.
* testsuite/libjava.compile/PR14853.xfail: New file.
Index: libjava/testsuite/libjava.compile/PR14853.java
===================================================================
RCS file: libjava/testsuite/libjava.compile/PR14853.java
diff -N libjava/testsuite/libjava.compile/PR14853.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/PR14853.java 6 Dec 2004 13:52:16 -0000
@@ -0,0 +1,17 @@
+class tt
+{
+ static final tt tt1 = new tt();
+ tt()
+ {
+ }
+}
+
+public class PR14853
+{
+ public static void main (String[] args)
+ {
+ // This is an invalid assignment. gcj would get confused in
+ // definite assignment when compiling to object code.
+ tt.tt1 = new tt();
+ }
+}
Index: libjava/testsuite/libjava.compile/PR14853.xfail
===================================================================
RCS file: libjava/testsuite/libjava.compile/PR14853.xfail
diff -N libjava/testsuite/libjava.compile/PR14853.xfail
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/PR14853.xfail 6 Dec 2004 13:52:16 -0000
@@ -0,0 +1 @@
+shouldfail