public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10437] Fortran: reject simplifying TRANSFER for MOLD with storage size 0
Date: Fri,  4 Feb 2022 19:18:15 +0000 (GMT)	[thread overview]
Message-ID: <20220204191815.B7E283858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:837ad03ad4a95629a0d17108f5258568bebbf13f

commit r10-10437-g837ad03ad4a95629a0d17108f5258568bebbf13f
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Feb 1 23:33:24 2022 +0100

    Fortran: reject simplifying TRANSFER for MOLD with storage size 0
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104311
            * check.c (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.
    
    (cherry picked from commit 4e4252db0348a7274663a892c3a96d3ed7702aff)

Diff:
---
 gcc/fortran/check.c                                |  2 +-
 gcc/testsuite/gfortran.dg/transfer_simplify_15.f90 | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index df2fe1ff828..44e2da65a4c 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -6126,7 +6126,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 00000000000..cdbec97ae71
--- /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


                 reply	other threads:[~2022-02-04 19:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220204191815.B7E283858D28@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).