]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/intrinsics/reshape_generic.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / intrinsics / reshape_generic.c
index 77bb3d89a033b939c215e2bf05e932ebd3b0d6b9..934ab82be50bf31ae58e4cdd061fb01d09872a5d 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic implementation of the RESHAPE intrinsic
-   Copyright (C) 2002-2016 Free Software Foundation, Inc.
+   Copyright (C) 2002-2024 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -24,11 +24,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <stdlib.h>
 #include <string.h>
 
-typedef GFC_ARRAY_DESCRIPTOR(1, index_type) shape_type;
-typedef GFC_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) parray;
+typedef GFC_FULL_ARRAY_DESCRIPTOR(1, index_type) shape_type;
+typedef GFC_FULL_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) parray;
 
 static void
 reshape_internal (parray *ret, parray *source, shape_type *shape,
@@ -67,6 +66,10 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
   rdim = GFC_DESCRIPTOR_EXTENT(shape,0);
+  /* rdim is always > 0; this lets the compiler optimize more and
+     avoids a warning.  */
+  GFC_ASSERT (rdim > 0);
+  
   if (rdim != GFC_DESCRIPTOR_RANK(ret))
     runtime_error("rank of return array incorrect in RESHAPE intrinsic");
 
@@ -103,8 +106,7 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
        alloc_size = rs;
 
       ret->base_addr = xmallocarray (alloc_size, size);
-
-      ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+      ret->dtype.rank = rdim;
     }
 
   if (shape_empty)
@@ -159,6 +161,10 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
+      /* sdim is always > 0; this lets the compiler optimize more and
+         avoids a warning.  */
+      GFC_ASSERT(sdim>0);
+
       for (n = 0; n < sdim; n++)
        {
          index_type se;
@@ -220,6 +226,10 @@ reshape_internal (parray *ret, parray *source, shape_type *shape,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+  /* sdim is always > 0; this lets the compiler optimize more and
+     avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)