* [Patch, Fortran] PR54221 - mark private module vars/procs as TREE_PUBLIC()=0
@ 2012-08-12 8:56 Tobias Burnus
2012-08-12 9:43 ` Mikael Morin
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2012-08-12 8:56 UTC (permalink / raw)
To: gcc patches, gfortran
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
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
[-- Attachment #2: mod-private.diff --]
[-- Type: text/x-patch, Size: 2611 bytes --]
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" } }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR54221 - mark private module vars/procs as TREE_PUBLIC()=0
2012-08-12 8:56 [Patch, Fortran] PR54221 - mark private module vars/procs as TREE_PUBLIC()=0 Tobias Burnus
@ 2012-08-12 9:43 ` Mikael Morin
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2012-08-12 9:43 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc patches, gfortran
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-12 9:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-12 8:56 [Patch, Fortran] PR54221 - mark private module vars/procs as TREE_PUBLIC()=0 Tobias Burnus
2012-08-12 9:43 ` Mikael Morin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).