]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Default missing exponents to 0 with -fdec.
authorforeese <foreese@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2016 18:09:44 +0000 (18:09 +0000)
committerforeese <foreese@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2016 18:09:44 +0000 (18:09 +0000)
gcc/fortran/
* gfortran.texi: Document.
* gfortran.h (gfc_dt): New field default_exp.
* primary.c (match_real_constant): Default exponent with -fdec.
* io.c (match_io): Set dt.default_exp with -fdec.
* ioparm.def (IOPARM_dt_default_exp): New.
* trans-io.c (build_dt): Set IOPARM_dt_default_exp with -fdec.

libgfortran/io/
* io.h (IOPARM_DT_DEFAULT_EXP): New flag bit.
* list_read.c (parse_real, read_real): Allow omission of exponent with
IOPARM_DT_DEFAULT_EXP.
* read.c (read_f): Ditto.

gcc/testsuite/gfortran.dg/
* dec_exp_1.f90, dec_exp_2.f90, dec_exp_3.f90: New testcases.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241828 138bc75d-0d04-0410-961f-82ee72b054a4

15 files changed:
gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/gfortran.texi
gcc/fortran/io.c
gcc/fortran/ioparm.def
gcc/fortran/primary.c
gcc/fortran/trans-io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dec_exp_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/dec_exp_2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/dec_exp_3.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/io.h
libgfortran/io/list_read.c
libgfortran/io/read.c

index baec7bf3eb5bc975ba9bd07a20c5141ed7846e51..b3cc871688c963cf83b7c136b69452b485090807 100644 (file)
@@ -1,3 +1,12 @@
+2016-11-03  Fritz Reese <fritzoreese@gmail.com>
+
+       * gfortran.texi: Document.
+       * gfortran.h (gfc_dt): New field default_exp.
+       * primary.c (match_real_constant): Default exponent with -fdec.
+       * io.c (match_io): Set dt.default_exp with -fdec.
+       * ioparm.def (IOPARM_dt_default_exp): New.
+       * trans-io.c (build_dt): Set IOPARM_dt_default_exp with -fdec.
+
 2016-11-03  Fritz O. Reese <fritzoreese@gmail.com>
 
        * decl.c (gfc_match_parameter): Allow omitted '()' with -std=legacy.
index b559e8ac5cb0503d2f87929f61703673c1733dbf..3fb6f4152cee3a9fdf783289e4214671dc4812a0 100644 (file)
@@ -2336,6 +2336,7 @@ typedef struct
   gfc_expr *io_unit, *format_expr, *rec, *advance, *iostat, *size, *iomsg,
           *id, *pos, *asynchronous, *blank, *decimal, *delim, *pad, *round,
           *sign, *extra_comma, *dt_io_kind, *udtio;
+  char default_exp;
 
   gfc_symbol *namelist;
   /* A format_label of `format_asterisk' indicates the "*" format */
index cd2c5a52575e88f9195400d46e5337927d40b8d1..6de6c9bfeeb343129124fd7445f6b8304f607e70 100644 (file)
@@ -1472,6 +1472,7 @@ compatibility extensions along with those enabled by @option{-std=legacy}.
 * Bitwise logical operators::
 * Extended I/O specifiers::
 * Legacy PARAMETER statements::
+* Default exponents::
 @end menu
 
 @node Old-style kind specifications
@@ -2713,6 +2714,14 @@ real c
 parameter c = 3.0e8
 @end smallexample
 
+@node Default exponents
+@subsection Default exponents
+@cindex exponent
+
+For compatibility, GNU Fortran supports a default exponent of zero in real
+constants with @option{-fdec}.  For example, @code{9e} would be
+interpreted as @code{9e0}, rather than an error.
+
 
 @node Extensions not implemented in GNU Fortran
 @section Extensions not implemented in GNU Fortran
index 80cf8308da71fa705443e2efd7851a173d400072..04cc1a253581f67bfcde39099b6be01ce6ac8b43 100644 (file)
@@ -4167,6 +4167,10 @@ get_io_list:
        goto syntax;
     }
 
+  /* See if we want to use defaults for missing exponents in real transfers.  */
+  if (flag_dec)
+    dt->default_exp = 1;
+
   /* A full IO statement has been matched.  Check the constraints.  spec_end is
      supplied for cases where no locus is supplied.  */
   m = check_io_constraints (k, dt, io_code, &spec_end);
