This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
PR15205 problem with nearest intrinsic
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: GCC Fortran mailing list <fortran at gcc dot gnu dot org>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 08 May 2004 14:52:54 +0200
- Subject: PR15205 problem with nearest intrinsic
(gcc.gnu.org's new IP hasn't yet propagated to my new nameserver so I
can't lookup the precise description of the bug. This is how I remember
it.) This bug has to do with the value of the NEAREST intrinsic when its
argument is of double precision. We didn't resolve this intrinsic
correctly, so its argument got converted to type default real, and then
the result got converted back to double precision again. This patch adds
the required resolution function, thus fixing the bug.
Bootstrapped and regtested on i686-pc-linux-gnu. Also verified that it
fixes the bug. Please look at the PR, I don't remember if there was a
testcase suitable for our testsuite. IIRC scanning -fdump-parse-tree's
output for __nearest_r8 should do the trick.
- Tobi
2004-04-30 Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/15205
* iresolve.c (gfc_resolve_nearest): Add new function.
* intrinsic.h: ... declare it here.
* intrinsic.c (add_functions): ... add it as resolving function
for NEAREST.
Index: iresolve.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/Attic/iresolve.c,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 iresolve.c
--- iresolve.c 11 Jan 2004 13:57:12 -0000 1.1.2.7
+++ iresolve.c 8 May 2004 11:47:46 -0000
@@ -910,6 +910,16 @@ gfc_resolve_modulo (gfc_expr * f, gfc_ex
a->ts.kind);
}
+void
+gfc_resolve_nearest (gfc_expr * f, gfc_expr * a,
+ gfc_expr *p ATTRIBUTE_UNUSED)
+{
+
+ f->ts = a->ts;
+ f->value.function.name =
+ gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
+ a->ts.kind);
+}
void
gfc_resolve_nint (gfc_expr * f, gfc_expr * a, gfc_expr * kind)
Index: intrinsic.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/Attic/intrinsic.h,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 intrinsic.h
--- intrinsic.h 11 Jan 2004 13:57:12 -0000 1.1.2.5
+++ intrinsic.h 8 May 2004 11:47:46 -0000
@@ -270,6 +270,7 @@ void gfc_resolve_minloc (gfc_expr *, gfc
void gfc_resolve_minval (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_mod (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_modulo (gfc_expr *, gfc_expr *, gfc_expr *);
+void gfc_resolve_nearest (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_nint (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_not (gfc_expr *, gfc_expr *);
void gfc_resolve_pack (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
Index: intrinsic.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/Attic/intrinsic.c,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 intrinsic.c
--- intrinsic.c 7 Feb 2004 14:20:54 -0000 1.1.2.10
+++ intrinsic.c 8 May 2004 11:47:39 -0000
@@ -1300,7 +1300,7 @@ add_functions (void)
make_generic ("modulo", GFC_ISYM_MODULO);
add_sym_2 ("nearest", 1, 1, BT_REAL, dr,
- gfc_check_nearest, gfc_simplify_nearest, NULL,
+ gfc_check_nearest, gfc_simplify_nearest, gfc_resolve_nearest,
x, BT_REAL, dr, 0, s, BT_REAL, dr, 0);
make_generic ("nearest", GFC_ISYM_NEAREST);