From patchwork Wed Oct 12 19:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2776155wrs; Wed, 12 Oct 2022 12:46:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EO1rvcGGWDgcAToIdoF22w5bxkWXtkQORX6xSY25hNM/k4cIV2D5cWnTbvU731UDU9V4b X-Received: by 2002:a05:6402:1d53:b0:459:7fef:f0fd with SMTP id dz19-20020a0564021d5300b004597feff0fdmr29322411edb.419.1665603988800; Wed, 12 Oct 2022 12:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665603988; cv=none; d=google.com; s=arc-20160816; b=zY5T+i5W09OJaPFrPHfY2CgV/PJK7i2vWE9z5872o7UqTTt4oilNMMVFHWQAHSQiXk AbGPwp2ri9dD9VUuq3XwyzLgeak+pXrbaCZQSgv6PSVJ8YituqAwzaMYJHJSVUhrK8yb Z0Skc4nfQkfn1sbQMRWRGtg7FdvinTIud4r613cIqHKQDtRm6yvcjuDohcXwxqDCz+Os Qy/NgOlkVWnQtT/FuumEMIfjqc8o9G4kSSLzUbsO63JNhZJ+0hcwzs49HXTvuxV4A5WA mE0wruEbiE1MD2rWVIBi3x6s6rKNrIoKyIyCGhzkodFGr9x/TmsJO2E0+O1X3i698oEe JdlQ== 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:sensitivity :importance:date:subject:to:message-id:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=RPXlGRzXbzZN0EHazkzfQ1PAYM888e3OiAEWIZ7SM+Q=; b=IDFdryPlhM1jJA0sbuYxJfuVCvULIexnVIsBlj8C4lXKl40m+A4+Kcv8BvmVyYZIrm sMIc3Mt+v8RHwU+wl06XMPuUK8/PLOdDmEZTigEhUlhCfwgyoFnedouQMVFZzTC4FgQs Yaa7ApPoNxwsxreA8tX9739Ykh8FsVnMb+wE3pqXS34tJsNLscMN62dmXC6amhLWlrOL dK+3IZXfP1xiWfHAdTlChtdw2xvxl8eBTiJ2ZsS6PWiKlpCLLRy26Td8irgcSsJyboaH nHFSHtCpiUNjxBPZnZAkdDlD3AANGtjKxIF+2mGZ1WggliGamhZhJ3A4LndgT9jM7Cqq aXDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cZL8DBP1; 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 a92-20020a509ee5000000b0045878eab247si14922786edf.193.2022.10.12.12.46.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 12:46:28 -0700 (PDT) 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=cZL8DBP1; 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 BC9EA385829B for ; Wed, 12 Oct 2022 19:46:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC9EA385829B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665603987; bh=RPXlGRzXbzZN0EHazkzfQ1PAYM888e3OiAEWIZ7SM+Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cZL8DBP1bMf/ETnYI9KfibI3rzGOdXZhXqs5lgOE90Koy7rqBeGPVd/hfXNI5VBJS IEZPskdudEWL9CFxyET2DzLMIkpLLOYtTKqFMgeaL+mnbp+rp2j4DidRsHCzCRYniK sRrya9Gzm2ub4nNAGgHSlh4YnzOCUnKrtZ+OgAik= 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.18]) by sourceware.org (Postfix) with ESMTPS id 8F1D33858D38; Wed, 12 Oct 2022 19:45:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F1D33858D38 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.84.1] ([93.207.84.1]) by web-mail.gmx.net (3c-app-gmx-bs25.server.lan [172.19.170.77]) (via HTTP); Wed, 12 Oct 2022 21:45:41 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: simplify array constructors with typespec [PR93483, PR107216, PR107219] Date: Wed, 12 Oct 2022 21:45:41 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:9HgwBO1feVipuwt88mssSnUTVG24js7oOZrjrfrAhIIplTUsa4IimEt1dWbXVqDP5LkqB +PSqA2rYa+OSoH/aEryor0K/5OZ1BdGycRcS6BvCrkNaH/MUhf+OOOe3R3ODU58fWjWhCnNEK4FF grm0yqCE4bkilr6qlm7UFzB4ezggy9VCUyUP9P4CJNIJo8aNwjVIyootv59FOuBVKkY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ICG7Cknq68zjOf7PqXRVxwVpAavV21yg Ovm5DBfwZeF5LNuqwclKpl2oRMtyXnGznOxO94hiIe494h+g0EQHg1LnQGBaPY0rgq0dEUGOl n43a9Egf+0SWaP+eHBXgSaRWqgaXdagGoyclDplzwGTqv41UlWouj0bZs/yQLNmbSMW9EUbXW kheOvrtPMKi4Mzzo6npVdHXfDzvezi5Dw257Sw8+HWKLkMpy/OCy4bCdfo/tQdKg+udk9aRig l5JznaTSluXtzuU3kuOmH0SCdHqVnPKmVJywk18q7B4zxdeFdq06qtPNWm1muTu1hzHrfhZlI MrgioJly6+Nl39S5t5MfWDONVbg+vkwd7B8duTSB7xVZBNkf9/YD51nJTwqc9FFmpaUIcz5jr Om9mLdih X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, 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?1746512367958284269?= X-GMAIL-MSGID: =?utf-8?q?1746512367958284269?= Dear Fortranners, this one was really bugging me for quite some time. We failed to properly handle (= simplify) expressions using array constructors with typespec, and with parentheses and unary '+' and '-' sprinkled here and there. When there was no typespec, there was no related problem. The underlying issue apparently was that we should simplify elements of the array constructor before attempting the type conversion. Thanks to Gerhard, who insisted by submitted many related PRs. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From ee65197f4d0b0050dc61687b5a77f1afe3bd4a27 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 12 Oct 2022 21:33:36 +0200 Subject: [PATCH] Fortran: simplify array constructors with typespec [PR93483, PR107216, PR107219] gcc/fortran/ChangeLog: PR fortran/93483 PR fortran/107216 PR fortran/107219 * array.cc (walk_array_constructor): If an element of an array constructor is an EXPR_OP, try simplification before type conversion. gcc/testsuite/ChangeLog: PR fortran/93483 PR fortran/107216 PR fortran/107219 * gfortran.dg/array_constructor_56.f90: New test. --- gcc/fortran/array.cc | 4 ++++ .../gfortran.dg/array_constructor_56.f90 | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/array_constructor_56.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index bbdb5b392fc..9bec299f160 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -1205,6 +1205,10 @@ walk_array_constructor (gfc_typespec *ts, gfc_constructor_base head) for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c)) { e = c->expr; + + if (e->expr_type == EXPR_OP) + gfc_simplify_expr (e, 0); + if (e->expr_type == EXPR_ARRAY && e->ts.type == BT_UNKNOWN && !e->ref && e->value.constructor) { diff --git a/gcc/testsuite/gfortran.dg/array_constructor_56.f90 b/gcc/testsuite/gfortran.dg/array_constructor_56.f90 new file mode 100644 index 00000000000..4701fb36225 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_56.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! +! Test the fix for the following: +! PR fortran/93483 +! PR fortran/107216 +! PR fortran/107219 +! +! Contributed by G.Steinmetz + +program p + real, parameter :: r0(*) = +[real :: +(1) ] + real, parameter :: r1(*) = +[real :: +[1] ] + real, parameter :: r2(*) = -[real :: [(1)]] + real, parameter :: r3(*) = +[real :: [-(1)]] + real, parameter :: r4(*) = -[real :: [[(1)]]] + real, parameter :: r5(*) = -[real :: -[1, 2]] + real, parameter :: r6(*) = +[real :: +[1, 2]] + real, parameter :: r7(*) = [real :: 1, 2] * [real :: 1, (2)] + real, parameter :: r8(*) = [real :: 1, (2)] * [real :: 1, 2] + real, parameter :: r9(*) = +[real :: 1, 2] * [real :: 1, (2)] + real, parameter :: rr(*) = -[real :: 1, (2)] * [real :: 1, 2] +end -- 2.35.3