From patchwork Tue Sep 11 05:54:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 183006 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 9729B2C0088 for ; Tue, 11 Sep 2012 15:54:49 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347947691; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=/KQnDYO AKKCCmzZZN5OrcoRi0yQ=; b=g2S8XVUfR6LhhThguc5sOJBrPnEd2A2p0Lw1xKS j6mKLROtAqfUDNn/nSBQKLc7So8wbpvVgfF/VewHH50VbQlKKYymwsI2n+4qGcLP l/7xfCtrdpTxDNjtIGwu6XROLvHQReLVdfmcxPYIS6DPvE50hJCC3EL+NMK63LrW IZj0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Gy2q5/21kQHx/QZ2v7aoE8oCe8+vmr5TTBsj3PAqb/Ae1YsA1tPzvfDkvGbC/n sL+6BJeltasdzIeYOOBPqav40uvi7C05M7jTUlD7g930vQBpwQOXuqWow4p8pUHu 3WGKEL+RPBuzyPBa4cYCBfdCLQrKAV+8sAGedQxPCfMXk=; Received: (qmail 5274 invoked by alias); 11 Sep 2012 05:54:41 -0000 Received: (qmail 5257 invoked by uid 22791); 11 Sep 2012 05:54:39 -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 mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Sep 2012 05:54:25 +0000 Received: from [192.168.178.22] (port-92-204-67-8.dynamic.qsc.de [92.204.67.8]) by mx02.qsc.de (Postfix) with ESMTP id 9CB13285A4; Tue, 11 Sep 2012 07:54:23 +0200 (CEST) Message-ID: <504ED20F.30209@net-b.de> Date: Tue, 11 Sep 2012 07:54:23 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Fortran, Patch] PR 54225 - Fix ice-on-invalid-code with "*" in array refs 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 This patch fixes a GCC 4.7/4.8 regression for invalid code. Build and regtested on x86-64-linux. OK for the trunk and 4.7? Tobias 2012-09-11 Tobias Burnus PR fortran/54225 * array.c (match_subscript, gfc_match_array_ref): Fix diagnostic of coarray's '*'. 2012-09-11 Tobias Burnus PR fortran/54225 * gfortran.dg/coarray_10.f90: Update dg-error. * gfortran.dg/coarray_28.f90: New. * gfortran.dg/array_section_3.f90: New. diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 07fecd8..44ec72e 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -91,9 +91,7 @@ match_subscript (gfc_array_ref *ar, int init, bool match_star) else if (!star) m = gfc_match_expr (&ar->start[i]); - if (m == MATCH_NO && gfc_match_char ('*') == MATCH_YES) - return MATCH_NO; - else if (m == MATCH_NO) + if (m == MATCH_NO) gfc_error ("Expected array subscript at %C"); if (m != MATCH_YES) return MATCH_ERROR; @@ -224,7 +222,7 @@ coarray: for (ar->codimen = 0; ar->codimen + ar->dimen < GFC_MAX_DIMENSIONS; ar->codimen++) { - m = match_subscript (ar, init, ar->codimen == (corank - 1)); + m = match_subscript (ar, init, true); if (m == MATCH_ERROR) return MATCH_ERROR; @@ -255,6 +253,13 @@ coarray: gfc_error ("Invalid form of coarray reference at %C"); return MATCH_ERROR; } + else if (ar->dimen_type[ar->codimen + ar->dimen] == DIMEN_STAR) + { + gfc_error ("Unexpected '*' for codimension %d of %d at %C", + ar->codimen + 1, corank); + return MATCH_ERROR; + } + if (ar->codimen >= corank) { gfc_error ("Invalid codimension %d at %C, only %d codimensions exist", diff --git a/gcc/testsuite/gfortran.dg/coarray_10.f90 b/gcc/testsuite/gfortran.dg/coarray_10.f90 index 99f5782..78abb5a 100644 --- a/gcc/testsuite/gfortran.dg/coarray_10.f90 +++ b/gcc/testsuite/gfortran.dg/coarray_10.f90 @@ -30,12 +30,12 @@ end subroutine this_image_check subroutine rank_mismatch() implicit none integer,allocatable :: A(:)[:,:,:,:] - allocate(A(1)[1,1,1:*]) ! { dg-error "Unexpected ... for codimension" } + allocate(A(1)[1,1,1:*]) ! { dg-error "Too few codimensions" } allocate(A(1)[1,1,1,1,1,*]) ! { dg-error "Invalid codimension 5" } allocate(A(1)[1,1,1,*]) allocate(A(1)[1,1]) ! { dg-error "Too few codimensions" } allocate(A(1)[1,*]) ! { dg-error "Too few codimensions" } - allocate(A(1)[1,1:*]) ! { dg-error "Unexpected ... for codimension" } + allocate(A(1)[1,1:*]) ! { dg-error "Too few codimensions" } A(1)[1,1,1] = 1 ! { dg-error "Too few codimensions" } A(1)[1,1,1,1,1,1] = 1 ! { dg-error "Invalid codimension 5" } @@ -48,5 +48,5 @@ end subroutine rank_mismatch subroutine rank_mismatch2() implicit none integer, allocatable:: A(:)[:,:,:] - allocate(A(1)[7:8,4:*]) ! { dg-error "Unexpected .*. for codimension 2 of 3" } + allocate(A(1)[7:8,4:*]) ! { dg-error "Too few codimensions" } end subroutine rank_mismatch2 --- /dev/null 2012-09-11 07:30:33.339725680 +0200 +++ gcc/gcc/testsuite/gfortran.dg/array_section_3.f90 2012-09-10 18:29:37.000000000 +0200 @@ -0,0 +1,12 @@ +! { dg-do compile } +! +! PR fortran/54225 +! +! Contributed by robb wu +! +program test + implicit none + real :: A(2,3) + + print *, A(1, *) ! { dg-error 'Expected array subscript' } +end program --- /dev/null 2012-09-11 07:30:33.339725680 +0200 +++ gcc/gcc/testsuite/gfortran.dg/coarray_28.f90 2012-09-11 07:51:24.000000000 +0200 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/54225 +! + +integer, allocatable :: a[:,:] + +allocate (a[*,4]) ! { dg-error "Unexpected '.' for codimension 1 of 2" } +end