This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC builtin functions allocate their results


I started working on the change that will allow builtin functions
to create the return value in case that the caller does not know
the shape of the result. This change was proposed by Paul Brook
long ago, but now I have time to do it.

Currently, if the caller does not know the shape of the result, it
causes ICE.  The change is (at least) two-fold.  First, to change
the caller's code so that it will create an array descriptor, but
does not allocate memory or set array bounds.  Second, to change
the library so that if the result array descriptor has null data
field, it will allocate the memory and set the array bounds.

This note deals with the second part of the change -- the library
part.  I changed one function just for example to get your
opinions, and then I will post a cross-library patch.

Note that without the related change in the compiler, this addition
is just dead code.  However, we must start somewhere -- if I first
patch the compiler, it will generate code that will crash in the
library.

Index: cshift0.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/intrinsics/cshift0.c,v
retrieving revision 1.2
diff -c -p -r1.2 cshift0.c
*** cshift0.c	13 May 2004 06:41:02 -0000	1.2
--- cshift0.c	26 Jul 2004 06:16:30 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 29,35 ****
     sizeof(int) < sizeof (index_type).  */

  static void
! __cshift0 (const gfc_array_char * ret, const gfc_array_char * array,
      int shift, int which)
  {
    /* r.* indicates the return array.  */
--- 29,35 ----
     sizeof(int) < sizeof (index_type).  */

  static void
! __cshift0 (gfc_array_char * ret, const gfc_array_char * array,
      int shift, int which)
  {
    /* r.* indicates the return array.  */
*************** __cshift0 (const gfc_array_char * ret, c
*** 69,74 ****
--- 69,93 ----
    soffset = size;
    len = 0;

+   if (ret->data == 0)
+     {
+       int i;
+
+       ret->data = prefix(internal_malloc) (size * prefix(size0) (array));
+       ret->base = 0;
+       ret->dtype = array->dtype;
+       for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+         {
+           ret->dim[i].lbound = 1;
+           ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound + 1;
+
+           if (i == 0)
+             ret->dim[i].stride = 1;
+           else
+             ret->dim[i].stride = ret->dim[i-1].ubound * ret->dim[i-1].stride;
+         }
+     }
+
    for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
      {
        if (dim == which)

-- 
  Victor Leikehman
  IBM Research Labs in Haifa, Israel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]