From patchwork Sun Mar 17 21:26:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1057592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498017-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="t5dYHsqm"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Msp22SLLz9s6w for ; Mon, 18 Mar 2019 08:26:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=VZjuQCpnQb/yj+vtucnmhS2z8zzBTO1CTtVZTh0Yp87keG t6+0dyHnLAeh11HHAA4CaGFyooqwSEcz9GdKExiWkpATs41PLcwPOFFXHk0sVwH0 /xWQg/yrnWS1t1ePkiy23o76n2vK/3dKTeMK157BCSpRvg2NVvu4FijRQViW4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=+4aOOAxKyEYwouzkKe6iotyR+Uw=; b=t5dYHsqmnjwP5AQTyFJS sGXKBngbi7OpvCE/JNc7H4dvaLYTColFyUmWn3YglgCYFED8UNVufH24TuIHrIkd qL9j+ccREJsXJRZHnBWJaWaonys56nqCPVOVH9srqPJ+tABNkJsEoXpabiXXnW4W HYN4w5s+c/cKKHU4mP7Feeo= Received: (qmail 50369 invoked by alias); 17 Mar 2019 21:26:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 50351 invoked by uid 89); 17 Mar 2019 21:26:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Provags-ID:V03, H*M:gmx, TRANSFER, H*MI:gmx X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.22) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 17 Mar 2019 21:26:29 +0000 Received: from proton.at.home ([93.207.95.16]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LkSOt-1gToJH36Ed-00cR4y; Sun, 17 Mar 2019 22:26:24 +0100 Message-ID: <5C8EBB7F.90305@gmx.de> Date: Sun, 17 Mar 2019 22:26:23 +0100 From: Harald Anlauf User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: gfortran , gcc-patches Subject: [PR fortran/85797, patch] - ICE in gfc_element_size, at fortran/target-memory.c:126 The attached patch fixes an ICE-on-invalid code when the TRANSFER intrinsic is being handed procedures to the SOURCE or MOLD arguments. My reading of the standard suggests that this is not allowed: SOURCE shall be a scalar or array of any type. MOLD shall be a scalar or array of any type. ... I was struggling for some moment with the idea that SOURCE could be a procedure pointer (technically), but finally dismissed it. The patch thus rejects procedures as arguments. Regtests cleanly on x86_64-pc-linux-gnu. OK for trunk? Harald 2019-03-17 Harald Anlauf PR fortran/85797 * check.c (gfc_check_transfer): Reject procedures as actual arguments for SOURCE and MOLD of TRANSFER intrinsic. 2019-03-17 Harald Anlauf PR fortran/85797 * gfortran.dg/pr85797.f90: New test. Index: gcc/testsuite/gfortran.dg/pr85797.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr85797.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr85797.f90 (working copy) @@ -0,0 +1,22 @@ +! { dg-do compile } +! PR fortran/85797 - ICE in gfc_element_size, at fortran/target-memory.c:126 +! Derived from original test cases by Gerhard Steinmetz + +module test +contains + function f () + f = 1. + end function f + subroutine sub () + end subroutine sub + recursive subroutine a () + integer(8) :: p + procedure(sub), pointer :: x => sub + p = transfer (sub, p) ! { dg-error "must not be a PROCEDURE" } + p = transfer (p, sub) ! { dg-error "must not be a PROCEDURE" } + p = transfer (f, p) ! { dg-error "must not be a PROCEDURE" } + p = transfer (p, f) ! { dg-error "must not be a PROCEDURE" } + c = transfer (a, b) ! { dg-error "must not be a PROCEDURE" } + print *, transfer (x, x) ! { dg-error "must not be a PROCEDURE" } + end subroutine a +end module test Index: gcc/fortran/check.c =================================================================== --- gcc/fortran/check.c (revision 269717) +++ gcc/fortran/check.c (working copy) @@ -5544,6 +5544,24 @@ size_t source_size; size_t result_size; + /* SOURCE shall be a scalar or array of any type. */ + if (source->ts.type == BT_PROCEDURE) + { + gfc_error ("% argument of % intrinsic at %L " + "must not be a %s", &source->where, + gfc_basic_typename (source->ts.type)); + return false; + } + + /* MOLD shall be a scalar or array of any type. */ + if (mold->ts.type == BT_PROCEDURE) + { + gfc_error ("% argument of % intrinsic at %L " + "must not be a %s", &mold->where, + gfc_basic_typename (mold->ts.type)); + return false; + } + if (mold->ts.type == BT_HOLLERITH) { gfc_error ("% argument of % intrinsic at %L must not be" @@ -5551,6 +5569,8 @@ return false; } + /* SIZE (optional) shall be an integer scalar. The corresponding actual + argument shall not be an optional dummy argument. */ if (size != NULL) { if (!type_check (size, 2, BT_INTEGER))