From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp09.smtpout.orange.fr [80.12.242.131]) by sourceware.org (Postfix) with ESMTPS id 38B3D3858002 for ; Thu, 9 Dec 2021 20:37:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38B3D3858002 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orange.fr Received: from [192.168.1.17] ([92.167.144.168]) by smtp.orange.fr with ESMTPA id vQA2mBr2bUujjvQA8m2qvb; Thu, 09 Dec 2021 21:37:08 +0100 X-ME-Helo: [192.168.1.17] X-ME-Auth: MDU4MTIxYWM4YWI0ZGE4ZTUwZWZmNTExZmI2ZWZlMThkM2ZhYiE5OWRkOGM= X-ME-Date: Thu, 09 Dec 2021 21:37:08 +0100 X-ME-IP: 92.167.144.168 Message-ID: <6c67790c-bda2-299b-a253-dc96bb11fea0@orange.fr> Date: Thu, 9 Dec 2021 21:37:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] PR libfortran/103634 - Runtime crash with PACK on zero-sized arrays Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: From: Mikael Morin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2021 20:37:12 -0000 Hello, On 09/12/2021 21:05, Harald Anlauf via Fortran wrote: > Dear all, > > I had thought that we had fixed this in the past (see PR31001), > but it did fail for me with all gcc versions I have tried (7-12) > for a slightly more elaborate case as in the old testcase. > > The loop in pack_internal did try to access the first element of > the array argument to PACK even if one (or more) extents were zero. > This is not good. > > Solution: check the extents and return early. (We already do a > related check for the vector argument if present). If there is a vector argument, aren’t we supposed to copy it to the result ? There is something else to pay attention for, the early return should come at least after the return array bounds have been set. In the testcase an array with the correct bounds has been allocated beforehand to hold the return value, but it’s not always the case. For what it’s worth, the non-generic variant in pack.m4 (or in pack_{i,f,c}{1,2,4,8,10,16}.c) has a zero extent check and it clears the source ptr in that case, which makes it setup the return array and then jump to the vector copy at the end of the function.