From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 7F4AA3858D1E; Sat, 11 Mar 2023 14:52:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F4AA3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678546346; bh=JVyPoaprKQYFvXr2etQBSNUN6Z23YdTHuSMTKh2WJ/o=; h=From:To:Subject:Date:From; b=cKHMF2TdE39oq0Qg0el+VvCECiOg12uXeTL3z+CaRzQ4SO1rhaA5jbgpD+Oq/AlC9 M/bXNP3kh9MSPqd05Gr3nMjZfnh89p4Mh67G/Zb/flNyinnvNzzOj2cW3/kpVreklW yXKT45zUGs2s8lsIXtvzlfrq4X7zCD9rpupv3bMc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6605] Fortran: fix bounds check for copying of class expressions [PR106945] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: c62df15d283f035d5b1644f74493db2933f2a8cb X-Git-Newrev: 2cf5f485e0351bb1faf46196a99e524688f3966e Message-Id: <20230311145226.7F4AA3858D1E@sourceware.org> Date: Sat, 11 Mar 2023 14:52:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2cf5f485e0351bb1faf46196a99e524688f3966e commit r13-6605-g2cf5f485e0351bb1faf46196a99e524688f3966e Author: Harald Anlauf 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. Diff: --- gcc/fortran/trans-expr.cc | 1 + gcc/testsuite/gfortran.dg/pr106945.f90 | 11 +++++++++++ 2 files changed, 12 insertions(+) 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