From patchwork Wed Jun 29 16:43:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 642138 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rfpR82sl5z9rxm for ; Thu, 30 Jun 2016 02:44:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=r/80d56x; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=kWeKeRYao/ATaI5FBL3DrmXhF7CCOJqwCk9qrSwk3Qr+sc2v+KpAA lFUFVAUEeoVGfS7ePw+NlKaU5BH21jUVqSeQdWPak8eqBFOpQNHacHD0UrgP3f4U PdYI168dD13LxDQknc8iPAKcz9FALW0gbMU35jQItVYUwbpcxKi4II= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=GiYYzEEoyc16BYDcAlVw9ZSJ3cs=; b=r/80d56xqXR3bQh1bHdU 2dyERhehPkzcGccVi2Fu2z+o8e02LGBRvRZnTpiBAQHml3CI7B6gm3bOPjOfwLjj ndGzTIiQJ9xWl5tkP+ulqy6Cq4Wg9fwSwAOVsomW5DJWosQFuOBAx9AWF+ZkKtT+ 5OBc1IXKI8857NQkIn+8mNg= Received: (qmail 29464 invoked by alias); 29 Jun 2016 16:43:51 -0000 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 Received: (qmail 29443 invoked by uid 89); 29 Jun 2016 16:43:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=mold, H*F:D*gmx.de, 58997, allocating X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jun 2016 16:43:41 +0000 Received: from nb-vehre.private ([95.90.219.132]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0Lxxw4-1bNXog1vXQ-015IAc; Wed, 29 Jun 2016 18:43:34 +0200 Date: Wed, 29 Jun 2016 18:43:27 +0200 From: Andre Vehreschild To: GCC-Fortran , gcc-patches@gcc.gnu.org Subject: [Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer Message-ID: <20160629184327.5cd2928b@nb-vehre.private> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:aMx5Mri0Oew=:up5Z9uvbVJp9sLwF+6+44Q eXGhs4Wl89oSn4VrJrla7lgVxHmZA32Eo7Lfe2bMBSgu/CEhKNxLdIUEiT+i26ums63b9o5LI oz8Cq10Y7n0SkD/U/CAudlqAFhiRFVVGQeJsd+G/Ah24MddBfDo2H7TW3zSWP55WrRLaWYCA+ Mx6vAjyVSTv/YHMI9JpsAQ9W7OOm9i1QNXgsq+QTvAL/idzVdbwRmi0t8R7tFjhNSzww4ZJES 5+IqR8H3rv8srvHyfWqeCAUdTbRHpes8v41zq1iWm716Xtp2igAx+XaHzYPdhIzqvVSP6exa5 309j59zWoZ0BpS1pZs2QrdX9ypi9vSk1MF2yLa4pSroEiAkr3s7qZ96EGEQ37SiIKQjFMUGDS IWDDA5DZ2ftgtH+VzxhKyQgZK2Q14aD44ggChHFrVRCwSmslMw8yycEcyCkxvoERyL4LehjC+ izblZVdx7fUMr9xt0dVzZAGPQps2Xvr1BjdNoqN4HA2IYNliNdRiAQZC2E7HC5kWPEb8QTGLd qAMO6wPwNm8HY9IJB6Zqq/3bOOWcLNoRUqW3foZmkErJbL2cRTIBTSz6TBAaaRaRpLUjHbDMP d/cS4poe8D51JksKKyYaYDkhZ7nluREmhaoenkneKdU6uiTltFuf9Gj3ApN+4Zsg81d2kAQON RtED0ukA2fclULZqWTmYikY1gatQLvKwSoNX2WwTW+18i98Y8TrenBd7ow2ShwW6N2P6Tm7Zr bfnBkAjTgP61RymiFbsfzmSc0aIvj+NKr9SMTJ2wjy1cm2oeKeQhLHaHhuI= Hi all, the attached patch fixes the regression at least for trunk (I haven't checked the others, but for 6 it should do either, 5 may need a little bit more work). The issue here is that computing the typespec involved code in se.pre that was not merged to the parent block. Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk? I promise to do a backport to gcc-6 and -5 next week, once this patch has been lifing in trunk a few days. Regards, Andre diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 84bf749..5aa7778 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5696,9 +5696,11 @@ gfc_trans_allocate (gfc_code * code) tmp = gfc_get_char_type (code->ext.alloc.ts.kind); tmp = TYPE_SIZE_UNIT (tmp); tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp); + gfc_add_block_to_block (&block, &se_sz.pre); expr3_esize = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (se_sz.expr), tmp, se_sz.expr); + expr3_esize = gfc_evaluate_now (expr3_esize, &block); } } @@ -5897,6 +5899,7 @@ gfc_trans_allocate (gfc_code * code) source= or mold= expression. */ gfc_init_se (&se_sz, NULL); gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length); + gfc_add_block_to_block (&block, &se_sz.pre); gfc_add_modify (&block, al_len, fold_convert (TREE_TYPE (al_len), se_sz.expr)); @@ -5981,11 +5984,19 @@ gfc_trans_allocate (gfc_code * code) specified by a type spec for deferred length character arrays or unlimited polymorphic objects without a source= or mold= expression. */ - gfc_init_se (&se_sz, NULL); - gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length); - gfc_add_modify (&block, al_len, - fold_convert (TREE_TYPE (al_len), - se_sz.expr)); + if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1) + { + gfc_init_se (&se_sz, NULL); + gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length); + gfc_add_block_to_block (&block, &se_sz.pre); + gfc_add_modify (&block, al_len, + fold_convert (TREE_TYPE (al_len), + se_sz.expr)); + } + else + gfc_add_modify (&block, al_len, + fold_convert (TREE_TYPE (al_len), + expr3_esize)); } else /* No length information needed, because type to allocate diff --git a/gcc/testsuite/gfortran.dg/deferred_character_17.f90 b/gcc/testsuite/gfortran.dg/deferred_character_17.f90 new file mode 100644 index 0000000..5a9d725 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_17.f90 @@ -0,0 +1,13 @@ +!{ dg-do run } + +! Check fix for PR fortran/71623 + +program allocatemvce + implicit none + character(len=:), allocatable :: string + integer, dimension(4), target :: array = [1,2,3,4] + integer, dimension(:), pointer :: array_ptr + array_ptr => array + ! The allocate used to segfault + allocate(character(len=size(array_ptr))::string) +end program allocatemvce