From patchwork Tue Jan 29 22:36:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 216678 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 7841C2C0096 for ; Wed, 30 Jan 2013 09:37:04 +1100 (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=1360103825; 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=zBb1uMw oLpLQYrVut5oerhT80LI=; b=dIvDhRzFkTqmF5sL6LSiRMjOuq0TVWQLbAIo4G/ lG83aQFhpwVcI9CYN0weHj9SCAxaye2k3hmLUUpfr2XJRiwA2oHVThb7hafqgLZs q/QhV02ZCJQwQ4QSgBqOjp01QKWMjtSqNXjg9bc4BcPkaYZQYqZVAtti4WDmOtGV VxXE= 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=DmTB0XL+V/iKzkGfzwrUxDeYMMxl1fjpZUJR2nipiWsuvbW2yEmI1xvC2pUaNh Nmvh1ac2mJoLJyqcQl57NQppoXy7tdD8LQvXOnIT4eoLEo8/mhmVTHfLodG2CXXQ S26lL6kqhPQu2+OKCeBRw+xEPQijTFvl7j4+gESGJWE/Y=; Received: (qmail 28489 invoked by alias); 29 Jan 2013 22:36:59 -0000 Received: (qmail 28323 invoked by uid 22791); 29 Jan 2013 22:36:58 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_NONE 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, 29 Jan 2013 22:36:52 +0000 Received: from archimedes.net-b.de (port-92-195-126-79.dynamic.qsc.de [92.195.126.79]) by mx01.qsc.de (Postfix) with ESMTP id D554C3CE70; Tue, 29 Jan 2013 23:36:50 +0100 (CET) Message-ID: <51084F02.6060903@net-b.de> Date: Tue, 29 Jan 2013 23:36:50 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR56138 - fix deferred-length character funcs w/o result variable 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 For allocatable string lengths (deferred length strings), the current code generates a local integer variable to which the the length is assigned. For some reason, that doesn't work for some functions which do not use a result variable - leading to failures as the pass-by-reference variable is not dereferenced. That's fixed by the attached patch. I have to admit that I do not understand why it works without the patch for the examples in gfortran.dg/allocatable_function_5.f90, where - for some tests - also no result variable is used. Build and regtested on x86-64-gnu-linux. OK for the trunk? Tobias 2012-01-29 Tobias Burnus PR fortran/56138 * trans-decl.c (gfc_trans_deferred_vars): Fix deferred-length results for functions without extra result variable. 2012-01-29 Tobias Burnus PR fortran/56138 * gfortran.dg/allocatable_function_6.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 1d0919d..7732440 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3775,7 +3775,7 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) null_pointer_node)); } - if ((sym->attr.dummy ||sym->attr.result) + if ((sym->attr.dummy || sym->attr.result || sym->result == sym) && sym->ts.type == BT_CHARACTER && sym->ts.deferred) { diff --git a/gcc/testsuite/gfortran.dg/allocatable_function_6.f90 b/gcc/testsuite/gfortran.dg/allocatable_function_6.f90 new file mode 100644 index 0000000..4255009 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocatable_function_6.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! +! PR fortran/56138 +! +! Contributed by John Chludzinski, using the code of John Reid +! +implicit none +CHARACTER(LEN=:),ALLOCATABLE :: str +if (s_to_c("ABCdef") /= "ABCdef" .or. len(s_to_c("ABCdef")) /= 6) call abort() +str = s_to_c("ABCdef") +if (str /= "ABCdef" .or. len(str) /= 6) call abort() +str(1:3) = s_to_c("123") +if (str /= "123def" .or. len(str) /= 6) call abort() + +contains + +PURE FUNCTION s_to_c(string) + CHARACTER(LEN=*),INTENT(IN) :: string + CHARACTER(LEN=:),ALLOCATABLE :: s_to_c + s_to_c = string +ENDFUNCTION s_to_c +end