From patchwork Sat Dec 11 20:28:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 75209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D7B3FB6F11 for ; Sun, 12 Dec 2010 07:28:30 +1100 (EST) Received: (qmail 25521 invoked by alias); 11 Dec 2010 20:28:26 -0000 Received: (qmail 25500 invoked by uid 22791); 11 Dec 2010 20:28:24 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 11 Dec 2010 20:28:17 +0000 Received: from [192.168.178.22] (port-92-204-53-80.dynamic.qsc.de [92.204.53.80]) by mx01.qsc.de (Postfix) with ESMTP id 1CF0D3D41A; Sat, 11 Dec 2010 21:28:13 +0100 (CET) Message-ID: <4D03DEDD.8080906@net-b.de> Date: Sat, 11 Dec 2010 21:28:13 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.12) Gecko/20101026 SUSE/3.1.6 Thunderbird/3.1.6 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Fortran, Patch] PR 46370: Error allocating CLASS coarrays Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The check for C617 was too strict as the following was rejected, ALLOCATE(polym_type[*]), but there is no subobject of the coindexed object. Additionally, the array ref matcher did not know that there is a coarray as the CLASS contained hid the issue. The test case for C1229 is superfluous but I wanted to make sure that part is correctly handled (it is). R611 data-ref is part-ref [ % part-ref ] ... C617 (R611) Except as an actual argument to an intrinsic inquiry function or as the designator in a type parameter inquiry, a data-ref shall not be a polymorphic subobject of a coindexed object and shall not be a coindexed object that has a polymorphic allocatable subcomponent. R1221 procedure-designator is ...or data-ref % binding-name C1229 (R1221) A data-ref shall not be a polymorphic subobject of a coindexed object. Build and currently regtesting on x86-64-linux. (The coarray* tests pass thus I do not expect surprises.) OK for the trunk? Tobias 2010-12-11 Tobias Burnus PR fortran/46370 * primary.c (gfc_match_varspec): Pass information about codimension to gfc_match_array_ref also for BT_CLASS. * resolve.c (resolve_procedure): Correct check for C612. 2010-12-11 Tobias Burnus PR fortran/46370 * gfortran.dg/coarray_14.f90: New. diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 9632d1c..7c20da6 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1783,7 +1783,11 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, tail->type = REF_ARRAY; m = gfc_match_array_ref (&tail->u.ar, equiv_flag ? NULL : sym->as, - equiv_flag, sym->as ? sym->as->corank : 0); + equiv_flag, + sym->ts.type == BT_CLASS + ? CLASS_DATA (sym)->as + ? CLASS_DATA (sym)->as->corank : 0 + : sym->as ? sym->as->corank : 0); if (m != MATCH_YES) return m; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 9d8ee23..ab49e93 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5027,13 +5027,6 @@ resolve_procedure: { gfc_ref *ref, *ref2 = NULL; - if (e->ts.type == BT_CLASS) - { - gfc_error ("Polymorphic subobject of coindexed object at %L", - &e->where); - t = FAILURE; - } - for (ref = e->ref; ref; ref = ref->next) { if (ref->type == REF_COMPONENT) @@ -5046,6 +5039,14 @@ resolve_procedure: if (ref->type == REF_COMPONENT) break; + /* Expression itself is not coindexed object. */ + if (ref && e->ts.type == BT_CLASS) + { + gfc_error ("Polymorphic subobject of coindexed object at %L", + &e->where); + t = FAILURE; + } + /* Expression itself is coindexed object. */ if (ref == NULL) { diff --git a/gcc/testsuite/gfortran.dg/coarray_14.f90 b/gcc/testsuite/gfortran.dg/coarray_14.f90 new file mode 100644 index 0000000..9230ad4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_14.f90 @@ -0,0 +1,55 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/46370 +! +! Coarray checks +! + +! Check for C1229: "A data-ref shall not be a polymorphic subobject of a +! coindexed object." which applies to function and subroutine calls. +module m + implicit none + type t + contains + procedure, nopass :: sub=>sub + procedure, nopass :: func=>func + end type t + type t3 + type(t) :: nopoly + end type t3 + type t2 + class(t), allocatable :: poly + class(t3), allocatable :: poly2 + end type t2 +contains + subroutine sub() + end subroutine sub + function func() + integer :: func + end function func +end module m + +subroutine test(x) + use m + type(t2) :: x[*] + integer :: i + call x[1]%poly2%nopoly%sub() ! OK + i = x[1]%poly2%nopoly%func() ! OK + call x[1]%poly%sub() ! { dg-error "Polymorphic subobject of coindexed object" } + i = x[1]%poly%func() ! { dg-error "Polymorphic subobject of coindexed object" } +end subroutine test + + +! Check for C617: "... a data-ref shall not be a polymorphic subobject of a +! coindexed object or ..." +! Before, the second allocate statment was failing - though it is no subobject. +program myTest +type t +end type t +class(t), allocatable :: a[:] + allocate (t :: a) ! { dg-error "Coarray specification required in ALLOCATE statement" } +allocate (t :: a[*]) ! { dg-error "allocatable scalar coarrays are not yet supported" } +end program myTest + +! { dg-final { cleanup-modules "m" } }