This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: RFA: Fix PR java/14853
>>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:
Andrew> Eeeeh, OK. This is nasty stuff.
Yeah. I really dislike how gcj builds different trees up front
depending on flag_emit_class_files and flag_syntax_only (and other
things, like enable_assertions).
Here's the revision of the patch as we discussed on irc.
Instead of stripping in an ad hoc way, we now use a function that
already existed for doing this. It is renamed since we both disliked
the old name.
Ok?
Tom
Index: gcc/java/ChangeLog
from Tom Tromey <tromey@redhat.com>
PR java/14853:
* java-tree.h (extract_field_decl): Declare.
* parse.y (extract_field_decl): Renamed from
strip_out_static_field_access_decl. No longer static.
* 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 14:59:49 -0000
@@ -164,6 +164,11 @@
static tree
get_variable_decl (tree exp)
{
+ /* A static field can be wrapped in a COMPOUND_EXPR where the first
+ argument initializes the class. */
+ if (TREE_CODE (exp) == COMPOUND_EXPR)
+ exp = extract_field_decl (exp);
+
if (TREE_CODE (exp) == VAR_DECL)
{
if (! TREE_STATIC (exp) || FIELD_FINAL (exp))
Index: gcc/java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.223
diff -u -r1.223 java-tree.h
--- gcc/java/java-tree.h 26 Nov 2004 18:04:45 -0000 1.223
+++ gcc/java/java-tree.h 6 Dec 2004 15:03:15 -0000
@@ -1922,4 +1922,6 @@
extern void java_genericize PARAMS ((tree));
extern int java_gimplify_expr PARAMS ((tree *, tree *, tree *));
+extern tree extract_field_decl (tree);
+
#endif /* ! GCC_JAVA_TREE_H */
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.524
diff -u -r1.524 parse.y
--- gcc/java/parse.y 2 Dec 2004 19:41:03 -0000 1.524
+++ gcc/java/parse.y 6 Dec 2004 15:03:19 -0000
@@ -277,7 +277,6 @@
static int array_constructor_check_entry (tree, tree);
static const char *purify_type_name (const char *);
static tree fold_constant_for_init (tree, tree);
-static tree strip_out_static_field_access_decl (tree);
static jdeplist *reverse_jdep_list (struct parser_ctxt *);
static void static_ref_err (tree, tree, tree);
static void parser_add_interface (tree, tree, tree);
@@ -9678,12 +9677,12 @@
return field_ref;
}
-/* If NODE is an access to f static field, strip out the class
+/* If NODE is an access to a static field, strip out the class
initialization part and return the field decl, otherwise, return
NODE. */
-static tree
-strip_out_static_field_access_decl (tree node)
+tree
+extract_field_decl (tree node)
{
if (TREE_CODE (node) == COMPOUND_EXPR)
{
@@ -14260,7 +14259,7 @@
case PREINCREMENT_EXPR:
/* 15.14.2 Prefix Decrement Operator -- */
case PREDECREMENT_EXPR:
- op = decl = strip_out_static_field_access_decl (op);
+ op = decl = extract_field_decl (op);
outer_field_flag = outer_field_expanded_access_p (op, NULL, NULL, NULL);
/* We might be trying to change an outer field accessed using
access method. */
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 14:59:55 -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 14:59:55 -0000
@@ -0,0 +1 @@
+shouldfail