Discussion:
[PATCH] Add -fpad-source option
Jakub Jelinek
2018-11-22 10:00:13 UTC
Permalink
Hi!

In the -fdec-include thread, Mark raised privately that some compilers
(verified on fortran.godbolt.org for ifort only myself) do not pad
fixed-form lines to the line length like gfortran does. Usually it makes no
difference, but if a string constant is continued, it does (including when
it appears in include string). We don't pad only with
-ffixed-line-length-{0,none}, but that has other effects, like not ignoring
characters in column 73+, which is needed for certain sources, e.g. if
an include file is written with fixed as well as free form compatible line
continuations.
ifort apparently has a -pad-source option which defaults to -nopad-source.

This patch introduces similar option, just with a different default (the one
that we default to).

What is the behavior of DEC fortran, Sun/Oracle fortran and others?
If not padding is common to the DEC fortran derived compilers, perhaps
-fdec might imply -fno-pad-source ?

Ok for trunk if it passes bootstrap/regtest (so far just checked with
make check-gfortran RUNTESTFLAGS='dg.exp=pad_source*'
)?

2018-11-22 Jakub Jelinek <***@redhat.com>

* lang.opt (fpad-source): New option.
* scanner.c (load_line): Don't pad fixed form lines if
!flag_pad_source.
* invoke.texi (-fno-pad-source): Document.

* gfortran.dg/pad_source_1.f: New test.
* gfortran.dg/pad_source_2.f: New test.
* gfortran.dg/pad_source_3.f: New test.
* gfortran.dg/pad_source_4.f: New test.
* gfortran.dg/pad_source_5.f: New test.

--- gcc/fortran/lang.opt.jj 2018-11-21 09:06:39.937688966 +0100
+++ gcc/fortran/lang.opt 2018-11-22 09:23:43.090852471 +0100
@@ -536,6 +536,10 @@ ffixed-line-length-
Fortran RejectNegative Joined UInteger Var(flag_fixed_line_length) Init(72)
-ffixed-line-length-<n> Use n as character line width in fixed mode.

+fpad-source
+Fortran Var(flag_pad_source) Init(1)
+Pad shorter fixed form lines to line width with spaces.
+
ffpe-trap=
Fortran RejectNegative JoinedOrMissing
-ffpe-trap=[...] Stop on following floating point exceptions.
--- gcc/fortran/scanner.c.jj 2018-11-21 09:06:39.946688820 +0100
+++ gcc/fortran/scanner.c 2018-11-22 09:33:51.861790813 +0100
@@ -1924,6 +1924,7 @@ next_char:
/* Pad lines to the selected line length in fixed form. */
if (gfc_current_form == FORM_FIXED
&& flag_fixed_line_length != 0
+ && flag_pad_source
&& !preprocessor_flag
&& c != EOF)
{
--- gcc/fortran/invoke.texi.jj 2018-11-21 21:06:01.869189443 +0100
+++ gcc/fortran/invoke.texi 2018-11-22 10:07:55.285011379 +0100
@@ -121,7 +121,7 @@ by type. Explanations are in the follow
-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 -ffree-form -ffree-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
@@ -321,8 +321,9 @@ declared as @code{PUBLIC}.
@opindex @code{ffixed-line-length-}@var{n}
@cindex file format, fixed
Set column after which characters are ignored in typical fixed-form
-lines in the source file, and through which spaces are assumed (as
-if padded to that length) after the ends of short fixed-form lines.
+lines in the source file, and, unless @code{-fno-pad-source}, through which
+spaces are assumed (as if padded to that length) after the ends of short
+fixed-form lines.

Popular values for @var{n} include 72 (the
standard and the default), 80 (card image), and 132 (corresponding
@@ -333,6 +334,15 @@ to them to fill out the line.
@option{-ffixed-line-length-0} means the same thing as
@option{-ffixed-line-length-none}.

+@item -fno-pad-source
+@opindex @code{fpad-source}
+By default fixed-form lines have spaces assumed (as if padded to that length)
+after the ends of short fixed-form lines. This is not done either if
+@option{-ffixed-line-length-0}, @option{-ffixed-line-length-none} or
+if @option{-fno-pad-source} option is used. With any of those options
+continued character constants never have implicit spaces appended
+to them to fill out the line.
+
@item -ffree-line-length-@var{n}
@opindex @code{ffree-line-length-}@var{n}
@cindex file format, free
--- gcc/testsuite/gfortran.dg/pad_source_1.f.jj 2018-11-22 09:43:45.952971238 +0100
+++ gcc/testsuite/gfortran.dg/pad_source_1.f 2018-11-22 09:48:35.933177267 +0100
@@ -0,0 +1,8 @@
+c { dg-do run }
+c { dg-skip-if "non-standard options" { *-*-* } { "-ffixed-line-length*" "-f*pad-source" } }
+ character(80) a
+ a = 'abc
+ +def'
+ if (a(:61) .ne. 'abc') stop 1
+ if (a(62:) .ne. 'def') stop 2
+ end
--- gcc/testsuite/gfortran.dg/pad_source_2.f.jj 2018-11-22 09:43:53.955838929 +0100
+++ gcc/testsuite/gfortran.dg/pad_source_2.f 2018-11-22 09:48:43.254056244 +0100
@@ -0,0 +1,9 @@
+c { dg-do run }
+c { dg-skip-if "non-standard options" { *-*-* } { "-ffixed-line-length*" } }
+c { dg-options "-fpad-source" }
+ character(80) a
+ a = 'abc
+ +def'
+ if (a(:61) .ne. 'abc') stop 1
+ if (a(62:) .ne. 'def') stop 2
+ end
--- gcc/testsuite/gfortran.dg/pad_source_3.f.jj 2018-11-22 09:44:23.941343209 +0100
+++ gcc/testsuite/gfortran.dg/pad_source_3.f 2018-11-22 09:44:48.056944540 +0100
@@ -0,0 +1,8 @@
+c { dg-do run }
+c { dg-skip-if "non-standard options" { *-*-* } { "-ffixed-line-length*" } }
+c { dg-options "-fno-pad-source" }
+ character(80) a
+ a = 'abc
+ +def'
+ if (a .ne. 'abcdef') stop 1
+ end
--- gcc/testsuite/gfortran.dg/pad_source_4.f.jj 2018-11-22 09:45:00.395740544 +0100
+++ gcc/testsuite/gfortran.dg/pad_source_4.f 2018-11-22 09:45:13.298527237 +0100
@@ -0,0 +1,7 @@
+c { dg-do run }
+c { dg-options "-ffixed-line-length-none" }
+ character(80) a
+ a = 'abc
+ +def'
+ if (a .ne. 'abcdef') stop 1
+ end
--- gcc/testsuite/gfortran.dg/pad_source_5.f.jj 2018-11-22 09:45:20.788403413 +0100
+++ gcc/testsuite/gfortran.dg/pad_source_5.f 2018-11-22 09:45:26.860303031 +0100
@@ -0,0 +1,7 @@
+c { dg-do run }
+c { dg-options "-ffixed-line-length-0" }
+ character(80) a
+ a = 'abc
+ +def'
+ if (a .ne. 'abcdef') stop 1
+ end

Jakub
Jakub Jelinek
2018-11-22 19:43:55 UTC
Permalink
Post by Jakub Jelinek
Ok for trunk if it passes bootstrap/regtest (so far just checked with
make check-gfortran RUNTESTFLAGS='dg.exp=pad_source*'
)?
Note, it passed bootstrap/regtest on x86_64-linux.
Post by Jakub Jelinek
* lang.opt (fpad-source): New option.
* scanner.c (load_line): Don't pad fixed form lines if
!flag_pad_source.
* invoke.texi (-fno-pad-source): Document.
* gfortran.dg/pad_source_1.f: New test.
* gfortran.dg/pad_source_2.f: New test.
* gfortran.dg/pad_source_3.f: New test.
* gfortran.dg/pad_source_4.f: New test.
* gfortran.dg/pad_source_5.f: New test.
Jakub
Jerry DeLisle
2018-11-22 23:56:27 UTC
Permalink
Post by Jakub Jelinek
Post by Jakub Jelinek
Ok for trunk if it passes bootstrap/regtest (so far just checked with
make check-gfortran RUNTESTFLAGS='dg.exp=pad_source*'
)?
Note, it passed bootstrap/regtest on x86_64-linux.
OK, and thanks for the work.

Jerry

Loading...