From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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] Content-Type: multipart/mixed; boundary=rekceb-bf45b63f-f1f1-46a3-8f93-0012cc64eea3 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 List-Id: --rekceb-bf45b63f-f1f1-46a3-8f93-0012cc64eea3 Content-Type: text/plain; charset=UTF-8 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 --rekceb-bf45b63f-f1f1-46a3-8f93-0012cc64eea3 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr30802-part2.diff Content-Transfer-Encoding: quoted-printable =46rom 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 mes= sage [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. =2D-- 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 =2D-- 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, t= ree index, int n, tree descriptor; char *msg; const char * name =3D NULL; + char *var_name =3D 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, t= ree index, int n, name =3D ss->info->expr->symtree->n.sym->name; gcc_assert (name !=3D NULL); + /* When we have a component ref, compile name for the array section. + Note that there can only be one part ref. */ + expr =3D ss->info->expr; + if (expr->ref && !compname) + { + len =3D strlen (name) + 1; + + /* Find a safe length. */ + for (ref =3D expr->ref; ref; ref =3D ref->next) + if (ref->type =3D=3D REF_COMPONENT) + len +=3D 2 + strlen (ref->u.c.component->name); + + var_name =3D XALLOCAVEC (char, len); + strcpy (var_name, name); + + for (ref =3D expr->ref; ref; ref =3D ref->next) + { + /* Append component name. */ + if (ref->type =3D=3D REF_COMPONENT) + { + strcat (var_name, "%%"); + strcat (var_name, ref->u.c.component->name); + continue; + } + if (ref->type =3D=3D REF_ARRAY && ref->u.ar.type =3D=3D AR_SECTION) + break; + } + name =3D var_name; + } + if (VAR_P (descriptor)) name =3D IDENTIFIER_POINTER (DECL_NAME (descriptor)); diff --git a/gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 b/gcc/tests= uite/gfortran.dg/bounds_check_fail_8.f90 new file mode 100644 index 00000000000..3397e953ba6 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_fail_8.f90 @@ -0,0 +1,35 @@ +! { dg-do compile } +! { dg-additional-options "-fcheck=3Dbounds -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 her= e. + +program test + implicit none + integer :: k =3D 0 + type t + real, dimension(10,20,30) :: z =3D 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 ran= ge" 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 ran= ge" 2 "original" } } +! { dg-final { scan-tree-dump-times "'y2%%vv.' outside of expected range"= 2 "original" } } =2D- 2.35.3 --rekceb-bf45b63f-f1f1-46a3-8f93-0012cc64eea3--