From patchwork Sun Jan 23 16:00:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 80065 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 B35FCB710E for ; Mon, 24 Jan 2011 03:01:20 +1100 (EST) Received: (qmail 12881 invoked by alias); 23 Jan 2011 16:01:16 -0000 Received: (qmail 12863 invoked by uid 22791); 23 Jan 2011 16:01:15 -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 mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 23 Jan 2011 16:00:58 +0000 Received: from [192.168.178.22] (port-92-204-33-159.dynamic.qsc.de [92.204.33.159]) by mx01.qsc.de (Postfix) with ESMTP id 46B2E3D10F; Sun, 23 Jan 2011 17:00:54 +0100 (CET) Message-ID: <4D3C50B6.1090400@net-b.de> Date: Sun, 23 Jan 2011 17:00:54 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 47421 - Don't nullify allocatable scalar (character) dummy arguments 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 scalar allocatable character strings with "LEN=", gfortran nullified the dummy and freed it on on exit. The patch is simple: Don't do this. Build and regtested on x86-64-linux. OK for the trunk? What about 4.5? Tobias 2011-01-23 Tobias Burnus PR fortran/47421 * trans-decl.c (gfc_trans_deferred_vars): Do not nullify scalar allocatable dummy arguments. 2011-01-23 Tobias Burnus PR fortran/47421 * gfortran.dg/allocatable_scalar_12.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 254db76..5e3afbe 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3304,9 +3304,10 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) if (sym_has_alloc_comp && !seen_trans_deferred_array) gfc_trans_deferred_array (sym, block); } - else if (sym->attr.allocatable - || (sym->ts.type == BT_CLASS - && CLASS_DATA (sym)->attr.allocatable)) + else if (!sym->attr.dummy + && (sym->attr.allocatable + || (sym->ts.type == BT_CLASS + && CLASS_DATA (sym)->attr.allocatable))) { if (!sym->attr.save) { --- /dev/null 2011-01-14 07:32:07.372000004 +0100 +++ gcc/testsuite/gfortran.dg/allocatable_scalar_12.f90 2011-01-23 15:49:56.000000000 +0100 @@ -0,0 +1,30 @@ +! { dg-do run } +! +! PR fortran/47421 +! +! Don't auto-deallocatable scalar character allocatables. +! +implicit none +character(len=5), allocatable :: str +allocate(str) +str = '1bcde' +if(str /= '1bcde') call abort() +call sub(str,len(str)) +if(str /= '1bcde') call abort() +call subOUT(str,len(str)) +if (len(str) /= 5) call abort() +if(allocated(str)) call abort() +contains + subroutine sub(x,n) + integer :: n + character(len=n), allocatable :: x + if(len(x) /= 5) call abort() + if(x /= '1bcde') call abort() + end subroutine sub + subroutine subOUT(x,n) + integer :: n + character(len=n), allocatable,intent(out) :: x + if(allocated(x)) call abort() + if(len(x) /= 5) call abort() + end subroutine subOUT +end