[multiple changes]
authorAndrew Haley <aph@cygnus.com>
Thu, 21 Jan 1999 08:50:06 +0000 (08:50 +0000)
committerAndrew Haley <aph@gcc.gnu.org>
Thu, 21 Jan 1999 08:50:06 +0000 (08:50 +0000)
Thu Jan 21 16:00:06 1999  Andrew Haley  <aph@cygnus.com>
* typeck.c (convert): Allow conversions to void type: some
  optimizations in gcc do this.
Thu Jan 21 15:21:49 1999  Andrew Haley  <aph@cygnus.com>
* typeck.c (convert_ieee_real_to_integer): New function.
(convert): When not using fast-math and using hardware fp, convert
  an IEEE NaN to zero.

From-SVN: r24797

gcc/java/ChangeLog
gcc/java/typeck.c

index bbd7ca3748971e5514ae8cb32ade32dbdb428df9..9c4a281874ac9afd688054e12621b7cfa6a53164 100644 (file)
@@ -1,3 +1,14 @@
+Thu Jan 21 16:00:06 1999  Andrew Haley  <aph@cygnus.com>
+
+       * typeck.c (convert): Allow conversions to void type: some
+       optimizations in gcc do this.
+
+Thu Jan 21 15:21:49 1999  Andrew Haley  <aph@cygnus.com>
+
+       * typeck.c (convert_ieee_real_to_integer): New function.
+       (convert): When not using fast-math and using hardware fp, convert
+       an IEEE NaN to zero.
 1999-01-18  Andrew Haley  <aph@cygnus.com>
 
        * parse.y (patch_binop): Do a type conversion from signed to
index 8af3a4f51b052daf817f7d40eda820cb82a6c7f7..6a37d7e92e23c1a80dd925ddeeba44b410bebda5 100644 (file)
@@ -28,6 +28,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "system.h"
 #include "tree.h"
 #include "obstack.h"
+#include "flags.h"
 #include "java-tree.h"
 #include "jcf.h"
 #include "convert.h"
@@ -52,6 +53,39 @@ set_local_type (slot, type)
     type_map[++slot] = void_type_node;
 }
 
+/* Convert an IEEE real to an integer type.  The result of such a
+   conversion when the source operand is a NaN isn't defined by
+   IEEE754, but by the Java language standard: it must be zero.  This
+   conversion produces something like:
+   
+   ({ double tmp = expr; (tmp != tmp) ? 0 : (int)tmp; })
+
+   */
+
+static tree
+convert_ieee_real_to_integer (type, expr)
+     tree type, expr;
+{
+  tree node, assignment, expr_decl;
+
+  expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
+  layout_decl (expr_decl, 0);
+  expand_decl (pushdecl (expr_decl));
+  assignment = build (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
+  TREE_SIDE_EFFECTS (assignment) = 1;
+  TREE_TYPE (assignment) = type;
+
+  expr = build (COMPOUND_EXPR, NULL_TREE,
+               assignment,
+               build (COND_EXPR, type, 
+                      build (NE_EXPR, boolean_type_node, expr_decl, expr_decl),
+                      build_int_2 (0, 0),
+                      convert_to_integer (type, expr_decl)));
+
+  TREE_TYPE (expr) = type;
+  return expr;
+}  
+
 /* Create an expression whose value is that of EXPR,
    converted to type TYPE.  The TREE_TYPE of the value
    is always TYPE.  This function implements all reasonable
@@ -69,10 +103,23 @@ convert (type, expr)
     return expr;
   if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
     return error_mark_node;
+  if (code == VOID_TYPE)
+    return build1 (CONVERT_EXPR, type, expr);
   if (code == BOOLEAN_TYPE)
     return fold (convert_to_boolean (type, expr));
   if (code == INTEGER_TYPE)
-    return fold (convert_to_integer (type, expr));
+    {
+      if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
+#ifdef TARGET_SOFT_FLOAT
+         && !TARGET_SOFT_FLOAT
+#endif
+         && !flag_emit_class_files
+         && !flag_fast_math
+         && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
+       return fold (convert_ieee_real_to_integer (type, expr));
+      else
+       return fold (convert_to_integer (type, expr));
+    }    
   if (code == REAL_TYPE)
     return fold (convert_to_real (type, expr));
   if (code == CHAR_TYPE)
@@ -83,6 +130,7 @@ convert (type, expr)
   return error_mark_node;
 }
 
+
 tree
 convert_to_char (type, expr)
     tree type, expr;