User account creation filtered due to spam.

Bug 46371 - [Coarray] [OOP] SELECT TYPE: scalar coarray variable is rejected
Summary: [Coarray] [OOP] SELECT TYPE: scalar coarray variable is rejected
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-11-08 15:05 UTC by Tobias Burnus
Modified: 2013-12-17 09:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-12-17 00:00:00


Attachments
Draft patch (450 bytes, patch)
2010-12-13 22:13 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-11-08 15:05:06 UTC
Example has been taken from the interpretation request at http://j3-fortran.org/doc/meeting/193/10-209r1.txt ; the IR does not contain a suggested edits.

The following program, which needs two images at run time is regarded as valid (with select 1 commented out) - if the ALLOCATE is not commented out. (The ALLOCATE statement is commented-out because of PR 46370.)


Using gfortran -fcorarray=single, it fails with:

    select type(o_foo)                ! 3 VALID
                                               1
Error: Selector in SELECT TYPE at (1) is not a named variable; use associate-name=>


module m
  type :: foo
    integer :: i = 0
  end type
end module m
program p
  use m
  type(foo), allocatable :: o_foo[:]
  integer :: j

!  allocate(foo :: o_foo[*])
  if (this_image() == 1) then

!    select type(a => o_foo[2])        ! 1 INVALID
!      type is(foo)
!      j = a%i
!    end select

!    select type(a => o_foo)           ! 2 VALID
!      type is(foo)
!      j = a[2]%i
!   end select

    select type(o_foo)                ! 3 VALID
      type is(foo)
      j = o_foo[2]%i
    end select

  end if
end program p
Comment 1 Tobias Burnus 2010-12-13 17:32:22 UTC
(In reply to comment #0)
>   type(foo), allocatable :: o_foo[:]

That should be "CLASS(foo)" - sorry for the typo.


TODO:

a) There is a gfc_is_coindexed() check missing for ASSOCIATE and SELECT TYPE, cf. link and "1 INVALID" part of comment 0

b) "2 VALID" and "3 VALID" do not work:

      j = a[1]%i
           1
Error: Coarray designator at (1) but '__tmp_type_foo' is not a coarray

I think at least "attr.codimension" needs to be added during match time - resolve time it too late. The variable is generated at select_type_set_tmp. I tried the following (cf. select_type_set_tmp part of the patch), which does not seem to be sufficient - though it is enough to trigger the issue in resolve.c (cf. resolve.c part of the patch).


diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 44da1bb..6521e79 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -4531,6 +4531,8 @@ select_type_set_tmp (gfc_typespec *ts)
                              &tmp->n.sym->as, false);
       tmp->n.sym->attr.class_ok = 1;
     }
+  if (select_type_stack->selector->attr.codimension)
+    tmp->n.sym->attr.codimension = 1;
   tmp->n.sym->attr.select_type_temporary = 1;

   /* Add an association for it, so the rest of the parser knows it is
@@ -4591,8 +4593,14 @@ gfc_match_select_type (void)
   if (m != MATCH_YES)
     goto cleanup;

-  /* Check for F03:C811.  */
-  if (!expr2 && (expr1->expr_type != EXPR_VARIABLE || expr1->ref != NULL))
+  /* Check for F03:C811. Special case: scalar coarray.  */
+  if (!expr2 && (expr1->expr_type != EXPR_VARIABLE
+                || (expr1->ref != NULL
+                    && (expr1->ref->next != NULL
+                        || expr1->ref->type != REF_ARRAY
+                        || expr1->ref->u.ar.type != AR_FULL
+                        || expr1->ref->u.ar.dimen != 0
+                        || expr1->ref->u.ar.codimen != 0))))
     {
       gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
                 "use associate-name=>");
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a27fe2d..5102aea 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12121,6 +12121,7 @@ resolve_symbol (gfc_symbol *sym)
   if (((sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.coarray_comp)
        || sym->attr.codimension)
       && !(sym->attr.allocatable || sym->attr.dummy || sym->attr.save
+          || sym->attr.select_type_temporary
           || sym->ns->proc_name->attr.flavor == FL_MODULE
           || sym->ns->proc_name->attr.is_main_program
           || sym->attr.function || sym->attr.result || sym->attr.use_assoc))
Comment 2 Tobias Burnus 2010-12-13 22:13:53 UTC
Created attachment 22747 [details]
Draft patch

Draft patch fixes "2 VALID" and "3 VALID" - however, I see failures for the following examples. Additionally, the gfc_is_coindexed check is still missing.

Additional examples:

  class(foo), allocatable :: o_foo(:)
  class(foo), allocatable :: o_bar(:)[:]

! Expected: "o => o_foo" gives an error because of missing "(...)"
! However, it is accepted by NAG and Intel; the gfortran message is strange
!    select type(o => o_foo)                ! 4 INVALID
      type is(foo) ! "must have a deferred shape"
      j = o(1)%i
    end select

   select type(o => o_bar)                ! 5 VALID
     type is(foo)
     j = o(1)[1]%i ! "Unexpected coarray designator"
   end select

   select type(o => o_foo(1))  ! ICE segfault       
     type is(foo)              ! 6 VALID
     j = o%i
   end select
Comment 3 Tobias Burnus 2011-11-24 16:41:54 UTC
Polymorphic array example: Todo check for validity and fix.

program p
  use m
  class(foo), allocatable :: o_bar(:)[:]
  integer :: j

  allocate(foo :: o_bar(5)[*])

  select type(o_bar)
    type is(foo)
      j = o_bar(2)[1]%i
  end select

!! FIXME: "type if (foo)" fails with:
!! Associate-name '__tmp_type_foo' at (1) is used as array
  select type(a => o_bar)
    type is (foo)
      j = a(1)[1]%i
  end select

!! FIXME: "a" should be a rank 0 not a rank 1
!!        array
  select type(a => o_bar(1))
    type is (foo)
      j = a[2]%i
  end select
end program p
Comment 4 Dominique d'Humieres 2013-12-17 09:16:59 UTC
Still present at r206026. What happened to the patch?