This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch,gfortran] PR 23843: IO on derived types with PRIVATE components (fwd)


Sorry, forgot to CC the mailinglists.


        Erik
----- Forwarded message from Erik Edelmann <erik.edelmann@iki.fi> -----

Date: Thu, 22 Sep 2005 23:45:30 +0300
From: Erik Edelmann <erik.edelmann@iki.fi>
To: Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
Subject: Re: [patch,gfortran] PR 23843: IO on derived types with PRIVATE components
In-Reply-To: <4331C937.2010605@physik.uni-muenchen.de>
User-Agent: Mutt/1.4.1i

tobias.schlueter@physik.uni-muenchen.de wrote:
> While the patch certainly does the right thing, there's other stuff that we
> get wrong before and after:
> schluter@pcl247d:~/src/tests> cat derio.f90
> module gfortran2
>     type tp1
>         private
>         integer :: i
>     end type
>     type tp
>         type (tp1) :: t
>     end type tp
> end module
> use gfortran2
> type (tp) :: x
> print *, x
> end
> schluter@pcl247d:~/src/tests> ~/src/gcc/build/gcc/f951 derio.f90
>  MAIN__
> Execution times (seconds)
>  parser                :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (50%) wall
>     61 kB (11%) ggc
>  TOTAL                 :   0.01             0.00             0.02
>    551 kB
> Extra diagnostic checks enabled; compiler may run slowly.
> Configure with --disable-checking to disable checks.
> schluter@pcl247d:~/src/tests>
> 
> This is because we don't look through the elements of the type to determine if
> it ultimately contains PRIVATE components, but only look at the first level.
> Your patch is ok to fix the PR, but I'd prefer if this issue were fixed at the
> same time.

Here's an improved patch (+ improved testcase) that recursively
goes through all components of derived type.  Bubblestrapped &
reg.-tested on 4.0 & mainline, Linux/x86.  Please commit if OK.


2005-09-22  Erik Edelmann  <erik.edelmann@iki.fi>

        PR fortran/23843
        * resolve.c (derived_inaccessible): New function.
        (resolve_transfer): Use it to check for private
        components.


2005-09-22  Erik Edelmann  <erik.edelmann@iki.fi>

        PR fortran/23843
        * gfortran.dg/der_io_2.f90: New test.



        Erik

Index: gcc/fortran/resolve.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.54
diff -u -p -r1.54 resolve.c
--- gcc/fortran/resolve.c	18 Sep 2005 05:50:01 -0000	1.54
+++ gcc/fortran/resolve.c	22 Sep 2005 20:39:58 -0000
@@ -2518,6 +2518,29 @@ derived_pointer (gfc_symbol * sym)
 }
 
 
+/* Given a pointer to a symbol that is a derived type, see if it's
+   inaccessible, i.e. if it's defined in another module and the components are
+   PRIVATE.  The search is recursive if necessary.  Returns zero if no
+   inaccessible components are found, nonzero otherwise.  */
+
+static int
+derived_inaccessible (gfc_symbol *sym)
+{
+  gfc_component *c;
+
+  if (sym->attr.use_assoc && sym->component_access == ACCESS_PRIVATE)
+    return 1;
+
+  for (c = sym->components; c; c = c->next)
+    {
+        if (c->ts.type == BT_DERIVED && derived_inaccessible (c->ts.derived))
+          return 1;
+    }
+
+  return 0;
+}
+
+
 /* Resolve the argument of a deallocate expression.  The expression must be
    a pointer or a full array.  */
 
@@ -3184,7 +3207,8 @@ resolve_select (gfc_code * code)
 
 /* Resolve a transfer statement. This is making sure that:
    -- a derived type being transferred has only non-pointer components
-   -- a derived type being transferred doesn't have private components
+   -- a derived type being transferred doesn't have private components, unless 
+      it's being transferred from the module where the type was defined
    -- we're not trying to transfer a whole assumed size array.  */
 
 static void
@@ -3219,7 +3243,7 @@ resolve_transfer (gfc_code * code)
 	  return;
 	}
 
-      if (ts->derived->component_access == ACCESS_PRIVATE)
+      if (derived_inaccessible (ts->derived))
 	{
 	  gfc_error ("Data transfer element at %L cannot have "
 		     "PRIVATE components",&code->loc);

! { dg-do compile }
! PR 23843
! IO of derived types with private components is allowed in the module itself,
! but not elsewhere
module gfortran2
    type :: tp1
        private
        integer :: i
    end type tp1

    type :: tp1b
        integer :: i
    end type tp1b

    type :: tp2
        real :: a
        type(tp1) :: t
    end type tp2
    
contains
    
    subroutine test()
        type(tp1) :: x
        type(tp2) :: y

        write (*, *) x
        write (*, *) y
    end subroutine test

end module gfortran2

program prog

    use gfortran2

    implicit none
    type :: tp3
        type(tp2) :: t
    end type tp3
    type :: tp3b
        type(tp1b) :: t
    end type tp3b

    type(tp1) :: x
    type(tp2) :: y
    type(tp3) :: z
    type(tp3b) :: zb

    write (*, *) x   ! { dg-error "PRIVATE components" }
    write (*, *) y   ! { dg-error "PRIVATE components" }
    write (*, *) z   ! { dg-error "PRIVATE components" }
    write (*, *) zb
end program prog


----- End forwarded message -----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]