This is the mail archive of the mailing list for the Java project.

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

Re: Freenet compilation errors.

I've tracked down the cause of the "Missing return statement" bug.

The problem is these lines in patch_exit_expr in parse.y:

  if (! integer_zerop (TREE_OPERAND (node, 0))
      && ctxp->current_loop != NULL_TREE
      && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
    CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;

Here the CAN_COMPLETE_NORMALLY flag is set on the loop,
but only if TREE_OPERAND (node, 0) is not a false constant.
Unfortunately, TREE_OPERAND (node, 0) *should* be false,
but it is not viewed as constant, and so CAN_COMPLETE_NORMALLY
is set to true.

So why is TREE_OPERAND (node, 0) not false?  It is set in the
statement above:

  TREE_OPERAND (node, 0) = 
    fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));

This negates the "true", and then constant folds it.  The result
*should* be false, but it is not a constant, because the true
constant was wrapped in an EXPR_WITH_FILE_LOCATION node.

One might "fix" by putting in a special case for EXPR_WITH_FILE_LOCATION
in patch_exit_expr, but I think that is wrong:  Any constant expression
might be wrapped in a EXPR_WITH_FILE_LOCATION.  Thus we need to strip
off EXPR_WITH_FILE_LOCATION before doing constant folding - but we
should do it *generally*, not a special case for patch_exit_expr.
I don't there is much point in having a EXPR_WITH_FILE_LOCATION
wrapped around a constant, since a constant is never executed anyway.

I suggest the following patch:

Index: parse.y
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.238
diff -u -p -r1.238 parse.y
--- parse.y	2000/12/18 21:23:02	1.238
+++ parse.y	2001/01/07 07:43:25
@@ -11475,9 +11475,9 @@ java_complete_lhs (node)
 	  EXPR_WFL_NODE (node) = body;
-	  if (body == empty_stmt_node)
+	  if (body == empty_stmt_node || TREE_CONSTANT (body))
-	      /* Optimization;  makes it easier to detect empty bodies. */
+	      /* Makes it easier to constant fold, detect empty bodies. */
 	      return body;
 	  if (body == error_mark_node)
Index: lex.c
RCS file: /cvs/gcc/egcs/gcc/java/lex.c,v
retrieving revision 1.55
diff -u -p -r1.55 lex.c
--- lex.c	2000/12/13 22:47:13	1.55
+++ lex.c	2001/01/07 07:43:26
@@ -1642,7 +1642,10 @@ static tree
 build_wfl_node (node)
      tree node;
-  return build_expr_wfl (node, ctxp->filename, ctxp->elc.line, ctxp->elc.col);
+  node = build_expr_wfl (node, ctxp->filename, ctxp->elc.line, ctxp->elc.col);
+  /* Prevent java_complete_lhs from short-circuiting node (if constant). */
+  TREE_TYPE (node) = NULL_TREE;
+  return node;
Does this look reasonable?  (I think this is the first jc1 patch I've
submitted since I left Cygnus over 18 months ago ...  I do have a couple
sun-submitted verifier patches.)
	--Per Bothner

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