index f1bf7330fd0dac0672280970ed2dedc075e9fe14..46691874e10cee70584927549b1c491076c46208 100644 (file)
@@ -118,4 +118,5 @@ IOPARM (dt,      round,             1 << 23, char2)
 IOPARM (dt,      sign,         1 << 24, char1)
 #define IOPARM_dt_f2003                      (1 << 25)
 #define IOPARM_dt_dtio               (1 << 26)
+#define IOPARM_dt_default_exp        (1 << 27)
 IOPARM (dt,      u,            0,       pad)
index 2101644fcdc2649377b5c70517b6d98bd87b3212..f26740d42ef7089ead6dbcd00b114051dc1f4d18 100644 (file)
@@ -483,7 +483,7 @@ backup:
 static match
 match_real_constant (gfc_expr **result, int signflag)
 {
-  int kind, count, seen_dp, seen_digits, is_iso_c;
+  int kind, count, seen_dp, seen_digits, is_iso_c, default_exponent;
   locus old_loc, temp_loc;
   char *p, *buffer, c, exp_char;
   gfc_expr *e;
@@ -494,6 +494,7 @@ match_real_constant (gfc_expr **result, int signflag)
 
   e = NULL;
 
+  default_exponent = 0;
   count = 0;
   seen_dp = 0;
   seen_digits = 0;
@@ -575,8 +576,14 @@ match_real_constant (gfc_expr **result, int signflag)
 
   if (!ISDIGIT (c))
     {
-      gfc_error ("Missing exponent in real number at %C");
-      return MATCH_ERROR;
+      /* With -fdec, default exponent to 0 instead of complaining.  */
+      if (flag_dec)
+       default_exponent = 1;
+      else
+       {
+         gfc_error ("Missing exponent in real number at %C");
+         return MATCH_ERROR;
+       }
     }
 
   while (ISDIGIT (c))
@@ -597,8 +604,8 @@ done:
   gfc_current_locus = old_loc;
   gfc_gobble_whitespace ();
 
-  buffer = (char *) alloca (count + 1);
-  memset (buffer, '\0', count + 1);
+  buffer = (char *) alloca (count + default_exponent + 1);
+  memset (buffer, '\0', count + default_exponent + 1);
 
   p = buffer;
   c = gfc_next_ascii_char ();
@@ -621,6 +628,8 @@ done:
 
       c = gfc_next_ascii_char ();
     }
+  if (default_exponent)
+    *p++ = '0';
 
   kind = get_kind (&is_iso_c);
   if (kind == -1)
index 285e551585c01d814bf0bd9d7b15ded5852b3c01..253a5ac70a90cfed7079388f0b417574b066f076 100644 (file)
@@ -1911,6 +1911,9 @@ build_dt (tree function, gfc_code * code)
       if (dt->udtio)
        mask |= IOPARM_dt_dtio;
 
