From patchwork Mon Jul 25 20:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp1870513pxt; Mon, 25 Jul 2022 13:40:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uzHZ0l+sc5EhoMdhPL0Z4S+R5YvOFGsiqhwOZxJN1kHJe6YEWPRJMDc5dff+22j5QpODMa X-Received: by 2002:a05:6402:414b:b0:43b:6b1a:c230 with SMTP id x11-20020a056402414b00b0043b6b1ac230mr15350065eda.42.1658781630210; Mon, 25 Jul 2022 13:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658781630; cv=none; d=google.com; s=arc-20160816; b=x31rgrThHTC+iBR1RgQ5Sezmhm4S+AZsABHoIIVVu7ZwYqCf9uEixwqp1n3bSmQOHP 3fr7jUOqbgTCEUH3Wz+UqOgiDjF+a/GBbg+84MkbxRa/s04ALBzZqcKVLqCr2/Mh9ldn fe18cwlIm2mlWz1vYKqHJrbnZIFai1ydxq/LSiSY+7c8qReLc2N8JdafiCp+H+BLCLld CEo3OWbiY1bSWCbqlvfbtxRxMpXm1tySA5bRdYqfNfFNreLCoZ3c6al0cqr/+OD7c4/z Jjh2mKZS3ALiKifeAiK/5X58nfrBHmklsuPcebEVGB67aZ7yuHy48AYq0dQrwEOuLFI7 uTzw== 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=vAbTsn2bH4Yd1Flj+AL7TLtnIhMuzOpEeBPbkhp2tAY=; b=J/FpFPc4AqBnzb7306d/yv5Ng0WiGheabFZNQLD0rgE75SiUB6CVeJov9VmTuNbCja iFgZIe16Yph/2UBKEsf4dJVynVvaBPVL4piZCvKxnR/rngWY7KA48809MOVp/KE1khOS nw0ye8Mg2qUGYD442JSEeAe56Q9B+V3a8jnCBPZGI0fW1j0mF00qtOb9RkEBfPf7R7dj MekV3p8nLLzON27/1gTUuQj1Fq37llj9kpPduphh8in5iAixfQLDkJ2HDRXEIxZ6Ww4t CMwggPbK2HxiOPE0WUBXz/dhSAViUYkHL2DwiZP8k38KHFhH7hx6koeOvvHoMs3BjDdH Hdbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PJqs8+WZ; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n8-20020a170906724800b0070d5a5343a3si13192962ejk.353.2022.07.25.13.40.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 13:40:30 -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=PJqs8+WZ; 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 A14EC3839C6C for ; Mon, 25 Jul 2022 20:40:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A14EC3839C6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658781623; bh=vAbTsn2bH4Yd1Flj+AL7TLtnIhMuzOpEeBPbkhp2tAY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PJqs8+WZqraz3H41HRP8lOjmH7IyJViWiu3mjoFtEQ8hrtK0Ldh8JHryEJScyZnkb ludyQxjrPinuaOup+yI+Tymn7HW5TPNm4L9SIzNLMQ4xDWf76pRi1s+E1kQil52LW3 UZRks83UCPY47HO5pvVft3/Bu/9Juz7cTk92badM= 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 9EC113839412; Mon, 25 Jul 2022 20:39:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9EC113839412 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.48] ([93.207.82.48]) by web-mail.gmx.net (3c-app-gmx-bap14.server.lan [172.19.172.84]) (via HTTP); Mon, 25 Jul 2022 22:39:37 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery from calculation of storage size of a symbol [PR103504] Date: Mon, 25 Jul 2022 22:39:37 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:grxL6cnLtSbf+wiN5nKE3Z2dLirLuBr4O7CLGRAnVRCDZz/58481+lPyEk9UHPUNMRBzq DoGTEZofMWe7jua5UVfRmVvjebWr8+2DTEIUekuRiVQHn1Qwa9AyvqWs0bdsT1iUm6BWPQ569+RA SEXlCV2XDqj2UqYEqixqRHG7tdPbwywbmx4TwIsQdQf4fa1x7hFF9SorOt72CkSt28kVYFNBZtv3 0OiU+iPRC7tV4UD4ExnLrE2fDTskxxdPesvWQ+hK1u+FjgL+nwNuT2s9YhSIrV5ZlzHgNZwGn7/R 7I= X-UI-Out-Filterresults: notjunk:1;V03:K0:01x8sCCFsOo=:tLsQN0IslhdItqGfbLRCD/ vHOelL+6VIiib4PfLTEj7qQy1CZjrPKKCGQmNMBenxGVPF7VhFqnZWWwg1Dpw4cLuzIJoB34Z BKApEML9E0BFYDsYLTT7qEKkL7SXkxQ/FtUjWa1AEoUGbZ/r5S/jKVbox0OeuQGMe23GQAZEX 08YhOJVTZOcQN2SyyfRMrEZucsGMlGYTfLR80VI4Ay71QSvGVgaiejo0YBL9+Uboef3YSBhd1 ex0eLo422e62z6rGn9Qu/0bwHEbLeeQVdUuXTE7K3wBfpSou8gnrtUZtemhQLVpogQcnZLbAi wz8YcTfZmNzEUJIrnDefjV5G6gGLt6ZRNSKTakfiojwimHggDK+9rfqIte6RbPNev5kDHYR8i 0pGDgM6v7a0Y6tQ+l8nXhfqa1RNqpCtFwGWvesdQ5IvP4wUZB/slCJpVSeV+7yv7a0sOByCp9 Lwln8oUBs284ZpVoF876+tNlcsEeN3W2mJMkra9fKLht2A2psX1lE3HCl9a0aLt28XKMk855H IzTYzKuhfYWDKDPmCci++VeIkVu0BmuTVVbc3dBNlQD1048Dc70Rd0QHda8Ops5ubjBAYzXe0 ihoumHP119HO9G9jpuZWbwO/65cb1Xy59rS4r/EKeh2gpffu6jCEwBWlqKO4ycyQGQq3fzct9 vaeNZL7vwz6mtx5vx2f3wDE4gGq41F6TibwsXFfs5nJjwrYTfbMJVRYiyFA4fNKJTMR9NGmTq /O4KLpAlP3PvZ96zxaOtqze6BNWg4xFUMiUJkDEx1AmHzYYO36dW6uSFSPtdOGHNjcdgEiUje Au37efa X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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?1739358606487616983?= X-GMAIL-MSGID: =?utf-8?q?1739358606487616983?= Dear all, we currently may ICE when array bounds of a dummy argument have a non-integer type, and the procedure with the bad declaration is referenced. The same applies to bad character length of dummies. We could simply punt in such a situation, as the causing error seems to be reliably diagnosed, see testcase. Regtested on x86_64-pc-linux-gnu. OK for mainline? This is a really safe fix and potentially backportable to other open branches. Would that be fine? Thanks, Harald From 04bea97afd7f17083774b4309ee4d3c45e278dd3 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 25 Jul 2022 22:29:50 +0200 Subject: [PATCH] Fortran: error recovery from calculation of storage size of a symbol [PR103504] gcc/fortran/ChangeLog: PR fortran/103504 * interface.cc (get_sym_storage_size): Array bounds and character length can only be of integer type. gcc/testsuite/ChangeLog: PR fortran/103504 * gfortran.dg/pr103504.f90: New test. --- gcc/fortran/interface.cc | 7 +++++-- gcc/testsuite/gfortran.dg/pr103504.f90 | 28 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr103504.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index 7ed6e13711f..71eec78259b 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -2792,7 +2792,8 @@ get_sym_storage_size (gfc_symbol *sym) if (sym->ts.type == BT_CHARACTER) { if (sym->ts.u.cl && sym->ts.u.cl->length - && sym->ts.u.cl->length->expr_type == EXPR_CONSTANT) + && sym->ts.u.cl->length->expr_type == EXPR_CONSTANT + && sym->ts.u.cl->length->ts.type == BT_INTEGER) strlen = mpz_get_ui (sym->ts.u.cl->length->value.integer); else return 0; @@ -2809,7 +2810,9 @@ get_sym_storage_size (gfc_symbol *sym) for (i = 0; i < sym->as->rank; i++) { if (sym->as->upper[i]->expr_type != EXPR_CONSTANT - || sym->as->lower[i]->expr_type != EXPR_CONSTANT) + || sym->as->lower[i]->expr_type != EXPR_CONSTANT + || sym->as->upper[i]->ts.type != BT_INTEGER + || sym->as->lower[i]->ts.type != BT_INTEGER) return 0; elements *= mpz_get_si (sym->as->upper[i]->value.integer) diff --git a/gcc/testsuite/gfortran.dg/pr103504.f90 b/gcc/testsuite/gfortran.dg/pr103504.f90 new file mode 100644 index 00000000000..607d1c6c8cc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103504.f90 @@ -0,0 +1,28 @@ +! { dg-do compile } +! PR fortran/103504 - ICE in get_sym_storage_size, at fortran/interface.c:2800 +! Contributed by G.Steinmetz + +program p + implicit none + real :: y(1) + character :: b + call s(y) + call t(y) + call u(y) + call c(b) +contains + subroutine s(x) + real :: x(abs(1.):1) ! { dg-error "must be of INTEGER type" } + end + subroutine t(x) + real :: x(abs(1.):1) ! { dg-error "must be of INTEGER type" } + end + subroutine u(x) + real :: x(1:abs(1.)) ! { dg-error "must be of INTEGER type" } + end + subroutine c(z) + character(len=abs(1.)) :: z ! { dg-error "must be of INTEGER type" } + end subroutine c +end + +! { dg-prune-output "must be of INTEGER type" } -- 2.35.3