This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran] Better error reporting for ATAN2
- 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: Thu, 26 Aug 2004 18:53:34 +0200
- Subject: [gfortran] Better error reporting for ATAN2
While investigating PR 17175 I stumbled about how bad our error reporting in
the case of arguments of two different kinds to ATAN2 is. Fix below.
Problematic source:
double precision y
x = 1.; y =1.
x = atan2 (x, y)
end
Old error:
In file setexp.f90:3
x = atan2 (x, y)
1
Error: Type of argument 'x' in call to 'atan2' at (1) should be REAL(4), not
REAL(8)
New error:
In file setexp.f90:3
x = atan2 (x, y)
1
Error: 'x' argument of 'atan2' intrinsic at (1) must be the same type and kind
as 'y'
(BTW the error message could still be enhanced, because the formal definition
of ATAN2 is ATAN2(Y,X), which leads to the confusion more easily seen in the
old error message)
Do we need a testcase for this? Built and tested.
- Tobi
2004-08-26 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
* check.c (gfc_check_atan2): New function.
* intrinsic.c (add_functions): Use gfc_check_atan2 for ATAN2
* intrinsic.h (gfc_check_atan2): Add prototype.
Index: check.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/check.c,v
retrieving revision 1.10
diff -u -p -r1.10 check.c
--- check.c 26 Aug 2004 06:07:50 -0000 1.10
+++ check.c 26 Aug 2004 16:42:20 -0000
@@ -514,6 +514,18 @@ gfc_check_associated (gfc_expr * pointer
try
+gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
+{
+ if (type_check (y, 0, BT_REAL) == FAILURE)
+ return FAILURE;
+ if (same_type_check (y, 0, x, 1) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+
+try
gfc_check_btest (gfc_expr * i, gfc_expr * pos)
{
Index: intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/intrinsic.c,v
retrieving revision 1.17
diff -u -p -r1.17 intrinsic.c
--- intrinsic.c 22 Aug 2004 12:09:26 -0000 1.17
+++ intrinsic.c 26 Aug 2004 16:42:21 -0000
@@ -975,7 +975,7 @@ add_functions (void)
make_generic ("atan", GFC_ISYM_ATAN);
add_sym_2 ("atan2", 1, 1, BT_REAL, dr,
- NULL, gfc_simplify_atan2, gfc_resolve_atan2,
+ gfc_check_atan2, gfc_simplify_atan2, gfc_resolve_atan2,
y, BT_REAL, dr, 0, x, BT_REAL, dr, 0);
add_sym_2 ("datan2", 1, 1, BT_REAL, dd,
Index: intrinsic.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/intrinsic.h,v
retrieving revision 1.11
diff -u -p -r1.11 intrinsic.h
--- intrinsic.h 22 Aug 2004 12:09:26 -0000 1.11
+++ intrinsic.h 26 Aug 2004 16:42:21 -0000
@@ -34,6 +34,7 @@ try gfc_check_abs (gfc_expr *);
try gfc_check_all_any (gfc_expr *, gfc_expr *);
try gfc_check_allocated (gfc_expr *);
try gfc_check_associated (gfc_expr *, gfc_expr *);
+try gfc_check_atan2 (gfc_expr *, gfc_expr *);
try gfc_check_btest (gfc_expr *, gfc_expr *);
try gfc_check_char (gfc_expr *, gfc_expr *);
try gfc_check_cmplx (gfc_expr *, gfc_expr *, gfc_expr *);