From patchwork Thu Sep 23 19:47:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 45398 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E53EB385843E for ; Thu, 23 Sep 2021 19:48:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E53EB385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632426515; bh=nporEdc0zfVURsFGyShn/7h0/5usiKKX9AJJOKHR4eA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tqWIjEBKOyVtYrfeEJ6XEX9vD4VN7SGTFgO1pB0nKQJeHctsWf6wOm0gEVETgkAvP HZQ3lv9lLuHMiCJGngyu4nKTGTKhI31Fn7jysN8Vmh+17Ni0Yyhl9gqFzRWCPoQR0H Y/aFfNMDwdgKkQ2dbXqRJDf6v/sBzHkFaJ9lFPs0= 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 2A8633858D34; Thu, 23 Sep 2021 19:47:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A8633858D34 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.13.130] ([79.251.13.130]) by web-mail.gmx.net (3c-app-gmx-bap12.server.lan [172.19.172.82]) (via HTTP); Thu, 23 Sep 2021 21:47:47 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/102458 - ICE tree check: expected array_type, have pointer_type in gfc_conv_array_initializer, at fortran/trans-array.c:6136 Date: Thu, 23 Sep 2021 21:47:47 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:dQYWMgLPzzpd+e7Pc7N2TRiSMbDjqiJtXzPBXCXeu4feSwA44swRygSLUlYPb4gLvCCFv W9nHVHHHDTXIqt+i/dDVcYclCtwvrpRLHIjbZjxcPV8iNgFq9pGIGR7Fpc12xQo1FmDUfUyxM1R2 z1MXcgrZW8opxjUV4NSiWAiviLf6f92sfHiYvo309RBIud8Pve2g0G6c/PRIR6CpIIqsqySsEdfn OKMHwdeSa14m+NZ+2c/NyKnT+NK8R9oU0HhheR24ohfBnppJB+kHKs+BROHkaAejvLmKgsnuFEWq gI= X-UI-Out-Filterresults: notjunk:1;V03:K0:m+/17uCGFDQ=:ntnfltmV2zL7d+E7RP0sph e5mtddW42k2a+IAuSrFJ007qlrGzu90s1PJdR44cKd2Rbn5EKaipZCwYw9ei5oPP74ViQdXbc r54J9TohISDwgl9uBM0KJlDONnsl/sM+VThLDFD4j2H/beQMzohB3Y53xMvqoAlN7zSq8W2Ic RZZrWO+zD4RkapQPnbyzm8uTAtKd9DZ/CgaKZTwagIdZkZnfzWYovV1rEtlF0F6NGFEyrfpul 3kAGtwk2twZxAP2tdstRAT2HygIhXK7nPbJB/jT2lGhAHvSq2rBl5srfe0WOtTQV9BG9Rn/wB 2/KsK+tx/2uPt6G+sDAxKzaDGx/7ie1DAx74HN8DogGoVNMrLm5etn+FHoISAqj1RbjcAJ4F9 UUcA+JNkrU3/TmuKmR+Fr9xwQzwdicxAw+dJiKUyvIisf0IHelPaVJa1pJIqaWpD6S0PKshI1 lLEax2uCaCCmvPz1XsTXnUBxlTNibIRL61Z4ipPe3J8lp1uussZsxg4zRsl4Kt4D/6nNqB2yx jJ3qep1W3Hjzz1ni5EPXPLD+YIhuKt/1ePtRLIBmb0D/PleQTSm+kvum2Xx+MZHn97eAVyZQV 7/Ux1ZwhXNkIS3xOk8S6M9utCGFVYshwf3qsDGac3SqXtjSFeFIkrxqQyxz9/16w29Dh/qUhM ZxM0yR7/lctyCq1jvkyIIeCK2IdjX9ZOYgxzYjTBqCJTBO3CaVPgXCs6+109vLfr/8Q2G0A5b i/mtkQI1NP33K7/DSfXezsRCGcmK/yfuWiF4/4NnBV/nAFJXiZk/bqLrV7CkqGhFEuaXm+JTg uEyeu+n X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_STOCKGEN, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Dear Fortranners, we missed certain intrinsics as being disallowed in constant expressions, which lead to an ICE when these intrinsics were used in a specification expression with an initializer. The intrinsics in question are listed in F2018:10.1.2. As discussed in the PR, Steve recommended to omit TRANSFER from that list, as it is special and might need separate treatment. I also could not come up with a case where TRANSFER should not have simplified to a constant and we would run into an issue. (We could leave that job to Gerhard... ;-). However, in testing I encountered a case involving TRANSFER that is not properly simplified, which seems orthogonal to the present case. I would like to handle this separately. This case is mentioned in the testcase, but commented out. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald Fortran - improve checking for intrinsics allowed in constant expressions gcc/fortran/ChangeLog: PR fortran/102458 * expr.c (is_non_constant_intrinsic): Check for intrinsics excluded in constant expressions (F2018:10.1.2). (gfc_is_constant_expr): Use that check. gcc/testsuite/ChangeLog: PR fortran/102458 * gfortran.dg/pr102458.f90: New test. diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 604e63e6164..5ad1c4f9523 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -990,6 +990,34 @@ done: } +/* Standard intrinsics listed under F2018:10.1.2 (6), which are excluded in + constant expressions, except TRANSFER (c.f. item (8)), which would need + separate treatment. */ + +static bool +is_non_constant_intrinsic (gfc_expr *e) +{ + if (e->expr_type == EXPR_FUNCTION + && e->value.function.isym) + { + switch (e->value.function.isym->id) + { + case GFC_ISYM_COMMAND_ARGUMENT_COUNT: + case GFC_ISYM_GET_TEAM: + case GFC_ISYM_NULL: + case GFC_ISYM_NUM_IMAGES: + case GFC_ISYM_TEAM_NUMBER: + case GFC_ISYM_THIS_IMAGE: + return true; + + default: + return false; + } + } + return false; +} + + /* Determine if an expression is constant in the sense of F08:7.1.12. * This function expects that the expression has already been simplified. */ @@ -1023,6 +1051,10 @@ gfc_is_constant_expr (gfc_expr *e) gcc_assert (e->symtree || e->value.function.esym || e->value.function.isym); + /* Check for intrinsics excluded in constant expressions. */ + if (e->value.function.isym && is_non_constant_intrinsic (e)) + return false; + /* Call to intrinsic with at least one argument. */ if (e->value.function.isym && e->value.function.actual) { diff --git a/gcc/testsuite/gfortran.dg/pr102458.f90 b/gcc/testsuite/gfortran.dg/pr102458.f90 new file mode 100644 index 00000000000..555e4978fdb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102458.f90 @@ -0,0 +1,42 @@ +! { dg-do compile } +! { dg-options "-fcoarray=lib" } +! PR fortran/102458 - standard intrinsics excluded in constant expressions + +subroutine s1 + integer :: a(command_argument_count()) = 1 ! { dg-error "Automatic array" } + print *, a +end + +program p + block + integer :: a(get_team()) = 1 ! { dg-error "Automatic array" } + print *, a + end block +end + +subroutine s2 + integer :: a(num_images()) = 1 ! { dg-error "Automatic array" } + print *, a +end + +function f() + block + integer :: a(team_number()) = 0 ! { dg-error "Automatic array" } + a = 1 + end block +end + +subroutine s3 + integer :: a(this_image()) = 1 ! { dg-error "Automatic array" } + print *, a +end + +subroutine s4 + integer, parameter :: n = 4 + integer, parameter :: x(transfer(n, n)) = 1 ! legal + integer :: y(transfer(n, n)) = 2 ! legal + integer, parameter :: k = size (x) ! ok +! integer, parameter :: m = size (y) ! fails, tracked separately + print *, k, x, y + if (k /= size (y)) stop 1 +end