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: 68125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp319500wrd; Sat, 11 Mar 2023 07:00:17 -0800 (PST) X-Google-Smtp-Source: AK7set/aqnmXrek2slB2mmP7UZzvFVpfNW+VR/OZHmc82Tf/59zmRuBS87usEyAw3LPgMtkLQc5m X-Received: by 2002:a05:6402:3d2:b0:4ac:bde4:ff14 with SMTP id t18-20020a05640203d200b004acbde4ff14mr27191736edw.42.1678546816990; Sat, 11 Mar 2023 07:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678546816; cv=none; d=google.com; s=arc-20160816; b=kQAluF2DHcC4vahb6o7GMG7gqz+GuPv2Hn9qGqTiY0xJKQ53TAGhoX9IZilPh+BatW 89bMPvAkrFcc9vi9VboTZzwlg+SCmD98H6zLKt55UQdQW9pMXv0kX4mCQlZxaq27wTcL PjGWYp345YHjIRqem6cinMkqsR9a7+J3dNLL+3LyeLQ9snWMNIGbMOCgYpiph51IHtUN MBjlnaiLmt8k3AWnoEgi/pZRmRtZBGZHtF+hiN3thTR/zZe8EjXm3iNg0SHCIvd20r78 GImiod0eMs32Le8ZHhlBbqxogBNUVUqj+uaZ3KBOJLtwC39vU5dviSdc9crpiKy3ecGa Z/LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=qGxA26ki3pZuIRjJ+TyXZXNm2P0gvWPGS70kg8rPRqI=; b=OkLWhc2mUP0wCFdTuQjrK3kZLBkX+pN05uNvixx4x3QFQ+0Mij97H1j6gmhdESnJEt DQyoxFrs49PyUDCEmV//6cefxq9kI8Zx+Ksk6HeYPjK0Xc86QXijHr4c22b9QlM099tD xs/jkUKELjpvCuIHaffVw1tZopK9lGxONvGx2opstie5uBSxsLopvbuXvZX1ssbmZJOb fgalUthbD33FXgfCDxeCISjuVjRWnbjgaTZEi3LHXGP5f9wGZLlJ7hmELTnmrTg4kMOM UWQupQeMSNL9AOPXqaHmCnHGvrN1McgYS+qKsN+nUalqXq1psxhOPG8aS+viQ21303yE Kf9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PNIo3A1L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r22-20020aa7cb96000000b004c26b68c120si457535edt.420.2023.03.11.07.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Mar 2023 07:00:16 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PNIo3A1L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3E3B3858425 for ; Sat, 11 Mar 2023 15:00:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3E3B3858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678546815; bh=qGxA26ki3pZuIRjJ+TyXZXNm2P0gvWPGS70kg8rPRqI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PNIo3A1Lon2v9Sf95/9mOPR+Tj7h/1lZq67WCGOqBWF0myNCRuwVCT8+jw5s3FLdm 9uMn2zeYBDU03CoaLLJS3td9NPGSt/y7IcA+mRzKliqm1FVS5rij+BEIMq4m3PmR4R 2avbU2tW+i0SvfsTssdAFoOVebtFZ27EsRCEb3NA= 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: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:pgolFSwsAgJeuYcLYs62uwWEl+ds4ATkaYrHzSA6UeZBq8gnJIi+9Mzv+9fjtzE2c9/Ew I5wrohkWs3fWaGKL+5mpaH462JkOHrPVz1V26Mzo7aWwWGtrw+tCy7rxapXxkzlKBYhdKBi0Sksj NjfA9SCdRGpcyx3Bkn8mAi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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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760083907045156213?= X-GMAIL-MSGID: =?utf-8?q?1760083907045156213?= 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