+      if (dt->default_exp)
+       mask |= IOPARM_dt_default_exp;
+
       if (dt->namelist)
        {
          if (dt->format_expr || dt->format_label)
index 3b395839e1133f7f10922e12fe93fb5d05bd38b7..2a7d3360857237d9c0697ec3b3f61cc294e911b2 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-03  Fritz Reese <fritzoreese@gmail.com>
+
+       * gfortran.dg/dec_exp_1.f90: New test.
+       * gfortran.dg/dec_exp_2.f90: Likewise.
+       * gfortran.dg/dec_exp_3.f90: Likewise.
+
 2016-11-03  Fritz O. Reese <fritzoreese@gmail.com>
 
        * gfortran.dg/dec_parameter_1.f: New test.
diff --git a/gcc/testsuite/gfortran.dg/dec_exp_1.f90 b/gcc/testsuite/gfortran.dg/dec_exp_1.f90
new file mode 100644 (file)
index 0000000..c8b395a
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do run }
+! { dg-options "-fdec" }
+!
+! Test support for providing a default exponent of zero when unspecified in
+! real constants with -fdec.
+!
+
+subroutine asserteq (rexp, ract, msg)
+  real, intent(in) :: rexp, ract
+  character(*), intent(in) :: msg
+  if (rexp .ne. ract) then
+    write (*, '(A,F12.6,F12.6)') msg, rexp, ract
+    call abort()
+  endif
+end subroutine
+
+implicit none
+
+real, parameter :: r1 = 8e0
+real, parameter :: r2 = 8e ! { equivalent to 8e0 }
+real, volatile :: r3, r4
+character(2) :: s
+r3 = 8e ! { equivalent to 8e0 }
+s = '8e'
+
+read (s, *) r4
+
+call asserteq (r1, r2, "[const]")
+call asserteq (r1, r3, "[vol. ]")
+call asserteq (r1, r4, "[read ]")
+
+r4 = 8e + 48e
+call asserteq (56e, r4, "[sum ]")
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_exp_2.f90 b/gcc/testsuite/gfortran.dg/dec_exp_2.f90
new file mode 100644 (file)
index 0000000..9137aab
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "" }
+!
+! Make sure we still see an error for missing exponents without -fdec.
+!
+
+implicit none
+
+real, parameter :: r1 = 8e ! { dg-error "Missing exponent" }
+real, volatile :: r2
+r2 = 8e ! { dg-error "Missing exponent" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_exp_3.f90 b/gcc/testsuite/gfortran.dg/dec_exp_3.f90
new file mode 100644 (file)
index 0000000..34835a7
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do run "xfail *-*-*" }
+! { dg-options "" }
+!
+! Make sure we still see an error for missing exponents without -fdec.
+!
+
+implicit none
+
+real :: r
+character(2) :: s
+s = '8e'
+
+read (s, *) r ! { XFAIL "Bad real number" }
+
+end
index 745adf798d2e2382b44b67ee0fa39c4ec9f8ef73..d50ef47b475e3464cf0ac922070dba81114ddee5 100644 (file)
@@ -1,3 +1,10 @@
+2016-11-03  Fritz Reese <fritzoreese@gmail.com>
+
+       * io/io.h (IOPARM_DT_DEFAULT_EXP): New flag bit.
+       * io/list_read.c (parse_real, read_real): Allow omission of exponent
+       with IOPARM_DT_DEFAULT_EXP.
+       * io/read.c (read_f): Ditto.
+
 2016-10-31  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/54679
index 7a548497af9dcbe954dca45e19f9c63638bfa1d9..cd0a26f6aa0961819f4b76d4df219353f04f567e 100644 (file)
@@ -443,6 +443,7 @@ st_parameter_inquire;
 #define IOPARM_DT_HAS_SIGN                     (1 << 24)
 #define IOPARM_DT_HAS_F2003                     (1 << 25)
 #define IOPARM_DT_HAS_UDTIO                     (1 << 26)
+#define IOPARM_DT_DEFAULT_EXP                  (1 << 27)
 /* Internal use bit.  */
 #define IOPARM_DT_IONML_SET                    (1u << 31)
 
index f258c9d92499b787adfb2592f8f07daac8e59768..a35beb88a0045866238e9fb87cc59fae7e870353 100644 (file)
@@ -1374,7 +1374,16 @@ parse_real (st_parameter_dt *dtp, void *buffer, int length)
 
  exp2:
   if (!isdigit (c))
-    goto bad_exponent;
+    {
+      /* Extension: allow default exponent of 0 when omitted.  */
+      if (dtp->common.flags & IOPARM_DT_DEFAULT_EXP)
+       {
+         push_char (dtp, '0');
+         goto done;
+       }
+      else
+       goto bad_exponent;
+    }
 
   push_char (dtp, c);
 
@@ -1816,7 +1825,16 @@ read_real (st_parameter_dt *dtp, void * dest, int length)
 
  exp2:
   if (!isdigit (c))
-    goto bad_exponent;
+    {
+      /* Extension: allow default exponent of 0 when omitted.  */
+      if (dtp->common.flags & IOPARM_DT_DEFAULT_EXP)
+       {
+         push_char (dtp, '0');
+         goto done;
+       }
+      else
+       goto bad_exponent;
+    }
 
   push_char (dtp, c);
 
index 23b6f644429331d31dc85c6b3d5fee19c49a61f1..508b3a04fb0ee624b56f5f178abeb1ec67434123 100644 (file)
@@ -1087,7 +1087,13 @@ exponent:
      the d parameter before explict conversion takes place.  */
 
   if (w == 0)
-    goto bad_float;
+    {
+      /* Extension: allow default exponent of 0 when omitted.  */
+      if (dtp->common.flags & IOPARM_DT_DEFAULT_EXP)
+       goto done;
+      else
+       goto bad_float;
+    }
 
   if (dtp->u.p.blank_status == BLANK_UNSPECIFIED)
     {