From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119823 invoked by alias); 13 Jul 2016 17:33:18 -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 119724 invoked by uid 89); 13 Jul 2016 17:33:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=nicht, ping!, Ping!, jvdelisle@charter.net X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.22) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Jul 2016 17:33:08 +0000 Received: from vepi2 ([92.209.45.60]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0MA9FV-1bYcJI0XVZ-00BIlg; Wed, 13 Jul 2016 19:33:01 +0200 Date: Wed, 13 Jul 2016 17:33:00 -0000 From: Andre Vehreschild To: Jerry DeLisle Cc: fortran@gcc.gnu.org Subject: Re: [Ping, Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer Message-ID: <20160713193259.287c5d5d@vepi2> In-Reply-To: <20160705140745.6f74e0e5@vepi2> References: <20160629184327.5cd2928b@nb-vehre.private> <20160704134944.6d596ae4@vepi2> <20160705140745.6f74e0e5@vepi2> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/Yu0T7gF7MwZPtmZZHiBjfCP" X-UI-Out-Filterresults: notjunk:1;V01:K0:/gb9clxr7xg=:kf6pgpSaVDBHYbPrbcLRxK Nq5zLnfWGfJOv8w0a6FNuRfA59jzNUyMyTZwTp3r73FJaR6L3Brggui27Xq2z5O4RgsR4FA42 KQbIcSOrTE/97H84LBK7evK73MfpWfWM/hwpZzBSU1iuHOS1mMOIslRONNotxGHtKhUs6aZ9F 4Cis36VhZYimQxjcf9TbRItS95GDk/LlzTaJHc9b3BwpsdATszNWG4ZnLNavN2hlUwQZUToqX TXR4Dnd8EVM5n2QqjEIuCxdn5G4T36cMgEcbE/MuEx80fZVzN0Fp7KZTCv3bsLKtT0MaFgTQd 8GzR1/t+tbCbnSdx11DZ9wvMa4iy21WDYLuZTLtyApbYuk50w+Bs1ZwhWvzjfitwGnbvLYCur 4mA8yBP4KDCFrLJzImhbcJO/sOcvb9j8iQdHqo0Sy4M4k9tiUUM1SX8YqHJ6nLt9qnbe7/6ga G4Gb66S3JoSrR3m66SVKdiMd2C1oyOby+QxfDI572do0ZtfL+CRy6WDzMeGMF3TMVRt2J8TiM r89rlJm4x4SHgRtE2+K/xyg7X26/Ln/dGz/+w0b8t4e861Q9Mi9LkJ0fPbycLgBbD+VYBYRPc WEGcPa/A4doAmw7buh7OzEdLbxaLB144cIZ5kDq3CUp7ESdc5teYkPSiF/P4y6l/G/J2mia1X iMNxeljapEvNbw4vEBuRiTL+5nSm6nKwf70RTKvBsT8gb2EJswkRGZIEwGW0xQB4Ys48HPBou uyq887mKtrbpHUHsc3n55jVIzVMyEfkMztIX6Wyr2i54+IOO18cemGTtZUk= X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg00062.txt.bz2 --MP_/Yu0T7gF7MwZPtmZZHiBjfCP Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1570 Hi all, backported to gcc-6-branch as r238304, and gcc-5-branch as r238308. Thanks again for the review. Regards, Andre On Tue, 5 Jul 2016 14:07:45 +0200 Andre Vehreschild wrote: > Hi Jerry, > > thanks for the kind review. Committed to trunk as r238002. I will wait > one week before applying to gcc-6/5. > > Thanks again, > Andre > > On Mon, 4 Jul 2016 09:01:07 -0700 > Jerry DeLisle wrote: > > > On 07/04/2016 04:49 AM, Andre Vehreschild wrote: > > > Ping! > > > > > > Additionally did I get the time to check the patch for gcc-6 and > > > -5. It applies cleanly to both and has no regressions. Ok for > > > trunk and with one week delay for gcc-6 and -5? > > > > > > > > > OK, OK and OK! Thanks for your work. > > > > Jerry > > > > > - Andre > > > > > > On Wed, 29 Jun 2016 18:43:27 +0200 > > > Andre Vehreschild wrote: > > > > > >> 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_/Yu0T7gF7MwZPtmZZHiBjfCP Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=submit-gcc-6.diff Content-length: 3397 Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 238303) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,10 @@ +2016-07-13 Andre Vehreschild + + Backport from trunk: + PR fortran/71623 + * trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec + in allocate to parent block. + 2016-07-09 Thomas Koenig Backport from trunk: Index: gcc/fortran/trans-stmt.c =================================================================== --- gcc/fortran/trans-stmt.c (Revision 238303) +++ gcc/fortran/trans-stmt.c (Arbeitskopie) @@ -5694,9 +5694,11 @@ 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); } } @@ -5895,6 +5897,7 @@ 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)); @@ -5979,11 +5982,19 @@ 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 Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 238303) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2016-07-13 Andre Vehreschild + + Backport from trunk: + PR fortran/71623 + * gfortran.dg/deferred_character_17.f90: New test. + 2016-07-13 Ilya Enkovich Backport from mainline r238086. Index: gcc/testsuite/gfortran.dg/deferred_character_17.f90 =================================================================== --- gcc/testsuite/gfortran.dg/deferred_character_17.f90 (nicht existent) +++ gcc/testsuite/gfortran.dg/deferred_character_17.f90 (Arbeitskopie) @@ -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_/Yu0T7gF7MwZPtmZZHiBjfCP Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=submit-gcc-5.diff Content-length: 3399 Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 238304) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,10 @@ +2016-07-13 Andre Vehreschild + + Backport from trunk: + PR fortran/71623 + * trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec + in allocate to parent block. + 2016-07-11 Thomas Koenig Backport from trunk: Index: gcc/fortran/trans-stmt.c =================================================================== --- gcc/fortran/trans-stmt.c (Revision 238304) +++ gcc/fortran/trans-stmt.c (Arbeitskopie) @@ -5651,9 +5651,11 @@ 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); } } @@ -5848,6 +5850,7 @@ 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)); @@ -5932,11 +5935,19 @@ 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 Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 238304) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,10 @@ +2016-07-13 Andre Vehreschild + + Backport from trunk: + PR fortran/71623 + * gfortran.dg/deferred_character_18.f90: New test. + + 2016-07-12 Segher Boessenkool Backport from mainline Index: gcc/testsuite/gfortran.dg/deferred_character_18.f90 =================================================================== --- gcc/testsuite/gfortran.dg/deferred_character_18.f90 (nicht existent) +++ gcc/testsuite/gfortran.dg/deferred_character_18.f90 (Arbeitskopie) @@ -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_/Yu0T7gF7MwZPtmZZHiBjfCP--