This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inverted logic in arith.c:gfc_range_check()?


On Sunday 16 May 2004 18:52, Steve Kargl wrote:
> Gang,
>
> In reading through arith.c, I notice that gfc_range_check()
> contained the snippet:
>
>     case BT_COMPLEX:
>       rc = gfc_check_real_range (e->value.complex.r, e->ts.kind);
>       if (rc != ARITH_OK)
> 	     rc = gfc_check_real_range (e->value.complex.i, e->ts.kind);
>
> where gfc_range_check() supposely checks that the "constant numeric
> expression is within the range for its type and kind.".   Suppose,
> we somehow have a complex number of (1e50, 1.).  The first call
> will set rc = ARITH_OVERFLOW, and then the expression in the
> if () is true.  The second call to gfc_check_real_range will return
> ARITH_OK.  So, gfc_check_real_range() will return ARITH_OK, which
> seems contrary to the value of (1e50, 1.).  Should "!=" actually
> be "=="?  That is, if the real is ok, then check the imaginary part.

Well spotted. Fixed as follows.

Paul

2004-05-16  Paul Brook  <paul@codesourcery.com>

	* arith.c (gfc_range_check): Fix logic error.

Index: arith.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/arith.c,v
retrieving revision 1.4
diff -u -p -r1.4 arith.c
--- arith.c	16 May 2004 11:26:25 -0000	1.4
+++ arith.c	16 May 2004 18:00:02 -0000
@@ -1193,7 +1193,7 @@ gfc_range_check (gfc_expr * e)
 
     case BT_COMPLEX:
       rc = gfc_check_real_range (e->value.complex.r, e->ts.kind);
-      if (rc != ARITH_OK)
+      if (rc == ARITH_OK)
 	rc = gfc_check_real_range (e->value.complex.i, e->ts.kind);
 
       break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]