From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29465 invoked by alias); 29 Jun 2016 16:43:51 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@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 16:43:00 -0000 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 Content-Type: multipart/mixed; boundary="MP_/WubvD+1uYL8=.9gS7LpwXkN" 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= X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00120.txt.bz2 --MP_/WubvD+1uYL8=.9gS7LpwXkN Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 521 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 -- Andre Vehreschild * Email: vehre ad gmx dot de --MP_/WubvD+1uYL8=.9gS7LpwXkN Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pr71623_1.clog Content-length: 347 gcc/fortran/ChangeLog: 2016-06-28 Andre Vehreschild PR fortran/71623 * trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec in allocate to parent block. gcc/testsuite/ChangeLog: 2016-06-28 Andre Vehreschild PR fortran/71623 * gfortran.dg/deferred_character_17.f90: New test. --MP_/WubvD+1uYL8=.9gS7LpwXkN Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pr71623_1.patch Content-length: 2517 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 --MP_/WubvD+1uYL8=.9gS7LpwXkN--