diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2019-05-22 14:56:01 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2019-05-22 14:56:01 +0300 |
commit | 88a8126a906f32068724d87416eeb01971f37f35 (patch) | |
tree | ab7979c83f78bf0bfec681cc5ace497f74f98998 /gcc/fortran | |
parent | fa70c22141f5075ad4a9a3a6630f083c92755799 (diff) | |
download | gcc-88a8126a906f32068724d87416eeb01971f37f35.zip gcc-88a8126a906f32068724d87416eeb01971f37f35.tar.gz gcc-88a8126a906f32068724d87416eeb01971f37f35.tar.bz2 |
fortran/89100: Default widths with -fdec-format-defaults
gcc/fortran ChangeLog:
2019-05-22 Jeff Law <law@redhat.com>
Mark Eggleston <mark.eggleston@codethink.com>
PR fortran/89100
* gfortran.texi: Add Default widths for F, G and I format
descriptors to Extensions section.
* invoke.texi: Add -fdec-format-defaults
* io.c (check_format): Use default widths for i, f and g when
flag_dec_format_defaults is enabled.
* lang.opt: Add new option.
* options.c (set_dec_flags): Add SET_BITFLAG for
flag_dec_format_defaults.
gcc/testsuite ChangeLog:
2019-05-22 Mark Eggleston <mark.eggleston@codethink.com>
PR fortran/89100
* gfortran.dg/fmt_f_default_field_width_1.f90: New test.
* gfortran.dg/fmt_f_default_field_width_2.f90: New test.
* gfortran.dg/fmt_f_default_field_width_3.f90: New test.
* gfortran.dg/fmt_g_default_field_width_1.f90: New test.
* gfortran.dg/fmt_g_default_field_width_2.f90: New test.
* gfortran.dg/fmt_g_default_field_width_3.f90: New test.
* gfortran.dg/fmt_i_default_field_width_1.f90: New test.
* gfortran.dg/fmt_i_default_field_width_2.f90: New test.
* gfortran.dg/fmt_i_default_field_width_3.f90: New test.
libgfortran ChangeLog:
2019-05-22 Jeff Law <law@redhat.com>
PR fortran/89100
* io/format.c (parse_format_list): set default width when the
IOPARM_DT_DEC_EXT flag is set for i, f and g.
* io/io.h: add default_width_for_integer, default_width_for_float
and default_precision_for_float.
* io/write.c (write_boz): extra parameter giving length of data
corresponding to the type's kind.
(write_b): pass data length as extra parameter in calls to
write_boz.
(write_o): pass data length as extra parameter in calls to
write_boz.
(write_z): pass data length as extra parameter in calls to
write_boz.
(size_from_kind): also set size is default width is set.
* io/write_float.def (build_float_string): new paramter inserted
before result parameter. If default width use values passed
instead of the values in fnode.
(FORMAT_FLOAT): macro modified to check for default width and
calls to build_float_string to pass in default width.
(get_float_string): set width and precision to defaults when
needed.
From-SVN: r271511
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/fortran/gfortran.texi | 17 | ||||
-rw-r--r-- | gcc/fortran/invoke.texi | 25 | ||||
-rw-r--r-- | gcc/fortran/io.c | 31 | ||||
-rw-r--r-- | gcc/fortran/lang.opt | 4 | ||||
-rw-r--r-- | gcc/fortran/options.c | 1 |
6 files changed, 77 insertions, 14 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e6ae6bc..f119e74 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2019-05-22 Jeff Law <law@redhat.com> + Mark Eggleston <mark.eggleston@codethink.com> + + PR fortran/89100 + * gfortran.texi: Add Default widths for F, G and I format + descriptors to Extensions section. + * invoke.texi: Add -fdec-format-defaults + * io.c (check_format): Use default widths for i, f and g when + flag_dec_format_defaults is enabled. + * lang.opt: Add new option. + * options.c (set_dec_flags): Add SET_BITFLAG for + flag_dec_format_defaults. + 2019-05-21 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/90038 diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 6c746e3..57461e0 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -1576,6 +1576,7 @@ additional compatibility extensions along with those enabled by * X format descriptor without count field:: * Commas in FORMAT specifications:: * Missing period in FORMAT specifications:: +* Default widths for F@comma{} G and I format descriptors:: * I/O item lists:: * @code{Q} exponent-letter:: * BOZ literal constants:: @@ -1782,6 +1783,22 @@ discouraged. 10 FORMAT ('F4') @end smallexample +@node Default widths for F@comma{} G and I format descriptors +@subsection Default widths for @code{F}, @code{G} and @code{I} format descriptors + +To support legacy codes, GNU Fortran allows width to be omitted from format +specifications if and only if @option{-fdec-format-defaults} is given on the +command line. Default widths will be used. This is considered non-conforming +code and is discouraged. + +@smallexample + REAL :: value1 + INTEGER :: value2 + WRITE(*,10) value1, value1, value2 +10 FORMAT ('F, G, I') +@end smallexample + + @node I/O item lists @subsection I/O item lists @cindex I/O item lists diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index ec3b040..73b836e 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -117,16 +117,16 @@ by type. Explanations are in the following sections. @item Fortran Language Options @xref{Fortran Dialect Options,,Options controlling Fortran dialect}. @gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol --fd-lines-as-comments @gol --fdec -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math @gol --fdec-include -fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 @gol --fdefault-real-10 -fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol --ffixed-line-length-none -fpad-source -ffree-form -ffree-line-length-@var{n} @gol --ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol --fmax-identifier-length -fmodule-private -ffixed-form -fno-range-check @gol --fopenacc -fopenmp -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 @gol --freal-8-real-10 -freal-8-real-16 -freal-8-real-4 -std=@var{std} --ftest-forall-temp +-fd-lines-as-comments -fdec -fdec-structure -fdec-intrinsic-ints @gol +-fdec-static -fdec-math -fdec-include -fdec-format-defaults @gol +-fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 -fdefault-real-10 @gol +-fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol +-ffixed-line-length-none -fpad-source -ffree-form @gol +-ffree-line-length-@var{n} -ffree-line-length-none @gol +-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length @gol +-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp @gol +-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10 @gol +-freal-8-real-16 -freal-8-real-4 -std=@var{std} -ftest-forall-temp } @item Preprocessing Options @@ -283,6 +283,11 @@ Enable parsing of INCLUDE as a statement in addition to parsing it as INCLUDE line. When parsed as INCLUDE statement, INCLUDE does not have to be on a single line and can use line continuations. +@item -fdec-format-defaults +@opindex @code{fdec-format-defaults} +Enable format specifiers F, G and I to be used without width specifiers, +default widths will be used instead. + @item -fdollar-ok @opindex @code{fdollar-ok} @cindex @code{$} diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 9828897..5711757 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -903,6 +903,13 @@ data_desc: if (u != FMT_POSINT) { + if (flag_dec_format_defaults) + { + /* Assume a default width based on the variable size. */ + saved_token = u; + break; + } + format_locus.nextc += format_string_pos; gfc_error ("Positive width required in format " "specifier %s at %L", token_to_string (t), @@ -1027,6 +1034,13 @@ data_desc: goto fail; if (t != FMT_ZERO && t != FMT_POSINT) { + if (flag_dec_format_defaults) + { + /* Assume the default width is expected here and continue lexing. */ + value = 0; /* It doesn't matter what we set the value to here. */ + saved_token = t; + break; + } error = nonneg_required; goto syntax; } @@ -1096,8 +1110,17 @@ data_desc: goto fail; if (t != FMT_ZERO && t != FMT_POSINT) { - error = nonneg_required; - goto syntax; + if (flag_dec_format_defaults) + { + /* Assume the default width is expected here and continue lexing. */ + value = 0; /* It doesn't matter what we set the value to here. */ + saved_token = t; + } + else + { + error = nonneg_required; + goto syntax; + } } else if (is_input && t == FMT_ZERO) { @@ -4368,8 +4391,8 @@ get_io_list: } /* See if we want to use defaults for missing exponents in real transfers - and other DEC runtime extensions. */ - if (flag_dec) + and other DEC runtime extensions. */ + if (flag_dec_format_defaults) dt->dec_ext = 1; /* A full IO statement has been matched. Check the constraints. spec_end is diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 80edc11..4d2340a 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -452,6 +452,10 @@ fdec-include Fortran Var(flag_dec_include) Enable legacy parsing of INCLUDE as statement. +fdec-format-defaults +Fortran Var(flag_dec_format_defaults) +Enable default widths for i, f and g format specifiers. + fdec-intrinsic-ints Fortran Var(flag_dec_intrinsic_ints) Enable kind-specific variants of integer intrinsic functions. diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 02970d5..4f91486 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -74,6 +74,7 @@ set_dec_flags (int value) SET_BITFLAG (flag_dec_static, value, value); SET_BITFLAG (flag_dec_math, value, value); SET_BITFLAG (flag_dec_include, value, value); + SET_BITFLAG (flag_dec_format_defaults, value, value); } /* Finalize DEC flags. */ |