From patchwork Fri Jun 7 14:03:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 249731 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 122B02C008E for ; Sat, 8 Jun 2013 00:04:11 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=OxomM1Ev47bsU8XlvMjjM4WnU0Ha6RKFn01lM8q7gseZP4 3w1/aQ+MHCJQboO58k3VW4qFIbQPyGg6Fged2mr5My7AX5BqebHsGHWcPlyV+y/+ 0SeQbtixkFOXUof7tPJpnqMaAnu8265YGX4IcJO8AyCFuNS+JhZFuz1D7rSQk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=7sH+ZFrq3SAxUjEN3D/HCrlzANo=; b=lct7xShbxtAdqQnc8VJS QOAPD8uMooIwZoILB4Za80bPzBxyBgK+/4OdcS51oA04nm/wTP+ziBY064R+e41l YfXE88ykvEqCnJt/cpaAGr3A/v+oEH7hdjMBPnfjTyWZrckD9kev02Q/heKH2/vG 03EYpxyT/KBUD/2HsXkt6Lw= Received: (qmail 14902 invoked by alias); 7 Jun 2013 14:03:59 -0000 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 Received: (qmail 14875 invoked by uid 89); 7 Jun 2013 14:03:58 -0000 X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 07 Jun 2013 14:03:57 +0000 Received: from archimedes.net-b.de (port-92-195-31-211.dynamic.qsc.de [92.195.31.211]) by mx01.qsc.de (Postfix) with ESMTP id B83DE3D3B4; Fri, 7 Jun 2013 16:03:53 +0200 (CEST) Message-ID: <51B1E848.1040302@net-b.de> Date: Fri, 07 Jun 2013 16:03:52 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR57549 - fix type-spec handling with array constructors X-Virus-Found: No Unreviewed patches: * http://gcc.gnu.org/ml/fortran/2013-06/msg00027.html * http://gcc.gnu.org/ml/fortran/2013-06/msg00048.html * * * As with ALLOCATE (type-spec :: ...), also array constructors take as type-spec a type name ("integer, my_dt, etc.) without an extra TYPE(). Thus, instead of using the decl.c var decl function, we use the same as for allocate. Build and regtested on x86-64-gnu-linux. OK for the trunk? From the standard: The Fortran 2008 standard has: R469 ac-spec is type-spec :: or [type-spec ::] ac-value-list R402 type-spec is intrinsic-type-spec or derived-type-spec R453 derived-type-spec is type-name [ ( type-param-spec-list ) ] Tobias 2013-06-07 Tobias Burnus PR fortran/57549 * array.c (gfc_match_array_constructor): Call gfc_match_type_spec instead of gfc_match_decl_type_spec. * match.c (gfc_match_type_spec): Renamed from match_type_spec. (gfc_match_type_is, gfc_match_allocate): Update call. * match.h (gfc_match_type_spec): Add prototype. 2013-06-07 Tobias Burnus PR fortran/57549 * gfortran.dg/array_constructor_48.f90: New. * gfortran.dg/array_constructor_type_14.f03: Correct test case. * gfortran.dg/array_constructor_type_15.f03: Ditto. diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index c2ac1ec..c6b8eb9 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1073,7 +1073,7 @@ gfc_match_array_constructor (gfc_expr **result) /* Try to match an optional "type-spec ::" */ gfc_clear_ts (&ts); gfc_new_undo_checkpoint (changed_syms); - if (gfc_match_decl_type_spec (&ts, 0) == MATCH_YES) + if (gfc_match_type_spec (&ts) == MATCH_YES) { seen_ts = (gfc_match (" ::") == MATCH_YES); diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index b44d815..2533584 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -1937,8 +1937,8 @@ match_derived_type_spec (gfc_typespec *ts) the implicit_flag is not needed, so it was removed. Derived types are identified by their name alone. */ -static match -match_type_spec (gfc_typespec *ts) +match +gfc_match_type_spec (gfc_typespec *ts) { match m; locus old_locus; @@ -3426,7 +3426,7 @@ gfc_match_allocate (void) /* Match an optional type-spec. */ old_locus = gfc_current_locus; - m = match_type_spec (&ts); + m = gfc_match_type_spec (&ts); if (m == MATCH_ERROR) goto cleanup; else if (m == MATCH_NO) @@ -5502,7 +5502,7 @@ gfc_match_type_is (void) c = gfc_get_case (); c->where = gfc_current_locus; - if (match_type_spec (&c->ts) == MATCH_ERROR) + if (gfc_match_type_spec (&c->ts) == MATCH_ERROR) goto cleanup; if (gfc_match_char (')') != MATCH_YES) diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h index ac8b9f8..1a701f0 100644 --- a/gcc/fortran/match.h +++ b/gcc/fortran/match.h @@ -59,6 +59,8 @@ match gfc_match_char (char); match gfc_match (const char *, ...); match gfc_match_iterator (gfc_iterator *, int); match gfc_match_parens (void); +match gfc_match_type_spec (gfc_typespec *); + /* Statement matchers. */ match gfc_match_program (void); --- /dev/null 2013-06-07 09:13:23.024185858 +0200 +++ gcc/gcc/testsuite/gfortran.dg/array_constructor_48.f90 2013-06-07 15:52:28.578691018 +0200 @@ -0,0 +1,17 @@ +! { dg-do compile } +! +! PR fortran/57549 +! +! Contributed by Vladimir Fuka +! + type t + end type + type(t),allocatable :: a(:) + a = [t::t()] + print *, [ integer :: ] +end + +subroutine invalid() + print *, [ type(integer) :: ] ! { dg-error "Syntax error in array constructor" } + print *, [ type(tt) :: ] ! { dg-error "Syntax error in array constructor" } +end subroutine invalid diff --git a/gcc/testsuite/gfortran.dg/array_constructor_type_14.f03 b/gcc/testsuite/gfortran.dg/array_constructor_type_14.f03 index 04ac728..0e24334 100644 --- a/gcc/testsuite/gfortran.dg/array_constructor_type_14.f03 +++ b/gcc/testsuite/gfortran.dg/array_constructor_type_14.f03 @@ -16,7 +16,7 @@ PROGRAM test TYPE(foo), DIMENSION(2) :: arr - arr = (/ TYPE(foo) :: x, foo(0, 1.) /) + arr = (/ foo :: x, foo(0, 1.) /) IF (arr(1)%i /= 42 .OR. arr(1)%x /= 42. .OR. & arr(2)%i /= 0 .OR. arr(2)%x /= 1.) THEN CALL abort() diff --git a/gcc/testsuite/gfortran.dg/array_constructor_type_15.f03 b/gcc/testsuite/gfortran.dg/array_constructor_type_15.f03 index 2073698..a946555 100644 --- a/gcc/testsuite/gfortran.dg/array_constructor_type_15.f03 +++ b/gcc/testsuite/gfortran.dg/array_constructor_type_15.f03 @@ -18,5 +18,5 @@ PROGRAM test TYPE(foo), PARAMETER :: x = foo(42, 42.) - WRITE (*,*) (/ TYPE(foo) :: x, foo(0, 1.), bar(.TRUE.) /) ! { dg-error "convert TYPE" } + WRITE (*,*) (/ foo :: x, foo(0, 1.), bar(.TRUE.) /) ! { dg-error "convert TYPE" } END PROGRAM test