/* Implementation of the NORM2 intrinsic
- Copyright 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010-2020 Free Software Foundation, Inc.
Contributed by Tobias Burnus <burnus@net-b.de>
This file is part of the GNU Fortran runtime library (libgfortran).
<http://www.gnu.org/licenses/>. */
#include "libgfortran.h"
-#include <stdlib.h>
-#include <math.h>
-#include <assert.h>
int continue_loop;
/* Make dim zero based to avoid confusion. */
- dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
+ dim = (*pdim) - 1;
+
+ if (unlikely (dim < 0 || dim > rank))
+ {
+ runtime_error ("Dim argument incorrect in NORM intrinsic: "
+ "is %ld, should be between 1 and %ld",
+ (long int) dim + 1, (long int) rank + 1);
+ }
len = GFC_DESCRIPTOR_EXTENT(array,dim);
if (len < 0)
extent[n] = 0;
}
- if (retarray->data == NULL)
+ if (retarray->base_addr == NULL)
{
size_t alloc_size, str;
}
retarray->offset = 0;
- retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+ retarray->dtype.rank = rank;
- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
- * extent[rank-1];
+ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
return;
}
- else
- retarray->data = internal_malloc_size (alloc_size);
}
else
{
return;
}
- base = array->data;
- dest = retarray->data;
+ base = array->base_addr;
+ dest = retarray->base_addr;
continue_loop = 1;
while (continue_loop)
*dest = 0;
else
{
+#if ! defined HAVE_BACK_ARG
for (n = 0; n < len; n++, src += delta)
{
+#endif
if (*src != 0)
{
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
- if (n == rank)
+ if (n >= rank)
{
- /* Break out of the look. */
+ /* Break out of the loop. */
continue_loop = 0;
break;
}