This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: PR 5941


>>>>> "Per" == Per Bothner <per@bothner.com> writes:

Per> I 'm not sure FORCED_REACHABLE_EXPR_P is a great name.
Per> We're not forcing it to be reachable, since that would
Per> means than any following statements should also be forced to be
Per> reachable.  Instead, I'd call it something like
Per> SUPRESS_UNREACHABLE_ERROR - and still emit a warning.

How's this?

This changes the macro name to SUPRESS_UNREACHABLE_ERROR.
It emits a warning, except when pedantic, in which case it prints
nothing (because pedantically the code in question is 100% correct).

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 25 Apr 2002 18:46:44 -0000
@@ -1503,6 +1503,10 @@
    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.  */
+#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 25 Apr 2002 18:46:57 -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,17 @@
   /* 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);
+      SUPPRESS_UNREACHABLE_ERROR (up2) = 1;
+    }
   LOOP_EXPR_BODY_UPDATE_BLOCK (LOOP_EXPR_BODY (loop)) = update;
   return loop;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]