From patchwork Wed Jan 24 21:39:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 191767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1268676dyi; Wed, 24 Jan 2024 13:40:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBVqZ3IUgJ56OD3a33KibWlfcDg5FrThXoOeXrURyjPCr7cMUqFbmT4cLd0cDvc8ay49Gh X-Received: by 2002:a67:bc0d:0:b0:469:a727:1410 with SMTP id t13-20020a67bc0d000000b00469a7271410mr31022vsn.20.1706132415088; Wed, 24 Jan 2024 13:40:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706132415; cv=pass; d=google.com; s=arc-20160816; b=nqltgm8EGkTLL2jIQHPgPZxTIT//DkD/5fZCu/CPDM6M5KAoNiAO6D7B72/DI+HwrO 4ihVCr+/N/xFKaayGjbN0Il4etnksy3OHVnv7CgNlIIh4qf0Xu2c9wvXeDcoflNmtn0e iyds4fgTE4DFYvWQGmeKcpsLaGldyTb3lfzS1yNvy3P/USwa+ZmErLuugml0WTlaBHVx vXJEURqKS8xxxGsoFFeMlZ83+f71Ss/dsASRlhffw8QV/bhp1ZO6YwRkTkpf38f0leIX /M3LWE3rIexSG6SFWDOZ8m0Vnr0pKW2jl6tzCl1i6NAB97o6dpg6xggPctJFHpbhqthx 2mLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:ui-outboundreport:sensitivity :importance:date:subject:to:from:message-id:mime-version :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=ACYTBuqQHxiUZpzgSKYiIFtn8133cwk39l1byM+6mNA=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=gFSEpBK9sMKuURF/WDIQvoFR5vEFJTivuVhtimRoBXoR0FT0eQEfgWnU9XYhnK1a96 H4oC6LJDygutJByuZtRhR7YvDF4if1VHhzl8V8VaW90CWPdS68GCYJEPgtVPQcdEF0s9 DpnIbT4bQBMfTzf4v4zO7mdRZwCDVFqcCBXjuGBOsVD/noNiaGtIsptRyrFUTFZqip/Y TxFDtbpgIDrRCW8w4UbU9oPcnsQKe61Wr2ZhvDqSW9uny4gRBit448K42QxxJnvSTutv A5Q9WNvZIWMTqQTfXYio/PIo+YuCUpq8laO/qQMFWI8ILLwS+fZwnWjyGumnrOtV6CPH eoyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="bocULo/8"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f12-20020a0ccc8c000000b006818acc6addsi11073330qvl.308.2024.01.24.13.40.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:40:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="bocULo/8"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C65F6385783C for ; Wed, 24 Jan 2024 21:40:14 +0000 (GMT) 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 74EB33858C35; Wed, 24 Jan 2024 21:39:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74EB33858C35 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 74EB33858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706132370; cv=none; b=fEFRIDHo2aqiA+8IIrHBdjYoxoUim1Y3WAgdUQ0N+tJq6W2M9bICQPPAJRUv1xRExBFglb+23PAK2sg/ygoTAxgMLcHnHsGV5tO8vUHrcPiSUlBkXon4CU3QsEb/uKCqd5DpAeCXdlZ7Ttm4C73aoGFjCr0mWg8v9oHLRp0OH+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706132370; c=relaxed/simple; bh=Ke6hCrqa5eMLPcOg86NPJ6P1/PnzGmd6GeQ/2jkIDOE=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=FWSyrdGtXuM6USXuBtEwDjUnNvak9A4gkCiM0FAbHlHU7sJ5bIeRYTcD6PI5OkoTgRzqrBYusK/8LTJia1BFbjApoCGjZHFrgnncG5PYLRueM8Cc6VGSx7qG2yH5QeMDSxjWU9LTn5dw88oNApd4+xTUC1WM/hXIjEnFwPd0Jss= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1706132367; x=1706737167; i=anlauf@gmx.de; bh=Ke6hCrqa5eMLPcOg86NPJ6P1/PnzGmd6GeQ/2jkIDOE=; h=X-UI-Sender-Class:From:To:Subject:Date; b=bocULo/83FV2CtWun+UmPdhvlEB5CT15sUxt2jpZd5E0U6u1+IIXjZHrpekIpJk7 Be8HHb/Ig3+vvKJ9QIQncAD4glBYJtdS8llFZW5y1/EDqFCIErpMsWkRXLrMDqMVN 4zDkJc6NOjgk9HmQVLdP0V5xEZ6zqeyhuS5WulMvZ5KGmbix5IrlQWMVOHnQZYjEH Xc8kkyO9xl/FFuWnD/Foxp5kOmhGCJOGVGsWVDDoPk+TbKHvsL5uMVyclxUHDSeCE pY3X08KgLeJtMnxj0yKhE/5s7bbNHraSE0m8FSOw3OC+NcTx/5fUDfdhYqjrwxrIu 6UyAuJHYqZmn1Ntzrw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.232.150.163] ([79.232.150.163]) by web-mail.gmx.net (3c-app-gmx-bap39.server.lan [172.19.172.109]) (via HTTP); Wed, 24 Jan 2024 22:39:27 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: use name of array component in runtime error message [PR30802] Date: Wed, 24 Jan 2024 22:39:27 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:Hp3rSm7t1bmBxT3YlyWM5/9K0ol7N3FOWprEM0TeZvn6Va86gybNlTkpzlF6SFzLufGUL 7KEEAkJOlKZyfDdEJUNRa+4ipUqv7b9My/LASdbR35ABOuD1dQUb07y8v8VDgeCQQDzcRggK1J55 lq+ooIQTnUYjEi9MK1kNOgDlM4erdM7GO9u7fqjEetmu+OQYvCoSWFgwTTt0l/MPd37Ip1dG9sQ1 IW25r3N/Fm/pdmVwCtqs2Wg6WyM29QrbF1TiIbqYoOgKSlIq6heeR60mY4zzi8H93lWl5iHy3vUX Kk= UI-OutboundReport: notjunk:1;M01:P0:4PiqMHod3/c=;Rb/NDzE2ELBbcZijz8cBLUSqCuj O2LY54i/e0/UCPn/Uo6iAnfy25Kw/pnsig5OGfNq+WpjjemOhFq2RLlTbChHJKDHnBcWB24ZX neKSjzEH53O/26EGkXy2jOg6MXn4n+BabVdq7Cwq3YlgsAqNTK+eau8hw6Xxm3jG0HOKwPCcY kVONgMM8QWL85mdOD6E4YiCJRj+x6+CZxxd89vbvwpdgxKwd3JBuKweg1HOQ8k/hM5GlzoS1i EWvHarF/8h5cu7yPCQXGXzVxMOrWHYiqgm3GB559KkeepaGOp7UDG5vPyklEtp/Tx4IzyaCGi gBeZ8m81kQtJsbtDIu6CM6h7wOW5ErJpurRsZi0Q7oAAfOqcwreOKJuXLWndDbBjZ780KqIUM +wpEwaXu99sQxolWs4aUD/Io//74b4AYciQVXXOPfJ3V+gpVitH8RRRluGft6rZaqQrFGG8si qW+lp2jqQJ63hhzFt8d1tbndQtmOBSgM3wPHWZpuuIrttizIAQpN097f2nLb8CfQddazK6Jnu /G77in1YYZRPHk/ahKyGY22n5VUGYTEFi0jW1ljvmwnYpPu8KbDYI2rx8aN5MEukxvXqikwxl DN2Az0TTzUroPYkblxsZVyZ+KLso8fxRNdhAKS69qfmfvx84Vqu1gK363EIbwSFc7Y9DQR68/ erNCKHhUJAY42Jd8DXWE2FhE4y0opcPWjlad7YTc3bmMVCMC89p8nD3nfT4vJnphzrjuFFiQe BSPjsTmrkKflsCcLCyXJ7s4svBRYJ+KdGub5HyWuafo6vOQhgWzlOoGWQhtLkfN2COrUVmnWq kYIdH7ijIlAo4PXcg7AJKNz8HWUH7AFwvSpsXQxTlTHC0= X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789009503192418227 X-GMAIL-MSGID: 1789009503192418227 Dear all, this patch is actually only a followup fix to generate the proper name of an array reference in derived-type components for the runtime error message generated for the bounds-checking code. Without the proper part ref, not only a user may get confused: I was, too... The testcase is compile-only, as it is only important to check the strings used in the error messages. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 43c0185764ec878576ef2255d9df24fbb1961af4 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 24 Jan 2024 22:28:31 +0100 Subject: [PATCH] Fortran: use name of array component in runtime error message [PR30802] gcc/fortran/ChangeLog: PR fortran/30802 * trans-array.cc (trans_array_bound_check): Derive name of component for use in runtime error message. gcc/testsuite/ChangeLog: PR fortran/30802 * gfortran.dg/bounds_check_fail_8.f90: New test. --- gcc/fortran/trans-array.cc | 34 ++++++++++++++++++ .../gfortran.dg/bounds_check_fail_8.f90 | 35 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 878a92aff18..f6ddce2d023 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3497,6 +3497,10 @@ trans_array_bound_check (gfc_se * se, gfc_ss *ss, tree index, int n, tree descriptor; char *msg; const char * name = NULL; + char *var_name = NULL; + gfc_expr *expr; + gfc_ref *ref; + size_t len; if (!(gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)) return index; @@ -3509,6 +3513,36 @@ trans_array_bound_check (gfc_se * se, gfc_ss *ss, tree index, int n, name = ss->info->expr->symtree->n.sym->name; gcc_assert (name != NULL); + /* When we have a component ref, compile name for the array section. + Note that there can only be one part ref. */ + expr = ss->info->expr; + if (expr->ref && !compname) + { + len = strlen (name) + 1; + + /* Find a safe length. */ + for (ref = expr->ref; ref; ref = ref->next) + if (ref->type == REF_COMPONENT) + len += 2 + strlen (ref->u.c.component->name); + + var_name = XALLOCAVEC (char, len); + strcpy (var_name, name); + + for (ref = expr->ref; ref; ref = ref->next) + { + /* Append component name. */ + if (ref->type == REF_COMPONENT) + { + strcat (var_name, "%%"); + strcat (var_name, ref->u.c.component->name); + continue; + } + if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION) + break; + } + name = var_name; + } + if (VAR_P (descriptor)) name = IDENTIFIER_POINTER (DECL_NAME (descriptor)); diff --git a/gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 b/gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 new file mode 100644 index 00000000000..3397e953ba6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 @@ -0,0 +1,35 @@ +! { dg-do compile } +! { dg-additional-options "-fcheck=bounds -g -fdump-tree-original" } +! { dg-output "At line 22 .*" } +! { dg-shouldfail "dimension 3 of array 'uu%z' outside of expected range" } +! +! PR fortran/30802 - improve bounds-checking for array references +! +! Checking the proper component references is the most important part here. + +program test + implicit none + integer :: k = 0 + type t + real, dimension(10,20,30) :: z = 23 + end type t + type u + type(t) :: vv(4,5) + end type u + type(t) :: uu, ww(1) + type(u) :: x1, x2, y1(1), y2(1) + + print *, uu % z(1,k,:) ! runtime check only for dimension 2 of z + print *, ww(1)% z(1,:,k) ! runtime check only for dimension 3 of z + print *, x1 % vv(2,3)% z(1,:,k) ! runtime check only for dimension 3 of z + print *, x2 % vv(k,:)% z(1,2,3) ! runtime check only for dimension 1 of vv + print *, y1(1)% vv(2,3)% z(1,:,k) ! runtime check only for dimension 3 of z + print *, y2(1)% vv(:,k)% z(1,2,3) ! runtime check only for dimension 2 of vv +end program test + +! { dg-final { scan-tree-dump-times "'uu%%z.' outside of expected range" 2 "original" } } +! { dg-final { scan-tree-dump-times "'ww%%z.' outside of expected range" 2 "original" } } +! { dg-final { scan-tree-dump-times "'x1%%vv%%z.' outside of expected range" 2 "original" } } +! { dg-final { scan-tree-dump-times "'x2%%vv.' outside of expected range" 2 "original" } } +! { dg-final { scan-tree-dump-times "'y1%%vv%%z.' outside of expected range" 2 "original" } } +! { dg-final { scan-tree-dump-times "'y2%%vv.' outside of expected range" 2 "original" } } -- 2.35.3