Bug 41978 - [F03] ICE in gfc_conv_expr_descriptor for array PPC assignment
Summary: [F03] ICE in gfc_conv_expr_descriptor for array PPC assignment
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-07 17:58 UTC by Daniel Kraft
Modified: 2009-11-11 22:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-11-11 21:02:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Kraft 2009-11-07 17:58:39 UTC
The following code ICEs:

MODULE m
  IMPLICIT NONE

  TYPE t
    PROCEDURE(myproc), POINTER, PASS :: myproc
  END TYPE t

CONTAINS

  INTEGER FUNCTION myproc (me)
    CLASS(t), INTENT(IN) :: me
    myproc = 42
  END FUNCTION myproc

END MODULE m

PROGRAM main
  USE m
  IMPLICIT NONE

  TYPE(t) :: arr(2)
  arr%myproc => myproc
END PROGRAM main

Removing the line at the bottom assigning myproc to arr%myproc makes it compile.  The relevant error is:

[/tmp]# gfortran-dev reduced.f90 
reduced.f90: In function 'MAIN__':
reduced.f90:17:0: internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:5019
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 janus 2009-11-11 20:38:45 UTC
Replacing the PPC assignment by a plain pointer component assignment

  IMPLICIT NONE
  TYPE t
    integer, pointer :: p
  END TYPE t
  integer :: i
  TYPE(t) :: arr(2)
  arr%p => i
END

is being rejected with:

  arr%p => i
  1
Error: Component to the right of a part reference with nonzero rank must not have the POINTER attribute at (1)

This is C614 in the F03 standard:

C614 (R612) There shall not be more than one part-ref with nonzero rank. A part-name to the right of a part-ref with nonzero rank shall not have the ALLOCATABLE or POINTER attribute.

I'm not 100% sure, but I think this also applies to PPCs.
Comment 2 janus 2009-11-11 21:02:50 UTC
(In reply to comment #1)
> I'm not 100% sure, but I think this also applies to PPCs.

If this is correct, then the fix for this PR is as simple as

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 153965)
+++ gcc/fortran/resolve.c       (working copy)
@@ -4272,7 +4272,8 @@ resolve_ref (gfc_expr *expr)
        case REF_COMPONENT:
          if (current_part_dimension || seen_part_dimension)
            {
-             if (ref->u.c.component->attr.pointer)
+             if (ref->u.c.component->attr.pointer
+                 || ref->u.c.component->attr.proc_pointer)
                {
                  gfc_error ("Component to the right of a part reference "
                             "with nonzero rank must not have the POINTER "

Daniel, what do you think?
Comment 3 Daniel Kraft 2009-11-11 21:08:42 UTC
I've not checked the standard about this, but seems fine to me.  I also give you an ok for that patch (maybe with a test-case) if you want to submit/commit.
Comment 4 janus 2009-11-11 22:37:50 UTC
Subject: Bug 41978

Author: janus
Date: Wed Nov 11 22:37:31 2009
New Revision: 154107

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

	PR fortran/41978
	* resolve.c (resolve_ref): Take care of procedure pointer component
	references.


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

	PR fortran/41978
	* gfortran.dg/proc_ptr_comp_22.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_22.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 janus 2009-11-11 22:38:34 UTC
Fixed with r154107. Closing.