testcases for pr21302 [was: Re: [patch] pr21302: Max line length in free form mode]
Bernhard Fischer
rep.nop@aon.at
Mon Oct 24 16:06:00 GMT 2005
Two testcases attached.
gfortran -ffixed-line-length-none -ffree-line-length-none -o a.elf f1.f f2.f90 && ./a.elf
thank you,
On Mon, Oct 24, 2005 at 03:28:35PM +0200, Bernhard Fischer wrote:
>On Sat, Oct 22, 2005 at 03:48:28PM +0200, Bernhard Fischer wrote:
>
>>21302 Max line length in free form mode
>
>Earlier referenced by Paul Brook here:
>http://gcc.gnu.org/ml/fortran/2004-07/msg00212.html
>
>2005-xx-yy Bernhard Fischer <rep.nop@aon.at>
>
> PR fortran/21302
> * lang.opt: New options -ffree-line-length- and -ffree-line-length-none.
> * gfortran.h: Add free_line_length.
> * c-opts.c (c_common_handle_option): Ignore OPT_ffree_form and
> OPT_ffree_line_length_ when preprocessing.
> * options.c (gfc_init_options, gfc_handle_option): Initialize
> and set free_line_length and fixed_line_length.
> * scanner.c (load_line): Set free_line_length to 132 and
> fixed_line_length to 72 or user requested values. A line either
> starts with '#' thus is a preprocessor-line or is an include, so
> use "else".
> * scanner.c: Typo in comment.
> * invoke.texi: Document -ffree-line-length- and
> -ffree-line-length-none
>
>Three questions:
>In c-opts.c, see XXX. I would reuse the existing case instead of
>duplicating it. This would, however, violate the alphabetical order.
>
>In options.c, gfc_handle_option(), eventually drop the check for the
>requested line-length but error out hinting to -ffree-line-length-none.
>The line-parser obviously gets incredibly slow (or could OOM) if you
>allocate huge amounts of memory instead of simply using ..-length-none.
>Maybe do the same for ffixed-line-length-<huge value>.
>
>In lang.opt, why is ffixed-line-length-none flagged with
>"Fortran RejectNegative" instead of plain "Fortran"?
>
>
>
>Please review and commit as it is trivial. Please wait for the assignment
>if you really think it to be a substantial contribution (it is not)..
>
>thank you,
>Bernhard
>diff -X excl -rduNp gcc.oorig/gcc/c-opts.c gcc/gcc/c-opts.c
>--- gcc.oorig/gcc/c-opts.c 2005-09-24 11:52:53.000000000 +0200
>+++ gcc/gcc/c-opts.c 2005-10-24 13:16:43.000000000 +0200
>@@ -662,6 +662,15 @@ c_common_handle_option (size_t scode, co
> flag_new_for_scope = value;
> break;
>
>+ /* XXX: mv this to OPT_ffixed_form: to peruse the case there. This would
>+ * violate the convention to handle the OPTs in alphabetical order. */
>+ case OPT_ffree_form:
>+ case OPT_ffree_line_length_:
>+ /* Fortran front end options ignored when preprocessing only. */
>+ if (!flag_preprocess_only)
>+ result = 0;
>+ break;
>+
> case OPT_fgnu_keywords:
> flag_no_gnu_keywords = !value;
> break;
>diff -X excl -rduNp gcc.oorig/gcc/fortran/gfortran.h gcc/gcc/fortran/gfortran.h
>--- gcc.oorig/gcc/fortran/gfortran.h 2005-10-18 09:00:36.000000000 +0200
>+++ gcc/gcc/fortran/gfortran.h 2005-10-24 10:20:19.000000000 +0200
>@@ -1432,6 +1432,7 @@ typedef struct
> char *module_dir;
> gfc_source_form source_form;
> int fixed_line_length;
>+ int free_line_length;
> int max_identifier_length;
> int verbose;
>
>diff -X excl -rduNp gcc.oorig/gcc/fortran/invoke.texi gcc/gcc/fortran/invoke.texi
>--- gcc.oorig/gcc/fortran/invoke.texi 2005-10-13 09:31:13.000000000 +0200
>+++ gcc/gcc/fortran/invoke.texi 2005-10-24 10:20:19.000000000 +0200
>@@ -119,6 +119,7 @@ by type. Explanations are in the follow
> -fdollar-ok -fimplicit-none -fmax-identifier-length @gol
> -std=@var{std} -fd-lines-as-code -fd-lines-as-comments @gol
> -ffixed-line-length-@var{n} -ffixed-line-length-none @gol
>+-ffree-line-length-@var{n} -ffree-line-length-none @gol
> -fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 }
>
> @item Warning Options
>@@ -252,6 +253,20 @@ to them to fill out the line.
> @option{-ffixed-line-length-0} means the same thing as
> @option{-ffixed-line-length-none}.
>
>+@cindex -ffree-line-length-@var{n} option
>+@cindex options, -ffree-line-length-@var{n}
>+@item -ffree-line-length-@var{n}
>+@cindex source file format
>+@cindex lines, length
>+@cindex length of source lines
>+@cindex free form
>+@cindex limits, lengths of source lines
>+Set column after which characters are ignored in typical free-form
>+lines in the source file.
>+@var{n} may be @samp{none}, meaning that the entire line is meaningful.
>+@option{-ffree-line-length-0} means the same thing as
>+@option{-ffree-line-length-none}.
>+
> @cindex -fmax-identifier-length=@var{n} option
> @cindex option -fmax-identifier-length=@var{n}
> @item -fmax-identifier-length=@var{n}
>diff -X excl -rduNp gcc.oorig/gcc/fortran/lang.opt gcc/gcc/fortran/lang.opt
>--- gcc.oorig/gcc/fortran/lang.opt 2005-10-13 09:31:13.000000000 +0200
>+++ gcc/gcc/fortran/lang.opt 2005-10-24 11:18:45.000000000 +0200
>@@ -137,6 +137,14 @@ ffixed-line-length-
> Fortran RejectNegative Joined UInteger
> -ffixed-line-length-<n> Use n as character line width in fixed mode
>
>+ffree-line-length-none
>+Fortran RejectNegative
>+Allow arbitrary character line width in free mode
>+
>+ffree-line-length-
>+Fortran RejectNegative Joined UInteger
>+-ffree-line-length-<n> Use n as character line width in free mode
>+
> fmax-identifier-length=
> Fortran RejectNegative Joined UInteger
> -fmax-identifier-length=<n> Maximum identifier length
>diff -X excl -rduNp gcc.oorig/gcc/fortran/options.c gcc/gcc/fortran/options.c
>--- gcc.oorig/gcc/fortran/options.c 2005-10-13 09:31:13.000000000 +0200
>+++ gcc/gcc/fortran/options.c 2005-10-24 10:20:19.000000000 +0200
>@@ -45,7 +45,8 @@ gfc_init_options (unsigned int argc ATTR
> gfc_source_file = NULL;
> gfc_option.module_dir = NULL;
> gfc_option.source_form = FORM_UNKNOWN;
>- gfc_option.fixed_line_length = 72;
>+ gfc_option.fixed_line_length = -1;
>+ gfc_option.free_line_length = -1;
> gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
> gfc_option.verbose = 0;
>
>@@ -397,10 +398,30 @@ gfc_handle_option (size_t scode, const c
> gfc_option.source_form = FORM_FIXED;
> break;
>
>+ case OPT_ffixed_line_length_none:
>+ gfc_option.fixed_line_length = 0;
>+ break;
>+
>+ case OPT_ffixed_line_length_:
>+ if (value != 0 && value < 7)
>+ gfc_fatal_error ("Fixed line length must be at least seven.");
>+ gfc_option.fixed_line_length = value;
>+ break;
>+
> case OPT_ffree_form:
> gfc_option.source_form = FORM_FREE;
> break;
>
>+ case OPT_ffree_line_length_none:
>+ gfc_option.free_line_length = 0;
>+ break;
>+
>+ case OPT_ffree_line_length_:
>+ if (value > (USHRT_MAX * 2)) /* arbitrarily chosen value. */
>+ gfc_warning_now ("Freeform line length of %d requested.", value);
>+ gfc_option.free_line_length = value;
>+ break;
>+
> case OPT_funderscoring:
> gfc_option.flag_underscoring = value;
> break;
>@@ -433,16 +454,6 @@ gfc_handle_option (size_t scode, const c
> gfc_option.flag_repack_arrays = value;
> break;
>
>- case OPT_ffixed_line_length_none:
>- gfc_option.fixed_line_length = 0;
>- break;
>-
>- case OPT_ffixed_line_length_:
>- if (value != 0 && value < 7)
>- gfc_fatal_error ("Fixed line length must be at least seven.");
>- gfc_option.fixed_line_length = value;
>- break;
>-
> case OPT_fmax_identifier_length_:
> if (value > GFC_MAX_SYMBOL_LEN)
> gfc_fatal_error ("Maximum supported idenitifier length is %d",
>diff -X excl -rduNp gcc.oorig/gcc/fortran/scanner.c gcc/gcc/fortran/scanner.c
>--- gcc.oorig/gcc/fortran/scanner.c 2005-08-22 08:52:33.000000000 +0200
>+++ gcc/gcc/fortran/scanner.c 2005-10-24 14:44:15.000000000 +0200
>@@ -690,7 +690,7 @@ gfc_gobble_whitespace (void)
> In fixed mode, we expand a tab that occurs within the statement
> label region to expand to spaces that leave the next character in
> the source region.
>- load_line returns wether the line was truncated. */
>+ load_line returns whether the line was truncated. */
>
> static int
> load_line (FILE * input, char **pbuf, int *pbuflen)
>@@ -701,9 +701,21 @@ load_line (FILE * input, char **pbuf, in
>
> /* Determine the maximum allowed line length. */
> if (gfc_current_form == FORM_FREE)
>- maxlen = GFC_MAX_LINE;
>+ {
>+ if (gfc_option.free_line_length == -1)
>+ maxlen = GFC_MAX_LINE;
>+ else
>+ maxlen = gfc_option.free_line_length;
>+ }
>+ else if (gfc_current_form == FORM_FIXED)
>+ {
>+ if (gfc_option.fixed_line_length == -1)
>+ maxlen = 72;
>+ else
>+ maxlen = gfc_option.fixed_line_length;
>+ }
> else
>- maxlen = gfc_option.fixed_line_length;
>+ maxlen = 72;
>
> if (*pbuf == NULL)
> {
>@@ -768,13 +780,13 @@ load_line (FILE * input, char **pbuf, in
> {
> /* Reallocate line buffer to double size to hold the
> overlong line. */
>- buflen = buflen * 2;
>+ buflen += buflen;
> *pbuf = xrealloc (*pbuf, buflen + 1);
> buffer = (*pbuf)+i;
> }
> }
> else if (i >= maxlen)
>- {
>+ {
> /* Truncate the rest of the line. */
> for (;;)
> {
>@@ -1051,7 +1063,7 @@ load_file (const char *filename, bool in
> line = NULL;
> line_len = 0;
>
>- for (;;)
>+ for (;;)
> {
> int trunc = load_line (input, &line, &line_len);
>
>@@ -1067,8 +1079,7 @@ load_file (const char *filename, bool in
> preprocessor_line (line);
> continue;
> }
>-
>- if (include_line (line))
>+ else if (include_line (line))
> {
> current_file->line++;
> continue;
-------------- next part --------------
C fixed form example .f/.for
program main
integer ii
ii = 0
if (abs(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).gt.999.d0.or.abs(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb).gt.999.d0.or.abs(cccccccccccccccccccc).gt.999.d0) THEN
ii = 1
endif
call two(ii)
if (ii.ne.0) then
call abort
endif
end program main
-------------- next part --------------
! free form example .f90/.f95
subroutine two(ii)
integer ii
if (abs(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).gt.999.d0.or.abs(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb).gt.999.d0.or.abs(cccccccccccccccccccc).gt.999.d0) THEN
ii = ii + 1
endif
end subroutine two
More information about the Fortran
mailing list