/* Implementation of the SHAPE intrinsic
- Copyright 2002 Free Software Foundation, Inc.
+ Copyright 2002, 2006, 2007 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
-#include "config.h"
+#include "libgfortran.h"
#include <stdlib.h>
#include <assert.h>
-#include "libgfortran.h"
-extern void shape_4 (gfc_array_i4 * ret, const gfc_array_i4 * array);
+
+#if defined (HAVE_GFC_INTEGER_4)
+
+extern void shape_4 (gfc_array_i4 * const restrict ret,
+ const gfc_array_i4 * const restrict array);
export_proto(shape_4);
void
-shape_4 (gfc_array_i4 * ret, const gfc_array_i4 * array)
+shape_4 (gfc_array_i4 * const restrict ret,
+ const gfc_array_i4 * const restrict array)
{
int n;
index_type stride;
+ index_type extent;
stride = ret->dim[0].stride;
- if (stride == 0)
- stride = 1;
+
+ if (ret->dim[0].ubound < ret->dim[0].lbound)
+ return;
for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++)
{
- ret->data[n * stride] =
- array->dim[n].ubound + 1 - array->dim[n].lbound;
+ extent = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ ret->data[n * stride] = extent > 0 ? extent : 0 ;
}
}
+
+#endif