From patchwork Thu Jan 13 20:57:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Fortran] PR 47266: Mark privat module procedures as TREE_PUBLIC=0 Date: Thu, 13 Jan 2011 10:57:03 -0000 From: Tobias Burnus X-Patchwork-Id: 78813 Message-Id: <4D2F671F.6070403@net-b.de> To: gcc patches , gfortran Module procedures which are marked as PRIVATE do not need to be available outside of the translation unit - thus they do not need to be TREE_PUBLIC (unless they are bind(C)). Build and regtested on x86-86-linux. OK for (whichever) trunk? Tobias PS: When submodules will be implemented, one needs to revisit the check. 2010-01-13 Tobias Burnus PR fortran/47266 * trans-decl.c (build_function_decl): Don't mark private module procedures as TREE_PUBLIC. 2010-01-13 Tobias Burnus PR fortran/47266 * gfortran.dg/module_private_2.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 254db76..2b0a32a 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1664,7 +1664,8 @@ build_function_decl (gfc_symbol * sym, bool global) DECL_EXTERNAL (fndecl) = 0; if (!current_function_decl - && !sym->attr.entry_master && !sym->attr.is_main_program) + && !sym->attr.entry_master && !sym->attr.is_main_program + && (sym->attr.access != ACCESS_PRIVATE || sym->binding_label[0] != '\0')) TREE_PUBLIC (fndecl) = 1; attributes = add_attributes_to_decl (attr, NULL_TREE); --- /dev/null 2011-01-11 08:18:04.636000005 +0100 +++ gcc/gcc/testsuite/gfortran.dg/module_private_2.f90 2011-01-13 19:34:01.000000000 +0100 @@ -0,0 +1,36 @@ +! { dg-do compile } +! { dg-options "-O2 -fdump-tree-optimized" } +! +! PR fortran/47266 +! +! Check whether the private procedure "priv" is optimized away +! +module m + implicit none + private :: priv + private :: export1, export2 + public :: pub +contains + integer function priv() + priv = 44 + end function priv + integer function export1() + export1 = 45 + end function export1 + function export2() bind(C) ! { dg-warning "is marked PRIVATE" } + use iso_c_binding, only: c_int + integer(c_int) :: export2 + export2 = 46 + end function export2 + subroutine pub(a,b) + integer :: a + procedure(export1), pointer :: b + a = priv() + b => export1 + end subroutine pub +end module m +! { dg-final { scan-tree-dump-times "priv" 0 "optimized" } } +! { dg-final { scan-tree-dump-times "export1 \\(\\)" 1 "optimized" } } +! { dg-final { scan-tree-dump-times "export2 \\(\\)" 1 "optimized" } } +! { dg-final { cleanup-tree-dump "optimized" } } +! { dg-final { cleanup-modules "m" } }