[gfortran] patch: fix COMMON vars in module

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sun Jul 11 00:33:00 GMT 2004


Something like
MODULE m
 common /c/x
contains
 subroutine b()
   x = 1.
 end
end

common /c/x
x = 2.
call b()
print *, x
end

would not print 1 as expected. This was due to the curious bug that we
generated code for x as if it were a module variable. Apparently, only
people working on compilers come up with code as the above.

This two-line patch fixes this, built and tested on i686-pc-linux.
Testcase is also ready for adding to the testsuite.

- Tobi

2004-07-10  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	* trans-decl.c (gfc_create_module_variable): Nothing to do if
	symbol is in common, because we ...
	(gfc_generate_module_vars): Call gfc_trans_common.

Index: trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-decl.c,v
retrieving revision 1.20
diff -u -p -r1.20 trans-decl.c
--- trans-decl.c        10 Jul 2004 22:31:18 -0000      1.20
+++ trans-decl.c        10 Jul 2004 23:09:01 -0000
@@ -1798,8 +1798,9 @@ gfc_create_module_variable (gfc_symbol *
       && (sym->attr.flavor != FL_PARAMETER || sym->attr.dimension == 0))
     return;

-  /* Don't generate variables from other modules.  */
-  if (sym->attr.use_assoc)
+  /* Don't generate variables from other modules. Variables from
+     COMMONs will already have been generated.  */
+  if (sym->attr.use_assoc || sym->attr.in_common)
     return;

   if (sym->backend_decl)
@@ -1867,6 +1868,9 @@ gfc_generate_module_vars (gfc_namespace
   /* Check if the frontend left the namespace in a reasonable state.  */
   assert (ns->proc_name && !ns->proc_name->tlink);

+  /* Generate COMMON blocks.  */
+  gfc_trans_common (ns);
+
   /* Create decls for all the module variables.  */
   gfc_traverse_ns (ns, gfc_create_module_variable);
 }



More information about the Gcc-patches mailing list