]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: check type of SUB argument to IMAGE_INDEX
authorHarald Anlauf <anlauf@gmx.de>
Mon, 29 Nov 2021 21:23:02 +0000 (22:23 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 30 Nov 2021 19:20:55 +0000 (20:20 +0100)
gcc/fortran/ChangeLog:

PR fortran/101565
* check.c (gfc_check_image_index): Verify that SUB argument to
IMAGE_INDEX is of type integer.

gcc/testsuite/ChangeLog:

PR fortran/101565
* gfortran.dg/coarray_49.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
gcc/fortran/check.c
gcc/testsuite/gfortran.dg/coarray_49.f90 [new file with mode: 0644]

index 3e65f3d8b1f8a2a8a7beb19b180f037a6e5d8552..ee3a51ee253bd5442cea5704734fea709013ca24 100644 (file)
@@ -5955,6 +5955,13 @@ gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
       return false;
     }
 
+  if (sub->ts.type != BT_INTEGER)
+    {
+      gfc_error ("Type of %s argument of IMAGE_INDEX at %L shall be INTEGER",
+                gfc_current_intrinsic_arg[1]->name, &sub->where);
+      return false;
+    }
+
   if (gfc_array_size (sub, &nelems))
     {
       int corank = gfc_get_corank (coarray);
diff --git a/gcc/testsuite/gfortran.dg/coarray_49.f90 b/gcc/testsuite/gfortran.dg/coarray_49.f90
new file mode 100644 (file)
index 0000000..370e3fd
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+! PR fortran/101565 - ICE in gfc_simplify_image_index
+! Contributed by G. Steinmetz
+
+program p
+  integer :: x[*]
+  print *, image_index (x, [1.0]) ! { dg-error "shall be INTEGER" }
+end