|Summary:||Fortran 2003: POINTER Rank Remapping|
|Product:||gcc||Reporter:||Tobias Burnus <burnus>|
|Component:||fortran||Assignee:||Daniel Kraft <domob>|
|Severity:||enhancement||CC:||anlauf, gcc-bugs, klaas_giesbertz|
|Build:||Known to work:|
|Known to fail:||Last reconfirmed:||2010-07-21 09:06:34|
|Bug Depends on:|
Description Tobias Burnus 2006-11-09 18:47:59 UTC
POINTER Rank Remapping (From http://www.fortran.bcs.org/forum2002/f2000dme.htm) Motivation: ability to have pointers to diagonals of matrices. REAL,ALLOCATABLE,TARGET :: base_array(:) REAL,POINTER :: matrix(:,:) REAL,POINTER :: diagonal(:) ... ALLOCATE(base_array(n*n)) matrix(1:n,1:n) => base_array ! rank remapping diagonal => base_array(::n+1) Notes: * The base array must be rank one, to ensure that the remapping is a simple linear transformation. * Both lower bound and upper bound must be specified for each dimension. Fortran 2003 standard, see "18.104.22.168 Data pointer assignment": "R735 pointer-assignment-stmt is data-pointer-object [ (bounds-spec-list) ] => data-target or data-pointer-object (bounds-remapping-list ) => data-target or proc-pointer-object => proc-target C718 (R735) If bounds-spec-list is specified, the number of bounds-specs shall equal the rank of data pointer-object. C719 (R735) If bounds-remapping-list is specified, the number of bounds-remappings shall equal the rank of data-pointer-object. C720 (R735) If bounds-remapping-list is specified, data-target shall have rank one; otherwise, the ranks of data-pointer-object and data-target shall be the same." and "22.214.171.124 Data pointer assignment": "If bounds-remapping-list is specified, data-target shall not be a disassociated or undefined pointer, and the size of data-target shall not be less than the size of data-pointer-object. The elements of the target of data-pointer-object, in array element order (126.96.36.199), are the first SIZE(data-pointer-object) elements of data-target."
Comment 1 Tobias Burnus 2007-04-12 09:19:31 UTC
Comment 2 Tobias Burnus 2008-07-03 16:09:49 UTC
In Fortran 2008 the rank-one constraint is gone: "C720 If bounds-remapping-list is not specified, the ranks of data-pointer-object and data-target shall be the same."
Comment 3 Joost VandeVondele 2009-08-07 07:35:07 UTC
still missing 4.5.0, this seems a particularly useful F03 feature ;-) For an expert, should be 'easy' to add (ignoring the F2008 variant) ?
Comment 4 Tobias Burnus 2010-07-21 09:03:19 UTC
Fortran 2008 has the following, which I missed to quote: "If bounds-remapping-list is specified, the pointer target shall be simply contiguous (6.5.4) or of rank one. It shall not be a disassociated or undefined pointer, and the size of the pointer target shall not be less than the size of the pointer object. The elements of the target of the pointer object, in array element order (188.8.131.52), are the first SIZE (data-pointer-object) elements of the pointer target." "C717 (R733) If bounds-remapping-list is specified, the number of bounds-remappings shall equal the rank of data-pointer-object."
Comment 5 Daniel Kraft 2010-07-21 09:06:34 UTC
I'll work on this.
Comment 6 Tobias Burnus 2010-07-21 10:14:34 UTC
See also PR 45016, which is not about bounds remapping but about setting the correct bounds in an array assignment. (Wrong-code F95 bug + missing F2003 feature). Maybe all three (remapping, fix bounds, F2003 lower bounds) can be fixed simultaneously.
Comment 7 Daniel Kraft 2010-08-17 17:38:28 UTC
Tobias (and all): Do you think we should check for "the size of data-target shall not be less than the size of data-pointer-object" at runtime when -fcheck=bounds is given?
Comment 8 Mikael Morin 2010-08-17 18:21:31 UTC
(In reply to comment #7) > Tobias (and all): Do you think we should check for "the size of data-target > shall not be less than the size of data-pointer-object" at runtime when > -fcheck=bounds is given? > Yes. The existing bounds-check code checks that we don't access an array beyond what its descriptor permits. We have to check that we don't create a descriptor that has bounds beyond the array limits, thus by-passing the bounds-check code.
Comment 9 Daniel Kraft 2010-08-18 19:34:44 UTC
Created attachment 21514 [details] Partial patch. This implements rank remapping and also bounds remapping as for PR 45016. Tests seem to be successful, although it's not yet been fully regtested. I still have to / want to add a compile-time and -fcheck=bounds test for too small target.
Comment 10 Daniel Kraft 2010-08-19 16:02:50 UTC
Subject: Bug 29785 Author: domob Date: Thu Aug 19 16:02:30 2010 New Revision: 163377 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163377 Log: 2010-08-19 Daniel Kraft <firstname.lastname@example.org> PR fortran/29785 PR fortran/45016 * trans.h (struct gfc_se): New flag `byref_noassign'. * trans-array.h (gfc_conv_shift_descriptor_lbound): New method. (gfc_conv_array_extent_dim), (gfc_conv_descriptor_size): New methods. * expr.c (gfc_check_pointer_assign): Allow bounds and rank remapping and check for compile-time errors with those. * trans-decl.c (trans_associate_var): Use new routine `gfc_conv_shift_descriptor_lbound' instead of doing it manually. * trans-array.c (gfc_conv_shift_descriptor_lbound): New method. (gfc_conv_array_extent_dim), (gfc_conv_descriptor_size): New methods. (gfc_array_init_size): Use new `gfc_conv_array_extent_dim'. (gfc_conv_expr_descriptor): Handle new flag `byref_noassign'. * trans-expr.c (gfc_trans_pointer_assignment): Handle bounds and rank remapping for assignment. 2010-08-19 Daniel Kraft <email@example.com> PR fortran/29785 PR fortran/45016 * gfortran.dg/pointer_assign_5.f90: Remove 'not implemented' error. * gfortran.dg/pointer_remapping_1.f90: New test. * gfortran.dg/pointer_remapping_2.f03: New test. * gfortran.dg/pointer_remapping_3.f08: New test. * gfortran.dg/pointer_remapping_4.f03: New test. * gfortran.dg/pointer_remapping_5.f08: New test. * gfortran.dg/pointer_remapping_6.f08: New test. Added: trunk/gcc/testsuite/gfortran.dg/pointer_remapping_1.f90 trunk/gcc/testsuite/gfortran.dg/pointer_remapping_2.f03 trunk/gcc/testsuite/gfortran.dg/pointer_remapping_3.f08 trunk/gcc/testsuite/gfortran.dg/pointer_remapping_4.f03 trunk/gcc/testsuite/gfortran.dg/pointer_remapping_5.f08 trunk/gcc/testsuite/gfortran.dg/pointer_remapping_6.f08 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/fortran/trans-array.c trunk/gcc/fortran/trans-array.h trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans.h trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/pointer_assign_5.f90
Comment 11 Daniel Kraft 2010-08-19 16:06:12 UTC
Fixed (with an extended version of the patch attached above).