From patchwork Sat Aug 27 00:34:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 111845 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 B6CC9B702E for ; Sat, 27 Aug 2011 10:34:46 +1000 (EST) Received: (qmail 31210 invoked by alias); 27 Aug 2011 00:34:39 -0000 Received: (qmail 31069 invoked by uid 22791); 27 Aug 2011 00:34:38 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 27 Aug 2011 00:34:25 +0000 Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.5/8.14.5) with ESMTP id p7R0YOKt055167; Fri, 26 Aug 2011 17:34:24 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.5/8.14.5/Submit) id p7R0YORB055166; Fri, 26 Aug 2011 17:34:24 -0700 (PDT) (envelope-from sgk) Date: Fri, 26 Aug 2011 17:34:24 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH, PR fortran/45170] -- properly translates substring reference Message-ID: <20110827003424.GA55073@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.2.3i 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 attached patch allows gfortran to compile the attached testcase. The resulting executable runs as expected. Short story: character(len=20) :: string = 'some text here' character(len=:), allocatable :: s n = 5 allocate(s, source=string(:n)) The length of s is determined from the expression in the source= argument. If this expression is a lonely substring reference as in the above, then gfortran does set the correct length. This patch fixes this. OK for trunk? 2011-08-26 Steven G. Kargl PR fortran/45170 * trans-stmt.c (gfc_trans_allocate): Evaluate the substring. 2011-08-26 Steven G. Kargl PR fortran/45170 * gfortran.dg/allocate_with_source_2.f90: New test Index: trans-stmt.c =================================================================== --- trans-stmt.c (revision 177772) +++ trans-stmt.c (working copy) @@ -4783,6 +4783,10 @@ gfc_trans_allocate (gfc_code * code) || code->expr3->expr_type == EXPR_CONSTANT) { gfc_conv_expr (&se_sz, code->expr3); + gfc_add_block_to_block (&se.pre, &se_sz.pre); + se_sz.string_length + = gfc_evaluate_now (se_sz.string_length, &se.pre); + gfc_add_block_to_block (&se.pre, &se_sz.post); memsz = se_sz.string_length; } else if (code->expr3->mold