]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/unpack_c4.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / unpack_c4.c
index 472ce48c26e18c1c14e1e31e0373b32ae374a691..15c20c57334ee1b8b3389ca1b3d46ed8bfa80f5e 100644 (file)
@@ -1,37 +1,30 @@
 /* Specific implementation of the UNPACK intrinsic
-   Copyright 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
    Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>, based on
    unpack_generic.c 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
 License as published by the Free Software Foundation; either
-version 2 of the License, or (at your option) any later version.
-
-In addition to the permissions in the GNU General Public License, the
-Free Software Foundation gives you unlimited permission to link the
-compiled version of this file into combinations with other programs,
-and to distribute those combinations without any restriction coming
-from the use of this file.  (The General Public License restrictions
-do apply in other respects; for example, they cover modification of
-the file, and distribution when not linked into a combine
-executable.)
+version 3 of the License, or (at your option) any later version.
 
 Ligbfortran is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public
-License along with libgfortran; see the file COPYING.  If not,
-write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+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>
 
 
@@ -45,7 +38,7 @@ unpack0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   index_type rstride[GFC_MAX_DIMENSIONS];
   index_type rstride0;
   index_type rs;
-  GFC_COMPLEX_4 *rptr;
+  GFC_COMPLEX_4 * restrict rptr;
   /* v.* indicates the vector array.  */
   index_type vstride0;
   GFC_COMPLEX_4 *vptr;
@@ -66,7 +59,7 @@ unpack0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
 
   empty = 0;
 
-  mptr = mask->data;
+  mptr = mask->base_addr;
 
   /* Use the same loop for all logical types, by using GFC_LOGICAL_1
      and using shifting to address size and endian issues.  */
@@ -86,7 +79,7 @@ unpack0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   else
     runtime_error ("Funny sized logical array");
 
-  if (ret->data == NULL)
+  if (ret->base_addr == NULL)
     {
       /* The front end has signalled that we need to populate the
         return array descriptor.  */
@@ -95,28 +88,29 @@ unpack0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
       for (n = 0; n < dim; n++)
        {
          count[n] = 0;
-         ret->dim[n].stride = rs;
-         ret->dim[n].lbound = 0;
-         ret->dim[n].ubound = mask->dim[n].ubound - mask->dim[n].lbound;
-         extent[n] = ret->dim[n].ubound + 1;
+         GFC_DIMENSION_SET(ret->dim[n], 0,
+                           GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
+         extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = ret->dim[n].stride;
-         mstride[n] = mask->dim[n].stride * mask_kind;
+         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
        }
       ret->offset = 0;
-      ret->data = internal_malloc_size (rs * sizeof (GFC_COMPLEX_4));
+      ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_4));
     }
   else
     {
       dim = GFC_DESCRIPTOR_RANK (ret);
+      /* Initialize to avoid -Wmaybe-uninitialized complaints.  */
+      rstride[0] = 1;
       for (n = 0; n < dim; n++)
        {
          count[n] = 0;
-         extent[n] = ret->dim[n].ubound + 1 - ret->dim[n].lbound;
+         extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = ret->dim[n].stride;
-         mstride[n] = mask->dim[n].stride * mask_kind;
+         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
       if (rstride[0] == 0)
        rstride[0] = 1;
@@ -128,13 +122,13 @@ unpack0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   if (mstride[0] == 0)
     mstride[0] = 1;
 
-  vstride0 = vector->dim[0].stride;
+  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
   if (vstride0 == 0)
     vstride0 = 1;
   rstride0 = rstride[0];
   mstride0 = mstride[0];
-  rptr = ret->data;
-  vptr = vector->data;
+  rptr = ret->base_addr;
+  vptr = vector->base_addr;
 
   while (rptr)
     {
@@ -188,7 +182,7 @@ unpack1_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   index_type rstride[GFC_MAX_DIMENSIONS];
   index_type rstride0;
   index_type rs;
-  GFC_COMPLEX_4 *rptr;
+  GFC_COMPLEX_4 * restrict rptr;
   /* v.* indicates the vector array.  */
   index_type vstride0;
   GFC_COMPLEX_4 *vptr;
@@ -211,7 +205,7 @@ unpack1_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
 
   empty = 0;
 
-  mptr = mask->data;
+  mptr = mask->base_addr;
 
   /* Use the same loop for all logical types, by using GFC_LOGICAL_1
      and using shifting to address size and endian issues.  */
@@ -231,7 +225,7 @@ unpack1_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   else
     runtime_error ("Funny sized logical array");
 
-  if (ret->data == NULL)
+  if (ret->base_addr == NULL)
     {
       /* The front end has signalled that we need to populate the
         return array descriptor.  */
@@ -240,30 +234,31 @@ unpack1_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
       for (n = 0; n < dim; n++)
        {
          count[n] = 0;
-         ret->dim[n].stride = rs;
-         ret->dim[n].lbound = 0;
-         ret->dim[n].ubound = mask->dim[n].ubound - mask->dim[n].lbound;
-         extent[n] = ret->dim[n].ubound + 1;
+         GFC_DIMENSION_SET(ret->dim[n], 0,
+                           GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
+         extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = ret->dim[n].stride;
-         fstride[n] = field->dim[n].stride;
-         mstride[n] = mask->dim[n].stride * mask_kind;
+         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
+         mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
        }
       ret->offset = 0;
-      ret->data = internal_malloc_size (rs * sizeof (GFC_COMPLEX_4));
+      ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_4));
     }
   else
     {
       dim = GFC_DESCRIPTOR_RANK (ret);
+      /* Initialize to avoid -Wmaybe-uninitialized complaints.  */
+      rstride[0] = 1;
       for (n = 0; n < dim; n++)
        {
          count[n] = 0;
-         extent[n] = ret->dim[n].ubound + 1 - ret->dim[n].lbound;
+         extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = ret->dim[n].stride;
-         fstride[n] = field->dim[n].stride;
-         mstride[n] = mask->dim[n].stride * mask_kind;
+         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
+         mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
       if (rstride[0] == 0)
        rstride[0] = 1;
@@ -277,15 +272,15 @@ unpack1_c4 (gfc_array_c4 *ret, const gfc_array_c4 *vector,
   if (mstride[0] == 0)
     mstride[0] = 1;
 
-  vstride0 = vector->dim[0].stride;
+  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
   if (vstride0 == 0)
     vstride0 = 1;
   rstride0 = rstride[0];
   fstride0 = fstride[0];
   mstride0 = mstride[0];
-  rptr = ret->data;
-  fptr = field->data;
-  vptr = vector->data;
+  rptr = ret->base_addr;
+  fptr = field->base_addr;
+  vptr = vector->base_addr;
 
   while (rptr)
     {