This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran] Patch for PR 14055
- From: Bud Davis <bdavis9659 at comcast dot net>
- To: gfortran <fortran at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 06 Mar 2004 14:39:15 -0600
- Subject: [gfortran] Patch for PR 14055
The problem is a leading "+" in a data statement constant yields a zero
in the variable.
DATA I /+100/
gives I=100
Caused by the gmp routines returning an error when given a string with a
leading '+'.
Tested i686/gnu/linux, no additional failures.
Test Case:
C PR 14055, leading '+' in data statements gives a 0 value
C
DATA PI /+3.1415/
DATA I /+100/
IF (PI.NE.3.1415) THEN
PRINT*,'DATA STATEMENT WITH REAL GAVE ',PI,' EXPECTED ',3.14
CALL ABORT
ENDIF
IF (I.NE.100) THEN
PRINT*,'DATA STATEMENT WITH INTEGER GAVE ',I,' EXPECTED ',100
CALL ABORT
ENDIF
END
Changelog:
2004-03-06 Bud Davis <bdavis9659@comcast.net>
PR 14055
* arith.c (gfc_convert_integer,gfc_convert_real): Removed leading '+'
before conversion by gmp library call.
regards,
bud davis
Index: gcc/gcc/fortran/arith.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/arith.c,v
retrieving revision 1.1.2.3
diff -c -3 -p -r1.1.2.3 arith.c
*** gcc/gcc/fortran/arith.c 29 Aug 2003 19:18:33 -0000 1.1.2.3
--- gcc/gcc/fortran/arith.c 6 Mar 2004 19:39:51 -0000
*************** gfc_expr *
*** 2426,2434 ****
gfc_convert_integer (const char *buffer, int kind, int radix, locus * where)
{
gfc_expr *e;
e = gfc_constant_result (BT_INTEGER, kind, where);
! mpz_set_str (e->value.integer, buffer, radix);
return e;
}
--- 2426,2440 ----
gfc_convert_integer (const char *buffer, int kind, int radix, locus * where)
{
gfc_expr *e;
+ const char *t;
e = gfc_constant_result (BT_INTEGER, kind, where);
! /* a leading plus is allowed, but not by mpz_set_str */
! if (buffer[0] == '+')
! t = buffer + 1;
! else
! t = buffer;
! mpz_set_str (e->value.integer, t, radix);
return e;
}
*************** gfc_expr *
*** 2440,2448 ****
gfc_convert_real (const char *buffer, int kind, locus * where)
{
gfc_expr *e;
e = gfc_constant_result (BT_REAL, kind, where);
! mpf_set_str (e->value.real, buffer, 10);
return e;
}
--- 2446,2460 ----
gfc_convert_real (const char *buffer, int kind, locus * where)
{
gfc_expr *e;
+ const char *t;
e = gfc_constant_result (BT_REAL, kind, where);
! /* a leading plus is allowed, but not by mpf_set_str */
! if (buffer[0] == '+')
! t = buffer + 1;
! else
! t = buffer;
! mpf_set_str (e->value.real, t, 10);
return e;
}