public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, pushed] Fortran: fix bounds check for copying of class expressions  [PR106945]
Date: Sat, 11 Mar 2023 15:59:28 +0100	[thread overview]
Message-ID: <trinity-618a0ce8-7457-4d87-828a-ea87d1342711-1678546768519@3c-app-gmx-bs11> (raw)

[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]

Dear all,

I've committed the attached patch to mainline as obvious after
regtesting on x86_64-pc-linux-gnu.

https://gcc.gnu.org/g:2cf5f485e0351bb1faf46196a99e524688f3966e

commit r13-6605-g2cf5f485e0351bb1faf46196a99e524688f3966e
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sat Mar 11 15:37:37 2023 +0100

    Fortran: fix bounds check for copying of class expressions [PR106945]

    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.


The PR is marked as a 10/11/12/13 regression, and given its simplicity,
it should qualify for backports.

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr106945.diff --]
[-- Type: text/x-patch, Size: 2113 bytes --]

From 2cf5f485e0351bb1faf46196a99e524688f3966e Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Sat, 11 Mar 2023 15:37:37 +0100
Subject: [PATCH] Fortran: fix bounds check for copying of class expressions
 [PR106945]

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              |  1 +
 gcc/testsuite/gfortran.dg/pr106945.f90 | 11 +++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr106945.f90

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 045c8b00b90..dcd39f46776 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -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
index 00000000000..e760ca7d27f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106945.f90
@@ -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
--
2.35.3


                 reply	other threads:[~2023-03-11 14:59 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=trinity-618a0ce8-7457-4d87-828a-ea87d1342711-1678546768519@3c-app-gmx-bs11 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@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).