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]

Re: [PATCH] Java: @deprecated handling, division by zero detection.



Andrew Haley <aph@cambridge.redhat.com> writes:

> We're risking breaking compatibility for no good reason.  IMO.

OK, so instead of completely abandoning the idea of doing something if
an integer division by zero is detected, and taking into account the
input so far, here's something that could amend this patch. Two hunks
in this patch are fixing Mauve build problem reported by Tom:

  http://gcc.gnu.org/ml/java/2001-08/msg00121.html

and an other one generated by this particular patch :-(

./A

2001-08-28  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* parse.y (java_complete_tree): Prevent unwanted cast with
	initialized floating point finals.
	(patch_binop): Emit a warning when detecting a division by zero,
	don't simplify non integer division.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.303
diff -u -p -r1.303 parse.y
--- parse.y     2001/08/27 14:46:57     1.303
+++ parse.y     2001/08/29 01:40:28
@@ -11391,7 +11400,8 @@ java_complete_tree (node)
          /* fold_constant_for_init sometimes widen the original type
              of the constant (i.e. byte to int.) It's not desirable,
              especially if NODE is a function argument. */
-         if (TREE_CODE (value) == INTEGER_CST
+         if ((TREE_CODE (value) == INTEGER_CST
+              || TREE_CODE (value) == REAL_CST)
              && TREE_TYPE (node) != TREE_TYPE (value))
            return convert (TREE_TYPE (node), value);
          else
@@ -13481,8 +13491,8 @@ patch_binop (node, wfl_op1, wfl_op2)
              (TREE_CODE (op2) == INTEGER_CST &&
               ! TREE_INT_CST_LOW (op2)  && ! TREE_INT_CST_HIGH (op2))))
        {
-         parse_error_context (wfl_operator, "Arithmetic exception");
-         error_found = 1;
+         parse_warning_context (wfl_operator, "Evaluating this expression will res
ult in an arithmetic exception being thrown.");
+         TREE_CONSTANT (node) = 0;
        }
          
       /* Change the division operator if necessary */
@@ -13490,9 +13500,11 @@ patch_binop (node, wfl_op1, wfl_op2)
        TREE_SET_CODE (node, TRUNC_DIV_EXPR);
 
       /* Before divisions as is disapear, try to simplify and bail if
-         applicable, otherwise we won't perform even simple simplifications
-        like (1-1)/3. */
-      if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
+         applicable, otherwise we won't perform even simple
+         simplifications like (1-1)/3. We can't do that with floating
+         point number, folds can't handle them at this stage. */
+      if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)
+         && JINTEGRAL_TYPE_P (op1) && JINTEGRAL_TYPE_P (op2))
        {
          TREE_TYPE (node) = prom_type;
          node = fold (node);


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