diff mbox series

module_column not initialized in write_module()

Message ID 3666129.0IVxUXv0u3@andrew-precision-3520
State New
Headers show
Series module_column not initialized in write_module() | expand

Commit Message

Andrew Benson May 1, 2019, 6:39 p.m. UTC
The value of 'module_column' is not initialized in write_module() before a 
module file is written. As a result, the first line break in the module file can 
occur at an arbitrary column, depending on what value 'module_column' happens 
to have. While this doesn't affect the behavior of the module file as far as 
gfortran is concerned, it does mean that the structure of the module file can 
change, even though the actual content is unaltered. 

For example, these first few lines of a (uncompressed) module file before and 
after adding a single write statement to one of its functions:

GFORTRAN module version '15' created from 
structure_formation.excursion_sets.first_crossing_distribution.p.F90
(() ()
() () () () () () () () () () () () () () () () () () () () () () () ()
())

()

and:

GFORTRAN module version '15' created from 
structure_formation.excursion_sets.first_crossing_distribution.p.F90
(() () () () () () () () () () () () () () () () () () () () () () ()
() () () ())

()

When building large projects with gfortran I 'cmp' newly produced module files 
with the equivalent module file from the previous build as a way to avoid 
recompilation cascades. The changing position of the first line break makes 
this approach not work.

Fixing this seems to be simple:

This causes no regressions. I've attached the patch including the ChangeLog - 
is this ok to commit?

-Andrew

Comments

Thomas Koenig May 1, 2019, 7:35 p.m. UTC | #1
Hi Andrew,

> Fixing this seems to be simple:
> 
> --- gcc/fortran/module.c        (revision 270772)
> +++ gcc/fortran/module.c        (working copy)
> @@ -6052,6 +6052,9 @@ write_module (void)
>   {
>     int i;
>   
> +  /* Initialize the column counter. */
> +  module_column = 1;
> +
>     /* Write the operator interfaces.  */
>     mio_lparen ();
> 
> This causes no regressions. I've attached the patch including the ChangeLog -
> is this ok to commit?

OK for trunk.

Thanks a lot for the patch!

Regards

	Thomas
Andrew Benson May 1, 2019, 7:49 p.m. UTC | #2
Thanks Thomas, committed as r270777.

On Wednesday, May 1, 2019 9:35:13 PM PDT Thomas Koenig wrote:
> Hi Andrew,
> 
> > Fixing this seems to be simple:
> > 
> > --- gcc/fortran/module.c        (revision 270772)
> > +++ gcc/fortran/module.c        (working copy)
> > @@ -6052,6 +6052,9 @@ write_module (void)
> > 
> >   {
> >   
> >     int i;
> > 
> > +  /* Initialize the column counter. */
> > +  module_column = 1;
> > +
> > 
> >     /* Write the operator interfaces.  */
> >     mio_lparen ();
> > 
> > This causes no regressions. I've attached the patch including the
> > ChangeLog - is this ok to commit?
> 
> OK for trunk.
> 
> Thanks a lot for the patch!
> 
> Regards
> 
> 	Thomas
diff mbox series

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 270772)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -1,3 +1,8 @@ 
+2019-05-01  Andrew Benson  <abensonca@gmail.com>
+
+	* module.c (write_module): Initialize module_column before writing
+	module to ensure line break occurs at correct column.
+
 2019-04-19  Steven G. Kargl  <kargl@gcc.gnu.org>
 
 	PR fortran/90166
Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c	(revision 270772)
+++ gcc/fortran/module.c	(working copy)
@@ -6052,6 +6052,9 @@  write_module (void)
 {
   int i;
 
+  /* Initialize the column counter. */
+  module_column = 1;
+  
   /* Write the operator interfaces.  */
   mio_lparen ();