From patchwork Tue May 15 10:26:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 159287 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 AD1FAB6F86 for ; Tue, 15 May 2012 20:27:33 +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=1337682453; 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=oLsFwAZ nF/dM1KrzKoz2vT3owE0=; b=JF62pTKJ0Ths2vdcTIrjBJmy9CcyzCD5T7D8ota hSdH+Ock0rOV0ipAa9yDL48aRlRMdy3yX270W9/UMPdOA4gqzuL9c6I0cHGYmQKo xPsuF4Q84inzK+HrmLauCFRRo7rBECXmF4/vP0EeIDT6+jLXfgz0hzNX3Cckdc8I 3diw= 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=vPxrmstWf+YZMN0oyhv7yhGrsu8nXFnBYjn0VY+eI0FqqB0mh/scuz2sIVI6cm KgQBZWg/3UygYb0Gxa9RtVnMZtsjMHnpiWUdn6lgfeE23UvCyBmQ8aEx08zSF9TX 2V1JJ+lx00TahwgVohHQX2w7kEbBQbahHEDCqy96DU4DU=; Received: (qmail 13700 invoked by alias); 15 May 2012 10:27:22 -0000 Received: (qmail 13684 invoked by uid 22791); 15 May 2012 10:27:20 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SUBJ_OBFU_PUNCT_FEW, SUBJ_OBFU_PUNCT_MANY 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; Tue, 15 May 2012 10:27:06 +0000 Received: from [192.168.178.22] (port-92-204-48-84.dynamic.qsc.de [92.204.48.84]) by mx01.qsc.de (Postfix) with ESMTP id 347A53CFBA; Tue, 15 May 2012 12:26:59 +0200 (CEST) Message-ID: <4FB22F6F.8010000@net-b.de> Date: Tue, 15 May 2012 12:26:55 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR51055 - accept non-spec-expr "i" in allocate(character(len=i)::s) 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 A rather simple patch. Build and regtested on x86-64-linux. OK for the trunk? I think that is the last patch required for commonly used code. Remaining are issues with array constructors and concatenations - and, of course, deferred-length components. Tobias 2012-05-15 Tobias Burnus PR fortran/51055 PR fortran/45170 * match.c (gfc_match_allocate): Set length_from_typespec for characters. * resolve.c (resolve_charlen): If set, don't check whether the len is a specification expression. 2012-05-15 Tobias Burnus PR fortran/51055 PR fortran/45170 * gfortran.dg/allocate_with_typespec_6.f90: New. diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 3d11918..93d7fab 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -3466,6 +3466,9 @@ gfc_match_allocate (void) "type parameter", &old_locus); goto cleanup; } + + if (ts.type == BT_CHARACTER) + ts.u.cl->length_from_typespec = true; } else { diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 9814c14..6fd2d97 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -9945,12 +9945,24 @@ resolve_charlen (gfc_charlen *cl) cl->resolved = 1; - specification_expr = 1; - if (resolve_index_expr (cl->length) == FAILURE) + if (cl->length_from_typespec) { - specification_expr = 0; - return FAILURE; + if (gfc_resolve_expr (cl->length) == FAILURE) + return FAILURE; + + if (gfc_simplify_expr (cl->length, 0) == FAILURE) + return FAILURE; + } + else + { + specification_expr = 1; + + if (resolve_index_expr (cl->length) == FAILURE) + { + specification_expr = 0; + return FAILURE; + } } /* "If the character length parameter value evaluates to a negative --- /dev/null 2012-05-14 08:15:48.907781309 +0200 +++ gcc/gcc/testsuite/gfortran.dg/allocate_with_typespec_6.f90 2012-05-15 09:50:53.000000000 +0200 @@ -0,0 +1,17 @@ +! { dg-do compile } +! +! PR fortran/51055 +! PR fortran/45170 comment 14 +! +! Contributed by Juha Ruokolainen +! and Hans-Werner Boschmann +! +! gfortran was before checking whether the length +! was a specification expression. +! + +program a + character(len=:), allocatable :: s + integer :: i=10 + allocate(character(len=i)::s) +end program a