Bug 47768 - ICE: printing a derived-type variable with proc-pointer components
ICE: printing a derived-type variable with proc-pointer components
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.6.0
: P3 normal
: ---
Assigned To: janus
: ice-on-invalid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-02-16 17:51 UTC by janus
Modified: 2011-03-11 14:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-02-16 22:37:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2011-02-16 17:51:48 UTC
Test case:


type :: t
  integer :: i = 3
  !type(t), pointer :: p     ! rejected with this line
  procedure(type(t)), pointer, nopass :: ppc
end type 

type(t) :: x

print *,x
end



This segfaults with 4.5 and 4.6. Adding a data pointer component leads to rejection:

print *,x
         1
Error: Data transfer element at (1) cannot have POINTER components

So I'm guessing the version with proc-pointer is also illegal (haven't checked the standard).

Changing the proc-pointer to

  procedure(integer), pointer, nopass :: ppc

makes it compile and gives the output:

           3           0
Comment 1 janus 2011-02-16 18:16:13 UTC
(In reply to comment #0)
> Adding a data pointer component leads to rejection:
> 
> print *,x
>          1
> Error: Data transfer element at (1) cannot have POINTER components
> 
> So I'm guessing the version with proc-pointer is also illegal (haven't checked
> the standard).

I have the feeling we reject too much here. F08 says in chapter 9.6.3:

"If an output item is a pointer, it shall be associated with a target and data are transferred from the target to the file."

I think this is the same in F03 and F95.
So, it seems like pointers are ok (but should be associated), unless I'm missing something. Procedure pointers, however, are definitely illegal:

C935 (R917) An expression that is an output-item shall not have a value that is a procedure pointer.
Comment 2 janus 2011-02-16 22:22:03 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > Adding a data pointer component leads to rejection:
> > 
> > print *,x
> >          1
> > Error: Data transfer element at (1) cannot have POINTER components
> > 
> > So I'm guessing the version with proc-pointer is also illegal (haven't checked
> > the standard).
> 
> I have the feeling we reject too much here. F08 says in chapter 9.6.3:
> 
> "If an output item is a pointer, it shall be associated with a target and data
> are transferred from the target to the file."
> 
> I think this is the same in F03 and F95.
> So, it seems like pointers are ok (but should be associated), unless I'm
> missing something.

I indeed missed something. Further down in 9.6.3 one finds:

"If a derived-type list item is not processed by a defined input/output procedure and is not treated as a list of its individual components, all the subcomponents of that list item shall be accessible in the scoping unit containing the input/output statement and shall not be pointers or allocatable."

So, pointer components are indeed forbidden. All that's left to do here is to also reject procedure pointers and procedure pointer components.
Comment 3 janus 2011-02-16 22:37:22 UTC
(In reply to comment #2)
> So, pointer components are indeed forbidden. All that's left to do here is to
> also reject procedure pointers and procedure pointer components.

Here is a patch for rejecting PPCs:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 170222)
+++ gcc/fortran/resolve.c       (working copy)
@@ -8091,6 +8091,13 @@ resolve_transfer (gfc_code *code)
          return;
        }
 
+      if (ts->u.derived->attr.proc_pointer_comp)
+       {
+         gfc_error ("Data transfer element at %L cannot have "
+                    "procedure pointer components", &code->loc);
+         return;
+       }
+
       if (ts->u.derived->attr.alloc_comp)
        {
          gfc_error ("Data transfer element at %L cannot have "



Procedure pointers are already rejected with:

print *,pp
          1
Error: Function 'pp' requires an argument list at (1)
Comment 4 janus 2011-02-17 10:35:04 UTC
(In reply to comment #3)
> Here is a patch for rejecting PPCs:

This patch regtests cleanly. Will commit as obvious.
Comment 5 janus 2011-02-18 12:24:01 UTC
Author: janus
Date: Fri Feb 18 12:23:56 2011
New Revision: 170271

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170271
Log:
2011-02-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47768
	* resolve.c (resolve_transfer): Reject variables with procedure pointer
	components.

2011-02-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47768
	* gfortran.dg/proc_ptr_comp_30.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_30.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 janus 2011-02-18 12:26:51 UTC
Fixed with r170271. Closing.
Comment 7 janus 2011-03-11 14:13:52 UTC
Author: janus
Date: Fri Mar 11 14:13:49 2011
New Revision: 170871

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170871
Log:
2011-03-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47768
	* module.c (ab_attribute,attr_bits): Add AB_PROC_POINTER_COMP.
	(mio_symbol_attribute): Handle attribute 'proc_pointer_comp'.

2011-03-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47768
	* gfortran.dg/proc_ptr_comp_31.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_31.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog