From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id A0AAF3871024; Mon, 21 Jun 2021 06:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0AAF3871024 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: wGVsKrGvbn/8xVLv7q840ckgXojN5qGmiOqKZVVeUtv/ixwo8faGvo1r4EHopiklCiWj3w/O9s +546W0i+GNriyYP5M4k8URrYlPBGCXx39c44vGmYU80pvOFNKwX1RJ+FtrPoQHp3Mjygf6UGoJ df1ckDyyg4SPLyXYbbUyoYFrZ573k+tAUxe5kRDDT0jVS/rJLtUHsIG3C6ghwJ69xAfUGKcnBY 1xGVPiPLoW1nisCBRX+rUNfh5X7iQ9F0IP8AoUkaoQeAIc06Rs6wDnVe7zif2qdaj0nYKDNsrK Ds4= X-IronPort-AV: E=Sophos;i="5.83,289,1616486400"; d="scan'208";a="62801518" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 20 Jun 2021 22:05:44 -0800 IronPort-SDR: QdY787KffRLDmTDt2QeYQndunlED6b6/iz4jxqR381vYKkFLJhrctpFtpJpsuZd414dw2JqZeR kitJwV5FOYXm9HR4wlRIV5OWIEnnrtxCzK+DXsN5WJruMfdm4cxYS6GU8LcM7Zlg5RYldU7xYj 3WMjhUFMqFZmkFkjaemUSWdI81/SSEXvBppi7nXP+YNlAb1+0riPw0LDVzsFlK8bkUenbWDbWl qMbZNA/AUAUbtf6maxon2WOt3+QOjDAJpoQpMY0qkK29mzKDk7ou9cOV05MaODGurBEqRk7UAM 3Gk= To: "gcc-patches@gcc.gnu.org" , "fortran@gcc.gnu.org" , Tobias Burnus From: Sandra Loosemore Subject: [patch] Fortran: fix sm computation in CFI_allocate [PR93524] Message-ID: <0b898a9d-2140-c2d3-a315-33b49ff0fadf@codesourcery.com> Date: Mon, 21 Jun 2021 00:05:38 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------267FECB14BB63D03063769E6" Content-Language: en-US X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jun 2021 06:05:47 -0000 --------------267FECB14BB63D03063769E6 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit I ran into this bug in CFI_allocate while testing something else and then realized there was already a PR open for it. It seems like an easy fix, and I've used Tobias's test case from the issue more or less verbatim. There were some other bugs added on to this issue but I think they have all been fixed already except for this one. OK to check in? -Sandra --------------267FECB14BB63D03063769E6 Content-Type: text/x-patch; charset="UTF-8"; name="pr93524.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr93524.patch" commit de9920753469e36c968b273a0e8b4d66a1d57946 Author: Sandra Loosemore Date: Sun Jun 20 22:37:55 2021 -0700 Fortran: fix sm computation in CFI_allocate [PR93524] This patch fixes a bug in setting the step multiplier field in the C descriptor for array dimensions > 2. 2021-06-20 Sandra Loosemore Tobias Burnus libgfortran/ PR fortran/93524 * runtime/ISO_Fortran_binding.c (CFI_allocate): Fix sm computation. gcc/testsuite/ PR fortran/93524 * gfortran.dg/pr93524.c, gfortran.dg/pr93524.f90: New. diff --git a/gcc/testsuite/gfortran.dg/pr93524.c b/gcc/testsuite/gfortran.dg/pr93524.c new file mode 100644 index 0000000..8a6c066 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93524.c @@ -0,0 +1,33 @@ +/* Test the fix for PR93524, in which CFI_allocate was computing + sm incorrectly for dimensions > 2. */ + +#include // For size_t +#include + +void my_fortran_sub_1 (CFI_cdesc_t *dv); +void my_fortran_sub_2 (CFI_cdesc_t *dv); + +int main () +{ + CFI_CDESC_T (3) a; + CFI_cdesc_t *dv = (CFI_cdesc_t *) &a; + // dv, base_addr, attribute, type, elem_len, rank, extents + CFI_establish (dv, NULL, CFI_attribute_allocatable, CFI_type_float, 0, 3, NULL); + + if (dv->base_addr != NULL) + return 1; // shall not be allocated + + CFI_index_t lower_bounds[] = {-10, 0, 3}; + CFI_index_t upper_bounds[] = {10, 5, 10}; + size_t elem_len = 0; // only needed for strings + if (CFI_SUCCESS != CFI_allocate (dv, lower_bounds, upper_bounds, elem_len)) + return 2; + + if (!CFI_is_contiguous (dv)) + return 2; // allocatables shall be contiguous,unless a strided section is used + + my_fortran_sub_1 (dv); + my_fortran_sub_2 (dv); + CFI_deallocate (dv); + return 0; +} diff --git a/gcc/testsuite/gfortran.dg/pr93524.f90 b/gcc/testsuite/gfortran.dg/pr93524.f90 new file mode 100644 index 0000000..b21030b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93524.f90 @@ -0,0 +1,15 @@ +! { dg-additional-sources pr93524.c } +! { dg-do run } +! +! Test the fix for PR93524. The main program is in pr93524.c. + +subroutine my_fortran_sub_1 (A) bind(C) + real :: A(:, :, :) + print *, 'Lower bounds: ', lbound(A) ! Lower bounds: 1 1 1 + print *, 'Upper bounds: ', ubound(A) ! Upper bounds: 21 6 8 +end +subroutine my_fortran_sub_2 (A) bind(C) + real, ALLOCATABLE :: A(:, :, :) + print *, 'Lower bounds: ', lbound(A) + print *, 'Upper bounds: ', ubound(A) +end subroutine my_fortran_sub_2 diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c index 20833ad..0978832 100644 --- a/libgfortran/runtime/ISO_Fortran_binding.c +++ b/libgfortran/runtime/ISO_Fortran_binding.c @@ -254,10 +254,7 @@ CFI_allocate (CFI_cdesc_t *dv, const CFI_index_t lower_bounds[], { dv->dim[i].lower_bound = lower_bounds[i]; dv->dim[i].extent = upper_bounds[i] - dv->dim[i].lower_bound + 1; - if (i == 0) - dv->dim[i].sm = dv->elem_len; - else - dv->dim[i].sm = dv->elem_len * dv->dim[i - 1].extent; + dv->dim[i].sm = dv->elem_len * arr_len; arr_len *= dv->dim[i].extent; } } --------------267FECB14BB63D03063769E6--