]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/maxloc0_8_r16.c
re PR libfortran/34670 (bounds checking for array intrinsics)
[thirdparty/gcc.git] / libgfortran / generated / maxloc0_8_r16.c
index b849d5067cb3def69909715160a0e1db147ed3c9..6dec78a49f96389a4d5cfae73e7213b96d977298 100644 (file)
@@ -69,11 +69,22 @@ maxloc0_8_r16 (gfc_array_i8 * const restrict retarray,
     }
   else
     {
-      if (GFC_DESCRIPTOR_RANK (retarray) != 1)
-       runtime_error ("rank of return array does not equal 1");
-
-      if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
-        runtime_error ("dimension of return array incorrect");
+      if (compile_options.bounds_check)
+       {
+         int ret_rank;
+         index_type ret_extent;
+
+         ret_rank = GFC_DESCRIPTOR_RANK (retarray);
+         if (ret_rank != 1)
+           runtime_error ("rank of return array in MAXLOC intrinsic"
+                          " should be 1, is %d", ret_rank);
+
+         ret_extent = retarray->dim[0].ubound + 1 - retarray->dim[0].lbound;
+         if (ret_extent != rank)
+           runtime_error ("Incorrect extent in return value of"
+                          " MAXLOC intrnisic: is %ld, should be %d",
+                          (long int) ret_extent, rank);
+       }
     }
 
   dstride = retarray->dim[0].stride;
@@ -182,11 +193,40 @@ mmaxloc0_8_r16 (gfc_array_i8 * const restrict retarray,
     }
   else
     {
-      if (GFC_DESCRIPTOR_RANK (retarray) != 1)
-       runtime_error ("rank of return array does not equal 1");
-
-      if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
-        runtime_error ("dimension of return array incorrect");
+      if (compile_options.bounds_check)
+       {
+         int ret_rank, mask_rank;
+         index_type ret_extent;
+         int n;
+         index_type array_extent, mask_extent;
+
+         ret_rank = GFC_DESCRIPTOR_RANK (retarray);
+         if (ret_rank != 1)
+           runtime_error ("rank of return array in MAXLOC intrinsic"
+                          " should be 1, is %d", ret_rank);
+
+         ret_extent = retarray->dim[0].ubound + 1 - retarray->dim[0].lbound;
+         if (ret_extent != rank)
+           runtime_error ("Incorrect extent in return value of"
+                          " MAXLOC intrnisic: is %ld, should be %d",
+                          (long int) ret_extent, rank);
+       
+         mask_rank = GFC_DESCRIPTOR_RANK (mask);
+         if (rank != mask_rank)
+           runtime_error ("rank of MASK argument in MAXLOC intrnisic"
+                          "should be %d, is %d", rank, mask_rank);
+
+         for (n=0; n<rank; n++)
+           {
+             array_extent = array->dim[n].ubound + 1 - array->dim[n].lbound;
+             mask_extent = mask->dim[n].ubound + 1 - mask->dim[n].lbound;
+             if (array_extent != mask_extent)
+               runtime_error ("Incorrect extent in MASK argument of"
+                              " MAXLOC intrinsic in dimension %d:"
+                              " is %ld, should be %ld", n + 1,
+                              (long int) mask_extent, (long int) array_extent);
+           }
+       }
     }
 
   mask_kind = GFC_DESCRIPTOR_SIZE (mask);
@@ -312,11 +352,20 @@ smaxloc0_8_r16 (gfc_array_i8 * const restrict retarray,
     }
   else
     {
-      if (GFC_DESCRIPTOR_RANK (retarray) != 1)
-       runtime_error ("rank of return array does not equal 1");
+      if (compile_options.bounds_check)
+       {
+         int ret_rank;
+         index_type ret_extent;
 
-      if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
-        runtime_error ("dimension of return array incorrect");
+         ret_rank = GFC_DESCRIPTOR_RANK (retarray);
+         if (ret_rank != 1)
+           runtime_error ("rank of return array in MAXLOC intrinsic"
+                          " should be 1, is %d", ret_rank);
+
+         ret_extent = retarray->dim[0].ubound + 1 - retarray->dim[0].lbound;
+           if (ret_extent != rank)
+             runtime_error ("dimension of return array incorrect");
+       }
     }
 
   dstride = retarray->dim[0].stride;