Patchwork [Fortran] PR54221 - mark private module vars/procs as TREE_PUBLIC()=0

login
register
mail settings
Submitter Tobias Burnus
Date Aug. 12, 2012, 8:56 a.m.
Message ID <50276FBA.4010906@net-b.de>
Download mbox | patch
Permalink /patch/176779/
State New
Headers show

Comments

Tobias Burnus - Aug. 12, 2012, 8:56 a.m.
Since April, gfortran no longer marks module procedures/variables as 
TREE_PUBLIC, if they are marked as PRIVATE. (-> improved optimization, 
reduced file size)

However, as this PR shows, for "PRIVATE" instead of "PRIVATE :: symbol" 
this didn't work, which is addressed by the attached patch.

I only included a test case for module variables; for module procedures, 
one runs into PR54224.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
Mikael Morin - Aug. 12, 2012, 9:40 a.m.
On 12/08/2012 10:56, Tobias Burnus wrote:
> Build and regtested on x86-64-linux.
> OK for the trunk?

OK.

> 2012-08-11  Tobias Burnus  <burnus@net-b.de>
> 
>         PR fortran/54221
>         * vect/vect-gems.f90: Don't mark module vars as PRIVATE as
>         they appear (ninitialized on the RHS.
                      ^
Typo here. __________/

Thanks.
Mikael

Patch

2012-08-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/54221
	* trans-decl.c (gfc_finish_var_decl, build_function_decl):
	Fix setting private module vars/procs as TREE_PUBLIC(...) = 0.

2012-08-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/54221
	* vect/vect-gems.f90: Don't mark module vars as PRIVATE as
	they appear (ninitialized on the RHS.
	* gfortran.dg/public_private_module_6.f90: New.

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index f1b7444..6ef00e1 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -562,6 +562,12 @@  gfc_finish_var_decl (tree decl, gfc_symbol * sym)
       /* TODO: Don't set sym->module for result or dummy variables.  */
       gcc_assert (current_function_decl == NULL_TREE || sym->result == sym);
       /* This is the declaration of a module variable.  */
+      if (sym->attr.access == ACCESS_UNKNOWN
+	  && (sym->ns->default_access == ACCESS_PRIVATE
+	      || (sym->ns->default_access == ACCESS_UNKNOWN
+		  && gfc_option.flag_module_private)))
+	sym->attr.access = ACCESS_PRIVATE;
+
       if (sym->attr.access != ACCESS_PRIVATE || sym->attr.public_used)
 	TREE_PUBLIC (decl) = 1;
       TREE_STATIC (decl) = 1;
@@ -1839,6 +1845,12 @@  build_function_decl (gfc_symbol * sym, bool global)
      the opposite of declaring a function as static in C).  */
   DECL_EXTERNAL (fndecl) = 0;
 
+  if (sym->attr.access == ACCESS_UNKNOWN && sym->module
+      && (sym->ns->default_access == ACCESS_PRIVATE
+	  || (sym->ns->default_access == ACCESS_UNKNOWN
+	      && gfc_option.flag_module_private)))
+    sym->attr.access = ACCESS_PRIVATE;
+
   if (!current_function_decl
       && !sym->attr.entry_master && !sym->attr.is_main_program
       && (sym->attr.access != ACCESS_PRIVATE || sym->binding_label
diff --git a/gcc/testsuite/gfortran.dg/vect/vect-gems.f90 b/gcc/testsuite/gfortran.dg/vect/vect-gems.f90
index 019b415..2f75355 100644
--- a/gcc/testsuite/gfortran.dg/vect/vect-gems.f90
+++ b/gcc/testsuite/gfortran.dg/vect/vect-gems.f90
@@ -5,9 +5,9 @@  MODULE UPML_mod
 
 IMPLICIT NONE
 
-PUBLIC UPMLupdateE
-
-PRIVATE
+!PUBLIC UPMLupdateE
+!
+!PRIVATE
 
 real(kind=8), dimension(:,:,:), allocatable :: Dx_ilow
 
--- /dev/null	2012-08-08 07:41:43.631684108 +0200
+++ gcc/gcc/testsuite/gfortran.dg/public_private_module_6.f90	2012-08-11 19:07:44.000000000 +0200
@@ -0,0 +1,14 @@ 
+! { dg-do compile }
+! { dg-options "-O1" }
+!
+! PR fortran/54221
+!
+! Check that the unused PRIVATE "aaaa" variable is optimized away
+!
+
+module m
+  private
+  integer, save :: aaaa
+end module m
+
+! { dg-final { scan-assembler-not "aaaa" } }