]> gcc.gnu.org Git - gcc.git/commitdiff
Fortran: fix bounds check for copying of class expressions [PR106945]
authorHarald Anlauf <anlauf@gmx.de>
Sat, 11 Mar 2023 14:37:37 +0000 (15:37 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 11 Mar 2023 14:48:32 +0000 (15:48 +0100)
In the bounds check for copying of class expressions, the number of elements
determined from a descriptor, returned as type gfc_array_index_type (i.e. a
signed type), should be converted to the type of the passed element count,
which is of type size_type_node (i.e. unsigned), for use in comparisons.

gcc/fortran/ChangeLog:

PR fortran/106945
* trans-expr.cc (gfc_copy_class_to_class): Convert element counts in
bounds check to common type for comparison.

gcc/testsuite/ChangeLog:

PR fortran/106945
* gfortran.dg/pr106945.f90: New test.

gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/pr106945.f90 [new file with mode: 0644]

index 045c8b00b9021cece7d37abc6e1277537ba5a26f..dcd39f46776034cf1b494a776ed6d5f878267dd5 100644 (file)
@@ -1531,6 +1531,7 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, bool unlimited)
            name = (const char *)(DECL_NAME (to)->identifier.id.str);
 
          from_len = gfc_conv_descriptor_size (from_data, 1);
+         from_len = fold_convert (TREE_TYPE (orig_nelems), from_len);
          tmp = fold_build2_loc (input_location, NE_EXPR,
                                  logical_type_node, from_len, orig_nelems);
          msg = xasprintf ("Array bound mismatch for dimension %d "
diff --git a/gcc/testsuite/gfortran.dg/pr106945.f90 b/gcc/testsuite/gfortran.dg/pr106945.f90
new file mode 100644 (file)
index 0000000..e760ca7
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single -fcheck=bounds -ftrapv" }
+! PR fortran/106945
+! Contributed by G. Steinmetz
+
+module m
+  implicit none
+  type t
+     class(*), allocatable :: a[:]
+  end type
+end
This page took 0.095532 seconds and 5 git commands to generate.