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-10421] Fortran: MOLD argument to TRANSFER intrinsic having storage size zero
Date: Wed, 26 Jan 2022 17:56:54 +0000 (GMT)	[thread overview]
Message-ID: <20220126175655.0000D384B839@sourceware.org> (raw)

https://gcc.gnu.org/g:0646ff3e170b87050bad4448b89406e476f64496

commit r10-10421-g0646ff3e170b87050bad4448b89406e476f64496
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Jan 25 21:56:39 2022 +0100

    Fortran: MOLD argument to TRANSFER intrinsic having storage size zero
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104227
            * check.c (gfc_calculate_transfer_sizes): Fix checking of arrays
            passed as MOLD argument to the TRANSFER intrinsic for having
            storage size zero.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104227
            * gfortran.dg/transfer_check_6.f90: New test.
    
    (cherry picked from commit ec543c9833c2d9283c035cd8430849eb4ec04406)

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

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 392786ac48e..df2fe1ff828 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -6127,7 +6127,7 @@ gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
    * If SIZE is present, the result is an array of rank one and size SIZE.
    */
   if (result_elt_size == 0 && *source_size > 0 && !size
-      && mold->expr_type == EXPR_ARRAY)
+      && (mold->expr_type == EXPR_ARRAY || mold->rank))
     {
       gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "
 		 "array and shall not have storage size 0 when %<SOURCE%> "
diff --git a/gcc/testsuite/gfortran.dg/transfer_check_6.f90 b/gcc/testsuite/gfortran.dg/transfer_check_6.f90
new file mode 100644
index 00000000000..dffd0913f0d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/transfer_check_6.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/104227 - ICE virtual memory exhausted
+! Contributed by G.Steinmetz
+
+program p
+  type t
+  end type
+  type(t) :: x(2)
+  print *, transfer(1, x) ! { dg-error "shall not have storage size 0" }
+  x = transfer(1, x)      ! { dg-error "shall not have storage size 0" }
+end


                 reply	other threads:[~2022-01-26 17:56 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=20220126175655.0000D384B839@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).