From patchwork Sat Dec 17 21:21:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 34270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1677554wrn; Sat, 17 Dec 2022 13:22:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7outUO30RS5i/gxU5+lX43WYsya3DLy3Kk4CtKI1F3JakmPgDv19468gSGsa/BHvyqkzlU X-Received: by 2002:a05:6402:43c7:b0:46c:e558:ce60 with SMTP id p7-20020a05640243c700b0046ce558ce60mr30851709edc.22.1671312140145; Sat, 17 Dec 2022 13:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671312140; cv=none; d=google.com; s=arc-20160816; b=WSJTmrsDNDPe3bItB6d812YwMeqN8Ws+i+SOxiy9w/xNUxgFsWpvX38Yjk+3oeccuz yUQMXxNdC0oTTcWxf9FD1M/NxEd6SANktsrUwc2dRRhCsCFLpc6uS2vhxy+dFLFTrg32 +S+oZwUN1Uq7mOCxaquWEq3J6xHAL7pPYKuwHYYtNGw2i7/MjQzAwdLcCOQf7VWIMIT8 BgxOFO8Nk5R8puyBM+j1c+lh8tQLyvFwJBfhZ0LJE38MA573Dj+w1KA523CZP32eHAki zy6uq4l6zh5HcZNr0aL1/I0QL0URRn+6t/huh9AVr5CE9h7zr7TvmE12+3VQtYlf2u09 ofNA== 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=Ds+yDagAhjPstiKY/nEURMJb6AG11YmTDmZxD+6q71o=; b=V+D9/VcG10aHGGbS7cORf1uDENXE6pxI2Dwd6p+SCWQBPxODUTTpoMIIdPOYjoEdyX qq2BSdBT57x87TUqGxz+9a16Y+CdXPkVQKavxTsmsCbtdKgz3wAzEFA2EtUEl5fNYw63 5BGz77H/BwVUtFhHzButmu/28f+j46UHrsmkjFFxN8HIR5IIAQI0crocid3lIvve96uS vJie80ussPZGmuZLC/ZNvo6LnfPIChqzm+SqeeaB81GtXEEGEtmuR06e0g6Pefen+jws Zfg/7rcktiBiV5KGv6NYIZV0M1glRpnwK0wGYSo7r8SrnEQH+91tTthBsbJmL5LRPKKR DiAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pv2yF39b; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l15-20020a056402254f00b0046ab9b37cf2si6774821edb.116.2022.12.17.13.22.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 13:22:20 -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=@gcc.gnu.org header.s=default header.b=pv2yF39b; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B7A8385D0E2 for ; Sat, 17 Dec 2022 21:22:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B7A8385D0E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671312139; bh=Ds+yDagAhjPstiKY/nEURMJb6AG11YmTDmZxD+6q71o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pv2yF39bUUK/SdJsWqYNGGVzLoRNkFsdRDBKBRAYuM15zGft/3VCslX+VNzXiQdjt 4DLEaqgfxFXbLkftTKG6zRqOuaGadwXClTSIqs2vjOwy+cJ4id9dImGipawXhMvPqT hHHMBdJxk0miuc9jog47zTPcxf4YyXYdQWOmdzII= 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 C45F03858439; Sat, 17 Dec 2022 21:21:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C45F03858439 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.13.33] ([79.251.13.33]) by web-mail.gmx.net (3c-app-gmx-bap49.server.lan [172.19.172.119]) (via HTTP); Sat, 17 Dec 2022 22:21:17 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: incorrect array bounds when bound intrinsic used in decl [PR108131] Date: Sat, 17 Dec 2022 22:21:17 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:0FYlBggyjCYloL1s0/ZIf425SGPuCSuov51l668CT2VL0RvcIz6b7eKY2KBt9QFXfQcwg 5avKk3Z8lOI+r+Xj+QBqzpiX3XvO7AJoLwq8UwibKfDK1owKOTs/8sLBfIA+hZ/Wwbyt8W6VNJMa fWC3bVHw6DobhLtlbEzBrflK9kKjKyTFuPekNw99EESkT9ZQVL6yFdSdQ0P+zIw4l+5sjOuE/YjJ 5zVI+RdoOr/NAI5r7g80JPt6re1e650eYlbHQyC8BggTIiF6LCGlb84tyK62BRJUHfUiedJ6mmF6 rs= UI-OutboundReport: notjunk:1;M01:P0:qoYqXaIF+hg=;ZCRVCYRD8nkS/Vv78S0WpXCGHfA 47KzvytQ8i27rPcwBInJR587/Ey6TbNItU11tIT7EvLHp96h70djSdu3Yntz+In0AWlQnA8DJ lMyE1r9P3+Q8GD/B+r4O6zRV0Jg4w3oJvWbl83FQmA3lZEYGbLh7wdLexNEn3XahlOVRbHFbK /sn8mdeRtumnVTsH++KAlJXIQbfzoHGmOvovmPTz4Aqtq15smL/xAJ51Uc+w+DvUsN8wxMR/I 5QBRtTEeUfqUOUOHliB0SekLb1GD6rP41VmB8BPJRrWfJVngt3jFWAcapjYVXTDFEHV3O5t1Q +8Rshz575Fqh4UMc5lGatZOuKT9Vmj4bZJP5L/1FTLNLzYMhfgiq1A5apZpWbif+DbEcitOmH 3QDGU0HUHCTpp6m0wGzwrQpS2k2fSgRuAqi5TqdTAtdyczGsI4x/FxTN4wUT1E0braX2ZCXV6 6lOH0f3ao0wuLBmkyp9lBRKpSXdGxiALPGXn+FeXCieH5m36lyI/Pso5Kta3A709Hoizlkc/j KuO5hMje9B8tTK8fyT2qkSXcjgtm6sOaRpA0WwScnYDwJ5uMwdcUeSHpM6wRtmNOim119KHwH KhVgX8vG7/EfvbTQTdIP28GGL4VazVjtL6MUSt72KsF79dDYNsJbjfjIgmkHRXXVz2xbLHiaW Nveux3KmXzX1sBl35tVluiqpY9UAO+b9Q7KohNO9vTQhkgpOdYwlA+vfYXFlrK+TQlvVc0AxG MgmBUPANkZPVLbZrQyw2umR46CVjFiQ6/dHW6iYgMTUpIsNNfT0i0WY2c/j5CnZe2YAK3gDPW mhnqgp7OvUxyVzsx/AOVdb/g== X-Spam-Status: No, score=-13.4 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_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?1752497798636014029?= X-GMAIL-MSGID: =?utf-8?q?1752497798636014029?= Dear all, the previous fix for pr103505 introduced a regression that could lead to wrong array bounds when LBOUND/UBOUND were used in the array spec of a declaration. The reason was that we tried to simplify too early the array element spec, which appears to have interfered with the subtle semantics of the bound intrinsics. The solution is to undo the fix for pr103505. It turns out that there are other code changes in place that were put in place to fix related ICEs, and which handle that one, too, and only lead to a change of the emitted error diagnostics. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this is a 10/11/12/13 regression, I would like to backport as seems fit. Thanks, Harald From 531be0753352ec30c4b1e24591ec3e0c33cd4409 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 17 Dec 2022 22:04:32 +0100 Subject: [PATCH] Fortran: incorrect array bounds when bound intrinsic used in decl [PR108131] gcc/fortran/ChangeLog: PR fortran/108131 * array.cc (match_array_element_spec): Avoid too early simplification of matched array element specs that can lead to a misinterpretation when used as array bounds in array declarations. gcc/testsuite/ChangeLog: PR fortran/108131 * gfortran.dg/pr103505.f90: Adjust expected patterns. * gfortran.dg/pr108131.f90: New test. --- gcc/fortran/array.cc | 4 ---- gcc/testsuite/gfortran.dg/pr103505.f90 | 8 +++++--- gcc/testsuite/gfortran.dg/pr108131.f90 | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108131.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 10d9e0c5354..7457c03e6cd 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -512,8 +512,6 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; - gfc_try_simplify_expr (*upper, 0); - if (((*upper)->expr_type == EXPR_CONSTANT && (*upper)->ts.type != BT_INTEGER) || ((*upper)->expr_type == EXPR_FUNCTION @@ -546,8 +544,6 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; - gfc_try_simplify_expr (*upper, 0); - if (((*upper)->expr_type == EXPR_CONSTANT && (*upper)->ts.type != BT_INTEGER) || ((*upper)->expr_type == EXPR_FUNCTION diff --git a/gcc/testsuite/gfortran.dg/pr103505.f90 b/gcc/testsuite/gfortran.dg/pr103505.f90 index 522e53efcb2..01308019b2c 100644 --- a/gcc/testsuite/gfortran.dg/pr103505.f90 +++ b/gcc/testsuite/gfortran.dg/pr103505.f90 @@ -3,7 +3,9 @@ ! Testcase by G.Steinmetz program p - integer, parameter :: a((2.)) = [4,8] ! { dg-error "scalar INTEGER" } - integer, parameter :: z(1:(2.)) = [4,8] ! { dg-error "scalar INTEGER" } - print *, a(1:1) ! { dg-error "Syntax error" } + integer, parameter :: a((2.)) = [4,8] ! { dg-error "INTEGER type" } + integer, parameter :: z(1:(2.)) = [4,8] ! { dg-error "INTEGER type" } + print *, a(1:1) end + +! { dg-prune-output "Parameter array" } diff --git a/gcc/testsuite/gfortran.dg/pr108131.f90 b/gcc/testsuite/gfortran.dg/pr108131.f90 new file mode 100644 index 00000000000..4a3c467f73a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108131.f90 @@ -0,0 +1,25 @@ +! { dg-do run } +! { dg-additional-options "-fdump-tree-original" } +! PR fortran/108131 +! +! Incorrect array bounds when bound intrinsic used in declaration + +program test + implicit none + integer, parameter :: mg(7:10) = 0 + integer, parameter :: u = ubound(mg, dim=1) + integer, parameter :: cx(-1:ubound(mg, dim=1)) = 1 + integer, parameter :: dx(lbound(mg, dim=1):ubound(mg, dim=1)) = 2 + + write(*,*) ubound(mg, dim=1) + write(*,*) ubound(cx, dim=1) + if (u /= 10) stop 1 + if (ubound(mg, dim=1) /= 10) stop 2 + if (ubound(cx, dim=1) /= 10) stop 3 + if (ubound(dx, dim=1) /= 10) stop 4 + if (lbound(mg, dim=1) /= 7) stop 5 + if (lbound(cx, dim=1) /= -1) stop 6 + if (lbound(dx, dim=1) /= 7) stop 7 +end program test + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } } -- 2.35.3