aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-02-01 23:33:24 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-02-03 19:22:40 +0100
commit4e4252db0348a7274663a892c3a96d3ed7702aff (patch)
treeb4f376d186df501e905d94b7dc425a43ba1a06c9 /gcc
parentc7d0d03a6bfbd09dccaeaa0ed6c2e072c86e4792 (diff)
downloadgcc-4e4252db0348a7274663a892c3a96d3ed7702aff.zip
gcc-4e4252db0348a7274663a892c3a96d3ed7702aff.tar.gz
gcc-4e4252db0348a7274663a892c3a96d3ed7702aff.tar.bz2
Fortran: reject simplifying TRANSFER for MOLD with storage size 0
gcc/fortran/ChangeLog: PR fortran/104311 * check.cc (gfc_calculate_transfer_sizes): Checks for case when storage size of SOURCE is greater than zero while the storage size of MOLD is zero and MOLD is an array shall not depend on SIZE. gcc/testsuite/ChangeLog: PR fortran/104311 * gfortran.dg/transfer_simplify_15.f90: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/check.cc2
-rw-r--r--gcc/testsuite/gfortran.dg/transfer_simplify_15.f9011
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index d6c6767..fc97bb1 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -6150,7 +6150,7 @@ gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
* representation is not shorter than that of SOURCE.
* If SIZE is present, the result is an array of rank one and size SIZE.
*/
- if (result_elt_size == 0 && *source_size > 0 && !size
+ if (result_elt_size == 0 && *source_size > 0
&& (mold->expr_type == EXPR_ARRAY || mold->rank))
{
gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "
diff --git a/gcc/testsuite/gfortran.dg/transfer_simplify_15.f90 b/gcc/testsuite/gfortran.dg/transfer_simplify_15.f90
new file mode 100644
index 0000000..cdbec97
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/transfer_simplify_15.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/104311 - ICE out of memory
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ end type
+ type(t) :: x(2)
+ print *, transfer(1,x,2) ! { dg-error "shall not have storage size 0" }
+ print *, transfer(1,x,huge(1)) ! { dg-error "shall not have storage size 0" }
+end