Index: gcc/libgfortran/m4/minval.m4 |
diff --git a/gcc/libgfortran/m4/minval.m4 b/gcc/libgfortran/m4/minval.m4 |
index 9b8be5bc0ff161e9baf9c33a6290268b97543e28..3acae2eaa88e647c7bb0e56f3bb295ffef511e44 100644 |
--- a/gcc/libgfortran/m4/minval.m4 |
+++ b/gcc/libgfortran/m4/minval.m4 |
@@ -33,14 +33,55 @@ include(ifunction.m4)dnl |
`#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)' |
ARRAY_FUNCTION(atype_max, |
-` result = atype_max;', |
-` if (*src < result) |
- result = *src;') |
+`#if defined ('atype_inf`) |
+ result = atype_inf; |
+#else |
+ result = atype_max; |
+#endif', |
+`#if defined ('atype_nan`) |
+ if (*src <= result) |
+ break; |
+ } |
+ if (unlikely (n >= len)) |
+ result = atype_nan; |
+ else for (; n < len; n++, src += delta) |
+ { |
+#endif |
+ if (*src < result) |
+ result = *src;') |
MASKED_ARRAY_FUNCTION(atype_max, |
-` result = atype_max;', |
-` if (*msrc && *src < result) |
- result = *src;') |
+`#if defined ('atype_inf`) |
+ result = atype_inf; |
+#else |
+ result = atype_max; |
+#endif |
+#if defined ('atype_nan`) |
+ int non_empty_p = 0; |
+#endif', |
+`#if defined ('atype_inf`) || defined ('atype_nan`) |
+ if (*msrc) |
+ { |
+#if defined ('atype_nan`) |
+ non_empty_p = 1; |
+ if (*src <= result) |
+#endif |
+ break; |
+ } |
+ } |
+ if (unlikely (n >= len)) |
+ { |
+#if defined ('atype_nan`) |
+ result = non_empty_p ? atype_nan : atype_max; |
+#else |
+ result = atype_max; |
+#endif |
+ } |
+ else for (; n < len; n++, src += delta, msrc += mdelta) |
+ { |
+#endif |
+ if (*msrc && *src < result) |
+ result = *src;') |
SCALAR_ARRAY_FUNCTION(atype_max) |