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: [PATCH, libgfortran] Fix PR21875 (FM111.f) BN and BZ formatspecifiers


Jerry DeLisle wrote:

I have isolated two separate problems. The first is discovered coincidentally bacause of the manual entry of numbers from the console in the reduced case given in bugzilla that you referred to.


1) When reading from stdin, the flags.blank was set to BLANK_ZERO. This causes trailing blanks on input fields to be converted to zero's resulting in exponents out of range. This is in io/unit.c. The default should be set to BLANK_UNSPECIFIED.

Once that is fixed, then 2 happens

2) Exponents with trailing blanks are getting garbaged up for some reason. I am in the middle of fixing that.

The attached patches fix the problems in libgfortran and revise the test case to include a test of the snippet similar to the SPECfp problem with trailing blanks in exponents.

Regression tested (excluding real_const_1.f90, real_const_2.f90, and elemental.f90, which are failing from something else).

2005-07-19 Jerry DeLisle <jvdelisle@verizon.net>

* io/read.c (read_f): Fix reading of trailing blanks in exponents related to BZ and BN format specifier logic.
* io/unit.c (init_units): Change default setting of u->flags.blank
to BLANK_UNSPECIFIED for stdin, stdout, and stderr.


OK to commit to mainline and 4.0?

Jerry
Index: read.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/read.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 read.c
*** read.c	13 Jul 2005 18:43:11 -0000	1.14
--- read.c	20 Jul 2005 04:27:33 -0000
*************** read_f (fnode * f, char *dest, int lengt
*** 691,714 ****
    p++;
    w--;
  
!   while (w > 0)
      {
!       if (*p == ' ')
          {
!           if (g.blank_status == BLANK_ZERO) *p = '0';
!           if (g.blank_status == BLANK_NULL)
              {
!               p++;
!               w--;
!               continue;
              }
          }
-       if (!isdigit (*p))
-         goto bad_float;
-         
-       exponent = 10 * exponent + *p - '0';
-       p++;
-       w--;
      }
  
    exponent = exponent * exponent_sign;
--- 691,736 ----
    p++;
    w--;
  
!   if (g.blank_status == BLANK_UNSPECIFIED) /* Normal processing of exponent */
      {
!       while (w > 0 && isdigit (*p))
          {
!           exponent = 10 * exponent + *p - '0';
!           p++;
!           w--;
!         }
!         
!       /* Only allow trailing blanks */
! 
!       while (w > 0)
!         {
!           if (*p != ' ')
!   	  goto bad_float;
!           p++;
!           w--;
!         }
!     }    
!   else  /* BZ or BN status is enabled */
!     {
!       while (w > 0)
!         {
!           if (*p == ' ')
              {
!               if (g.blank_status == BLANK_ZERO) *p = '0';
!               if (g.blank_status == BLANK_NULL)
!                 {
!                   p++;
!                   w--;
!                   continue;
!                 }
              }
+           else if (!isdigit (*p))
+             goto bad_float;
+ 
+           exponent = 10 * exponent + *p - '0';
+           p++;
+           w--;
          }
      }
  
    exponent = exponent * exponent_sign;
Index: unit.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unit.c,v
retrieving revision 1.12
diff -c -3 -p -r1.12 unit.c
*** unit.c	17 May 2005 17:02:38 -0000	1.12
--- unit.c	20 Jul 2005 04:27:33 -0000
*************** init_units (void)
*** 304,310 ****
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_ZERO;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
--- 304,310 ----
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_UNSPECIFIED;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
*************** init_units (void)
*** 326,332 ****
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_ZERO;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
--- 326,332 ----
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_UNSPECIFIED;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
*************** init_units (void)
*** 348,354 ****
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_ZERO;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
--- 348,354 ----
        u->flags.access = ACCESS_SEQUENTIAL;
        u->flags.form = FORM_FORMATTED;
        u->flags.status = STATUS_OLD;
!       u->flags.blank = BLANK_UNSPECIFIED;
        u->flags.position = POSITION_ASIS;
  
        u->recl = options.default_recl;
Index: fmt_read_bz_bn.f90
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gfortran.dg/fmt_read_bz_bn.f90,v
retrieving revision 1.1
diff -c -3 -p -r1.1 fmt_read_bz_bn.f90
*** fmt_read_bz_bn.f90	9 Jul 2005 23:40:31 -0000	1.1
--- fmt_read_bz_bn.f90	20 Jul 2005 05:01:23 -0000
*************** program test_bn
*** 6,17 ****
          
  integer I1(2,2), I2(2,2,2)
  real A1(5)
  character*80 :: IDATA1="111 2 2 3 3. 3E-1  44 5 5 6 . 67 . 78 8. 8E-1"
  character*80 :: IDATA2="2345 1 34512 45123 51234 2345 1 34512 45123 5"
  character*80 :: ODATA=""
  character*80 :: CORRECT1=" 1110 2020 .30303E-07   44   55   6.6 70.07 .888E+01"
  character*80 :: CORRECT2="23450 10345. 12.45 1235 1234 2345  1345. 12.45 1235"
! 
  READ(IDATA1, 10) I1(1,2), IVI, A1(3), JVI, KVI, A1(2), AVS, A1(1)
  10 FORMAT (BZ,(2I4, E10.1, BN, 2I4, F5.2, BZ, F5.2, BN, E10.1))
  
--- 6,20 ----
          
  integer I1(2,2), I2(2,2,2)
  real A1(5)
+ real*8 A2(0:3)
  character*80 :: IDATA1="111 2 2 3 3. 3E-1  44 5 5 6 . 67 . 78 8. 8E-1"
  character*80 :: IDATA2="2345 1 34512 45123 51234 2345 1 34512 45123 5"
+ character*80 :: IDATA3="-8.0D0  1.0D-4  0.50D0  0.250D0"
  character*80 :: ODATA=""
  character*80 :: CORRECT1=" 1110 2020 .30303E-07   44   55   6.6 70.07 .888E+01"
  character*80 :: CORRECT2="23450 10345. 12.45 1235 1234 2345  1345. 12.45 1235"
! character*80 :: CORRECT3="   -0.8000000000D+01    0.1000000000D-03&
!     0.5000000000D+00    0.2500000000D+00"
  READ(IDATA1, 10) I1(1,2), IVI, A1(3), JVI, KVI, A1(2), AVS, A1(1)
  10 FORMAT (BZ,(2I4, E10.1, BN, 2I4, F5.2, BZ, F5.2, BN, E10.1))
  
*************** WRITE(ODATA, 40) I2(1,2,1), A1(3), AVS, 
*** 28,32 ****
--- 31,44 ----
  40 FORMAT (I5, F7.0, BZ, 1X, F5.2, 2(1X,I4),I5, F7.0, BZ, 1X, F5.2, 1X, I4)
  
  if (ODATA /= CORRECT2) call abort
+ ODATA=""
+ 
+ READ(IDATA3, 50) A2
+ 50 FORMAT (4D8.0)
+ 
+ WRITE(ODATA,60) A2
+ 60 FORMAT (4D20.10)
+ 
+ if (ODATA /= CORRECT3) call abort
  
  end program test_bn

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