]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/parity_l1.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / parity_l1.c
index 84b1e9676d0a08521a80f88abe65de27989b13f7..e8ee6bd3baca0211dd7e2cc947a929c2355a0f8c 100644 (file)
@@ -1,5 +1,5 @@
-/* Implementation of the NORM2 intrinsic
-   Copyright 2010 Free Software Foundation, Inc.
+/* Implementation of the PARITY intrinsic
+   Copyright (C) 2010-2023 Free Software Foundation, Inc.
    Contributed by Tobias Burnus  <burnus@net-b.de>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -24,9 +24,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <stdlib.h>
-#include <math.h>
-#include <assert.h>
 
 
 #if defined (HAVE_GFC_LOGICAL_1) && defined (HAVE_GFC_LOGICAL_1)
@@ -55,8 +52,15 @@ parity_l1 (gfc_array_l1 * const restrict retarray,
   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 PARITY 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)
@@ -96,12 +100,11 @@ parity_l1 (gfc_array_l1 * const restrict retarray,
        }
 
       retarray->offset = 0;
-      retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+      retarray->dtype.rank = rank;
 
-      alloc_size = sizeof (GFC_LOGICAL_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
-                  * extent[rank-1];
+      alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
-      retarray->base_addr = internal_malloc_size (alloc_size);
+      retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_1));
       if (alloc_size == 0)
        {
          /* Make sure we have a zero-sized array.  */
@@ -147,8 +150,10 @@ parity_l1 (gfc_array_l1 * const restrict retarray,
          *dest = 0;
        else
          {
+#if ! defined HAVE_BACK_ARG
            for (n = 0; n < len; n++, src += delta)
              {
+#endif
 
   result = result != *src;
              }
@@ -171,9 +176,9 @@ parity_l1 (gfc_array_l1 * const restrict retarray,
          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;
            }