]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/spread_i16.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / spread_i16.c
index bdefdac32715848963a6c7d524cce8580e9aafac..9b3cf849f09cb285f643d5611a647090e4407683 100644 (file)
@@ -1,9 +1,9 @@
 /* Special implementation of the SPREAD intrinsic
-   Copyright 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008-2024 Free Software Foundation, Inc.
    Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>, based on
    spread_generic.c written by Paul Brook <paul@nowt.org>
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
 Libgfortran is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public
@@ -25,8 +25,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 
 
@@ -58,6 +56,8 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
 
   srank = GFC_DESCRIPTOR_RANK(source);
 
+  sstride[0] = 0; /* Avoid warnings if not initialized.  */
+  
   rrank = srank + 1;
   if (rrank > GFC_MAX_DIMENSIONS)
     runtime_error ("return rank too large in spread()");
@@ -67,14 +67,15 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
 
   ncopies = pncopies;
 
-  if (ret->data == NULL)
+  if (ret->base_addr == NULL)
     {
 
       size_t ub, stride;
 
       /* The front end has signalled that we need to populate the
         return array descriptor.  */
-      ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rrank;
+      ret->dtype.rank = rrank;
+
       dim = 0;
       rs = 1;
       for (n = 0; n < rrank; n++)
@@ -100,13 +101,11 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
          GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
        }
       ret->offset = 0;
-      if (rs > 0)
-        ret->data = internal_malloc_size (rs * sizeof(GFC_INTEGER_16));
-      else
-       {
-         ret->data = internal_malloc_size (1);
-         return;
-       }
+
+      /* xmallocarray allocates a single byte for zero size.  */
+      ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_16));
+      if (rs <= 0)
+        return;
     }
   else
     {
@@ -183,8 +182,8 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
     }
   sstride0 = sstride[0];
   rstride0 = rstride[0];
-  rptr = ret->data;
-  sptr = source->data;
+  rptr = ret->base_addr;
+  sptr = source->base_addr;
 
   while (sptr)
     {
@@ -231,10 +230,8 @@ spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
 
 void
 spread_scalar_i16 (gfc_array_i16 *ret, const GFC_INTEGER_16 *source,
-                       const index_type along, const index_type pncopies)
+                       const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_16 * restrict dest;
   index_type stride;
 
@@ -244,9 +241,9 @@ spread_scalar_i16 (gfc_array_i16 *ret, const GFC_INTEGER_16 *source,
   if (along > 1)
     runtime_error ("dim outside of rank in spread()");
 
-  if (ret->data == NULL)
+  if (ret->base_addr == NULL)
     {
-      ret->data = internal_malloc_size (ncopies * sizeof (GFC_INTEGER_16));
+      ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_16));
       ret->offset = 0;
       GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
     }
@@ -257,10 +254,10 @@ spread_scalar_i16 (gfc_array_i16 *ret, const GFC_INTEGER_16 *source,
        runtime_error ("dim too large in spread()");
     }
 
-  dest = ret->data;
+  dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;