From patchwork Sat Jan 22 10:18:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 79991 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 56184B713F for ; Sat, 22 Jan 2011 21:18:26 +1100 (EST) Received: (qmail 26835 invoked by alias); 22 Jan 2011 10:18:21 -0000 Received: (qmail 26779 invoked by uid 22791); 22 Jan 2011 10:18:20 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_TB X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 22 Jan 2011 10:18:06 +0000 Received: from [192.168.178.22] (port-92-204-33-159.dynamic.qsc.de [92.204.33.159]) by mx02.qsc.de (Postfix) with ESMTP id 8ACE61E12D; Sat, 22 Jan 2011 11:18:03 +0100 (CET) Message-ID: <4D3AAEDA.2010807@net-b.de> Date: Sat, 22 Jan 2011 11:18:02 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 47399 - fix half of the PR: ICE with PARAMETER TBP 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 fix for the ICE is simple: Just modifying the gcc_assert is enough. The patch below only fixes that part. OK for the trunk? * * * The accept invalid part of the PR is much harder. Seemingly someone could not correctly read when creating gfc_is_constant_expr as the function also allows specification expressions. Fortran 95 has two confusing close concepts, initialization expressions and constant expressions; both reduce to a constant at compile time - and I have not yet fully deciphered what their difference is. In Fortran 2003 both are combined to "initialization expressions" and Fortran 2008 renamed those to "constant expressions". Thus, changing gfc_is_constant_expr should be done, but the problem is that some of the callers indeed want to check for specification expressions (or something related like restricted expressions or ...). Thus, one needs to go through F95/F2003/F2008 and check the concepts and then check all 56 callers of gfc_is_constant_expr to see which check they actually want... Tobias 2011-01-22 Tobias Burnus PR fortran/47399 * primary.c (gfc_match_varspec): Relax gcc_assert to allow for PARAMETER TBP. 2011-01-22 Tobias Burnus PR fortran/47399 * gfortran.dg/typebound_proc_19.f90: New. diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index ed85398..360176e 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1843,7 +1843,10 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, return MATCH_ERROR; gcc_assert (!tail || !tail->next); - gcc_assert (primary->expr_type == EXPR_VARIABLE); + gcc_assert (primary->expr_type == EXPR_VARIABLE + || (primary->expr_type == EXPR_STRUCTURE + && primary->symtree && primary->symtree->n.sym + && primary->symtree->n.sym->attr.flavor)); if (tbp->n.tb->is_generic) tbp_sym = NULL; diff --git a/gcc/testsuite/gfortran.dg/typebound_proc_19.f90 b/gcc/testsuite/gfortran.dg/typebound_proc_19.f90 new file mode 100644 index 0000000..be15bf0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/typebound_proc_19.f90 @@ -0,0 +1,43 @@ +! { dg-do compile } +! +! PR fortran/47399 +! +! Contributed by Wolfgang Kilian. +! + +module mytypes + implicit none + private + public :: mytype, get_i + + integer, save :: i_priv = 13 + type :: mytype + integer :: dummy + contains + procedure, nopass :: i => get_i + end type mytype + contains + pure function get_i () result (i) + integer :: i + i = i_priv + end function get_i +end module mytypes + +subroutine test() + use mytypes + implicit none + + type(mytype) :: a + type(mytype), parameter :: a_const = mytype (0) + integer, dimension (get_i()) :: x ! #1 + integer, dimension (a%i()) :: y ! #2 + integer, dimension (a_const%i()) :: z ! #3 + + if (size (x) /= 13 .or. size(y) /= 13 .or. size(z) /= 13) call abort() +! print *, size (x), size(y), size(z) +end subroutine test + +call test() +end + +! { dg-final { cleanup-modules "mytypes" } }