This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: PR 5941
>>>>> "Per" == Per Bothner <per@bothner.com> writes:
Per> This is good, but I'm not sure it's safe.
Per> Whenever you use a new TREE_LANG_FLAG_0, you must check and
Per> update the "Usage of TREE_LANG_FLAG_?" at the beginning of
Per> java-tree.h.
Thanks. I thought I'd done that but apparently I forgot.
I've updated the comments, and I added a bit of code to make sure we
don't set SUPPRESS_UNREACHABLE_ERROR on something other than what we
expect.
A potential problem is on the reading end. Maybe we can hit the
error-generating code and see the lang-flag-0 bit set even though it
wasn't done via SUPPRESS_UNREACHABLE_ERROR. However, I don't think
that can happen, because this branch of the case should only be hit
for expressions. In particular LOOP_EXPR is handled elsewhere.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
Fix for PR java/5941:
* parse.y (finish_for_loop): Set SUPPRESS_UNREACHABLE_ERROR for
loop update expression.
(java_complete_lhs): Use SUPPRESS_UNREACHABLE_ERROR.
* java-tree.h (SUPPRESS_UNREACHABLE_ERROR): New macro.
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.148
diff -u -r1.148 java-tree.h
--- java-tree.h 25 Apr 2002 06:24:40 -0000 1.148
+++ java-tree.h 26 Apr 2002 16:54:32 -0000
@@ -43,6 +43,7 @@
0: IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (in IDENTIFIER_NODE)
RESOLVE_EXPRESSION_NAME_P (in EXPR_WITH_FILE_LOCATION)
FOR_LOOP_P (in LOOP_EXPR)
+ SUPPRESS_UNREACHABLE_ERROR (for other _EXPR nodes)
ANONYMOUS_CLASS_P (in RECORD_TYPE)
ARG_FINAL_P (in TREE_LIST)
1: CLASS_HAS_SUPER_FLAG (in TREE_VEC).
@@ -1502,6 +1503,12 @@
/* True if NODE (a TREE_LIST) hold a pair of argument name/type
declared with the final modifier */
#define ARG_FINAL_P(NODE) TREE_LANG_FLAG_0 (NODE)
+
+/* True if NODE (some kind of EXPR, but not a WFL) should not give an
+ error if it is found to be unreachable. This can only be applied
+ to those EXPRs which can be used as the update expression of a
+ `for' loop. In particular it can't be set on a LOOP_EXPR. */
+#define SUPPRESS_UNREACHABLE_ERROR(NODE) TREE_LANG_FLAG_0 (NODE)
/* True if EXPR (a WFL in that case) resolves into a package name */
#define RESOLVE_PACKAGE_NAME_P(WFL) TREE_LANG_FLAG_3 (WFL)
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.373
diff -u -r1.373 parse.y
--- parse.y 25 Apr 2002 01:09:47 -0000 1.373
+++ parse.y 26 Apr 2002 16:54:44 -0000
@@ -11840,7 +11840,18 @@
if (TREE_CODE (nn) != EXIT_EXPR)
{
SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
- parse_error_context (wfl_operator, "Unreachable statement");
+ if (SUPPRESS_UNREACHABLE_ERROR (nn))
+ {
+ /* We emit a warning except when pedantic, in
+ which case this code is valid. Perhaps this
+ warning should have an associated flag. */
+ if (! pedantic)
+ parse_warning_context (wfl_operator,
+ "Unreachable statement");
+ }
+ else
+ parse_error_context (wfl_operator,
+ "Unreachable statement");
}
}
TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
@@ -14905,7 +14916,22 @@
/* Put the condition and the loop body in place */
tree loop = finish_loop_body (location, condition, body, 0);
/* LOOP is the current loop which has been now popped of the loop
- stack. Install the update block */
+ stack. Mark the update block as reachable and install it. We do
+ this because the (current interpretation of the) JLS requires
+ that the update expression be considered reachable even if the
+ for loop's body doesn't complete normally. */
+ if (update != NULL_TREE && update != empty_stmt_node)
+ {
+ tree up2 = update;
+ if (TREE_CODE (up2) == EXPR_WITH_FILE_LOCATION)
+ up2 = EXPR_WFL_NODE (up2);
+ /* Try to detect constraint violations. These would be
+ programming errors somewhere. */
+ if (! IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (up2)))
+ | TREE_CODE (up2) == LOOP_EXPR)
+ abort ();
+ SUPPRESS_UNREACHABLE_ERROR (up2) = 1;
+ }
LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
return loop;
}