From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id 88AA33882100; Fri, 14 Jun 2024 15:05:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88AA33882100 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 88AA33882100 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718377553; cv=none; b=SotG2zcu7yOZKZMXAO9rtnoBEF2GhbRin6ZxUHCbx14MXG7KVbmqqvMOmRA0G7+jV5xGTH68n61cUvw+a3cj3LHoDvPs2w3ZWEXs376mcucUfGs5AC4vef4zcRTu3FgbOYA0Uu7vhcqhrCc4rZh/XqaqbpEvHXLkumvyNpqTQu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718377553; c=relaxed/simple; bh=j0Ov+v1/0bkQwQmvLYLRXYv5cLjskuU7K50sFFV4GEg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=sm+6ZFi4evYRdfjbtUtMUsO133/9n0ncRWoRy7Z5hXml98aUrllL0UL4UwDEFWpSS+FOarX5P7CvLqkvjmGoQ88gG4PvC+Bu2YQVidnKslQUDwxYePmsyAW0JDD8sPYVw9H2Hj3WpPG+bSbBMcSuePmc35NwpaJQFghUIFU5gkk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1718377547; x=1718982347; i=vehre@gmx.de; bh=yTxkIk9zpxH8M88DFVvoJXE5IsC7/nH1Buhoyegmc0k=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=T7OZH8cLVqNQYGaFvFTHk+alQ+D9VssCbAp6fDmEUpRaLO63bENk1iRxbnCygXSW TatwprcJ14YUH9ZJKOpa7goGjY+Bjt0LXeKCtl4Ri0d6HQthGLCh/lIe9hKuOhRR6 m/vDSCFaR8KeaJgnVRftgpRxIy7YBWlK/D15j+yVQGN33/rBU7lo3nWvrjMU1cAis 03cTcrpkMtZF69D8gpKQ2HoQ7bPt79vY6aMOCdNbgnalnssbBOtUy5PLsdUH4NK6k s48tdESz/okGRVpPBf7vUkS+B5ILssKAjmufJru0kLMIxF6M6xWXVxiqv5ug01zJF qfSpRWoofaMvcKRp1Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from vepi2 ([79.194.165.201]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MbzyJ-1sozH20PLL-00aLlZ; Fri, 14 Jun 2024 17:05:47 +0200 Date: Fri, 14 Jun 2024 17:05:46 +0200 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Subject: [Fortran, Patch, PR 96992] Fix Class arrays of different ranks are rejected as storage association argument Message-ID: <20240614170546.4180607f@vepi2> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/7v4V3hqcH33HQNnE8nM0zGW" X-Provags-ID: V03:K1:i/o2OA7AQVXWKVwMeCmu0xI2h8TUEFaGZrjpYB8S9HQKaOhtAMO 7evnDFiTNRhlSoh+EC5SG53a2OWtjxXHmY98QMV0AY+HlLPyOz1PPIhKeU+St56T3NB9CC2 hmMR/BXjS2aD57j4VS4Cd6W7ORsw5ovP+7734E3NKLn/7zRusn2m3CjHaLPVLiEMBrk9xEh BMtDY2UmVro/rLwYsSBnw== UI-OutboundReport: notjunk:1;M01:P0:lCQJYt56OS8=;EskOluBawdI6oWK/Hq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_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --MP_/7v4V3hqcH33HQNnE8nM0zGW Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi all, I somehow got assigned to this PR so I fixed it. GFortran was ICEing becau= se of the ASSUME_RANK in a derived to class conversion. After fixing this, stora= ge association was producing segfaults. The "shape conversion" of the class a= rray as dummy argument was not initializing the dim 0 stride and with that grab= bing into the memory somewhere. This is now fixed and regtests fine on x86_64 Fedora 39. Ok for mainline? I assume this patch could be fixing some other PRs with class array's para= meter passing, too. If that sounds familiar, feel free to point me to them. Regards, Andre =2D- Andre Vehreschild * Email: vehre ad gmx dot de --MP_/7v4V3hqcH33HQNnE8nM0zGW Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=pr96992_1.patch =46rom 86ac3179e1314ca1c41f52025c5a156ad7346dc1 Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Fri, 14 Jun 2024 16:54:37 +0200 Subject: [PATCH] Fortran: [PR96992] Fix rejecting class arrays of differen= t ranks as storage association argument. Removing the assert in trans-expr, lead to initial strides not set which is not fixed. PR fortran/96992 gcc/fortran/ChangeLog: * trans-array.cc (gfc_trans_array_bounds): Set a starting stride, when descriptor expects a variable for the stride. (gfc_trans_dummy_array_bias): Allow storage association for dummy class arrays, when they are not elemental. * trans-expr.cc (gfc_conv_derived_to_class): Remove assert to allow converting derived to class type arrays with assumend rank. gcc/testsuite/ChangeLog: * gfortran.dg/pr96992.f90: New test. =2D-- gcc/fortran/trans-array.cc | 7 ++- gcc/fortran/trans-expr.cc | 2 - gcc/testsuite/gfortran.dg/pr96992.f90 | 61 +++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr96992.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index b3088a892c8..9fa8bad2f35 100644 =2D-- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -6798,6 +6798,9 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym,= tree * poffset, size =3D gfc_index_one_node; offset =3D gfc_index_zero_node; + stride =3D GFC_TYPE_ARRAY_STRIDE (type, 0); + if (stride && VAR_P (stride)) + gfc_add_modify (pblock, stride, gfc_index_one_node); for (dim =3D 0; dim < as->rank; dim++) { /* Evaluate non-constant array bound expressions. @@ -7134,7 +7137,9 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree t= mpdesc, || (is_classarray && CLASS_DATA (sym)->attr.allocatable)) return; - if (!is_classarray && sym->attr.dummy && gfc_is_nodesc_array (sym)) + if ((!is_classarray + || (is_classarray && CLASS_DATA (sym)->as->type =3D=3D AS_EXPLICIT= )) + && sym->attr.dummy && !sym->attr.elemental && gfc_is_nodesc_array (= sym)) { gfc_trans_g77_array (sym, block); return; diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 0796fb75505..4bb62cfb1ad 100644 =2D-- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -903,8 +903,6 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e= , if (e->rank !=3D class_ts.u.derived->components->as->rank) { - gcc_assert (class_ts.u.derived->components->as->type - =3D=3D AS_ASSUMED_RANK); if (derived_array && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (parmse->expr))) { diff --git a/gcc/testsuite/gfortran.dg/pr96992.f90 b/gcc/testsuite/gfortra= n.dg/pr96992.f90 new file mode 100644 index 00000000000..c56ed80f394 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr96992.f90 @@ -0,0 +1,61 @@ +! { dg-do run } + +! PR fortran/96992 + +! Contributed by Thomas Koenig + +! From the standard: +! An actual argument that represents an element sequence and +! corresponds to a dummy argument that is an array is sequence +! associated with the dummy argument. The rank and shape of the +! actual argument need not agree with the rank and shape of the +! dummy argument, but the number of elements in the dummy argument +! shall not exceed the number of elements in the element sequence +! of the actual argument. If the dummy argument is assumed-size, +! the number of elements in the dummy argument is exactly +! the number of elements in the element sequence. + +! Check that walking the sequence starts with an initialized stride +! for dim =3D=3D 0. + +module foo_mod + implicit none + type foo + integer :: i + end type foo +contains + subroutine d1(x,n) + integer, intent(in) :: n + integer :: i + class (foo), intent(out), dimension(n) :: x + select type(x) + class is(foo) + x(:)%i =3D (/ (42 + i, i =3D 1, n ) /) + class default + stop 1 + end select + end subroutine d1 + subroutine d2(x,n) + integer, intent(in) :: n + integer :: i + class (foo), intent(in), dimension(n,n,n) :: x + select type (x) + class is (foo) + print *,x%i + if ( any( x%i /=3D reshape((/ (42 + i, i =3D 1, n ** 3 ) /), [n, n= , n] ))) stop 2 + class default + stop 3 + end select + end subroutine d2 +end module foo_mod +program main + use foo_mod + implicit none + type (foo), dimension(:), allocatable :: f + integer :: n + n =3D 3 + allocate (f(n*n*n)) + call d1(f,n*n*n) + call d2(f,n) +end program main + =2D- 2.45.1 --MP_/7v4V3hqcH33HQNnE8nM0zGW--