From patchwork Sat Mar 11 14:59:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 66270 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADD853858C36 for ; Sat, 11 Mar 2023 15:00:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADD853858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678546800; bh=qGxA26ki3pZuIRjJ+TyXZXNm2P0gvWPGS70kg8rPRqI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aNh1ecJsm2WywwWMoUpIj80aHN1CH1wQ3NNpdnlHGjBEDoc+wxokS7KDYLUF3oIpQ CBG/zHnILQfcgjkq4H2e6NIu6gQh+ReVm+xi5hd/XqVYdYGwFpEO9oW5u6bNy/1Fza VJg/p7gOlPfwbrd+paT2U2JFJJ9Yv47Nf5HU+VVc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by sourceware.org (Postfix) with ESMTPS id 478DC3858D28; Sat, 11 Mar 2023 14:59:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 478DC3858D28 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.11.141] ([79.251.11.141]) by web-mail.gmx.net (3c-app-gmx-bs11.server.lan [172.19.170.62]) (via HTTP); Sat, 11 Mar 2023 15:59:28 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, pushed] Fortran: fix bounds check for copying of class expressions [PR106945] Date: Sat, 11 Mar 2023 15:59:28 +0100 Importance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WXht9X/Os5EoP2WB+IzCLXnUxSbB7/9s7BMBvWEqEaEJAJ+NIC6vEP13ZaGR9v71JruPs1 Fx3OUZspeeFljHF5fkoutUoFILNK52W8dpkyKyHJlmUsG7iF9AYt61Ex//VepWZkMTgXQSB/M wuv6eQHttAp1LVXoxhS+jNIwaV/6DriTtPYBAOlj5Vqh8= X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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 From 2cf5f485e0351bb1faf46196a99e524688f3966e Mon Sep 17 00:00:00 2001 From: Harald Anlauf 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