This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/32048] max / min and NaN
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jul 2007 13:49:42 -0000
- Subject: [Bug fortran/32048] max / min and NaN
- References: <bug-32048-10391@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from fxcoudert at gcc dot gnu dot org 2007-07-28 13:49 -------
Here's a patch that yields results according to IEEE:
Index: f95-lang.c
===================================================================
--- f95-lang.c (revision 126997)
+++ f95-lang.c (working copy)
@@ -1004,6 +1004,11 @@ gfc_init_builtin_functions (void)
"malloc", false);
DECL_IS_MALLOC (built_in_decls[BUILT_IN_MALLOC]) = 1;
+ tmp = tree_cons (NULL_TREE, void_type_node, void_list_node);
+ ftype = build_function_type (integer_type_node, tmp);
+ gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
+ "__builtin_isnan", true);
+
#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
builtin_types[(int) ENUM] = VALUE;
#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c (revision 126997)
+++ trans-intrinsic.c (working copy)
@@ -1407,11 +1407,11 @@ gfc_conv_intrinsic_ttynam (gfc_se * se,
/* Get the minimum/maximum value of all the parameters.
minmax (a1, a2, a3, ...)
{
- if (a2 .op. a1)
+ if (a2 .op. a1 || isnan(a1))
mvar = a2;
else
mvar = a1;
- if (a3 .op. mvar)
+ if (a3 .op. mvar || isnan(mvar))
mvar = a3;
...
return mvar
@@ -1487,7 +1487,7 @@ gfc_conv_intrinsic_minmax (gfc_se * se,
elsecase = build2_v (MODIFY_EXPR, mvar, limit);
for (i = 1, argexpr = argexpr->next; i < nargs; i++)
{
- tree cond;
+ tree cond, isnan;
val = args[i];
@@ -1509,6 +1509,11 @@ gfc_conv_intrinsic_minmax (gfc_se * se,
thencase = build2_v (MODIFY_EXPR, mvar, convert (type, val));
tmp = build2 (op, boolean_type_node, convert (type, val), limit);
+ if (FLOAT_TYPE_P (TREE_TYPE (limit)))
+ {
+ isnan = build_call_expr (built_in_decls[BUILT_IN_ISNAN], 1, limit);
+ tmp = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, tmp, isnan);
+ }
tmp = build3_v (COND_EXPR, tmp, thencase, elsecase);
if (cond != NULL_TREE)
With this, we generate calls to __builtin_isnan, which probably means slower
code is generated. Thus, we might want to make this dependent on whether
IEEE_ARITHMETIC is loaded or not, when we have this module implemented.
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2007-07-28 13:49:41
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32048