From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id 543473858D3C; Sun, 21 Jan 2024 20:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 543473858D3C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 543473858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705869673; cv=none; b=PQTYRSCrgtmEiIInlCwxiL4Uyqj4lpqTUk1dCDLdq/OOb+V5mapWCvxsKSoxdz/j3Ws2LWHeUAnom23gb0CCkfG54dsbpqsxAR3TUKIQn58U0PQvTO7dj2dScXjxaCCNY9OSw+2LA0cvSjmb5V02sPAEkKlsG6cDnuquc8IgZSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705869673; c=relaxed/simple; bh=wYwQl4w+Tn1ff1bbtdX02okWc1hSrUoOQg7DGWWI4d0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=UcgT0ZZNYO2XIsbuZJZL3ybgTc5IN/DNOuvaiiWuc2wXiS1AEKS/eQqp8sGZKrzN28ojtUBPJMc6c8c3vVk/0Lp7C8CdCQLOkTuCqzsCCqW5GffykEA7s1JzqdQxnZ3j0SYsiNYPpldG2ZOoEC8l1wn0gvtQcXKoy3LqbJ+A0jc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1705869669; x=1706474469; i=anlauf@gmx.de; bh=wYwQl4w+Tn1ff1bbtdX02okWc1hSrUoOQg7DGWWI4d0=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=MElWrIVX0K6S601M846xpt3W/mS5HjwvAuu1+flEkYGkxktH4hgtj7REcLSkQTtb hmDzW0/PbCKc/XHn6W7nm0SP/zPn/B5NzDf66J5LVq6/JgmSmxI3hsDMCcnrOHOJg +v/r1Z9UKTUO+AY7P9BEZL6voTeWEwTxNDNpypk1AKLg3In3R/j0nWpnoarG76xav SP/sU6dmv938r41Kyy5X6JWnnF8POhBB4wZXYCgaXRCSUTSzp7hCPBzgetvqVid2f 0tSge74jT1/oz11iRFETnt/w2M+M8nL1QjGMHnaIGYsuZH/pFub7ESdjXQy8Nala0 I8gvE6Lc7QFPI8OKew== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.146.63]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N6bjy-1r2u6d0MyU-0184kj; Sun, 21 Jan 2024 21:41:09 +0100 Message-ID: Date: Sun, 21 Jan 2024 21:41:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fortran: passing of optional scalar arguments with VALUE attribute [PR113377] To: Mikael Morin , fortran , gcc-patches Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <818b7f17-2d2d-476d-af31-14a0702f53bf@orange.fr> Content-Language: en-US From: Harald Anlauf In-Reply-To: <818b7f17-2d2d-476d-af31-14a0702f53bf@orange.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:EwpFiFF2sgpJL5uSUpZeH2b0dsxCXlNbRSR73j57q1ck358qonV f4SBHR/rsJxj4nGfOMSFO0hGFPmN/DxN3Oq5zBbGVPiksupjW5ST35aqsV57a4ExCRKkN1F lLeWnQOYcmg8bYowz+a8wQouae8C1pqqzifs0474Ce/wj27IOpZbF682odM6INGDECfyHUI h9Aj9nH8PZVCLnEYcyfXA== UI-OutboundReport: notjunk:1;M01:P0:LrIlOed9yFE=;WYny+o2iFsGmF/t7RWF0i27n/8L n9cBu2f7C50K6NBzir3TlrIivDgkBjMT0n9RbeJiZaa7XUCJBF7tng7OBMA3CBsFqB8G+ZuWp 0t6gUHW1zhmMLuf8k4uj2Zp8IOZ7e9mWYZHTJnvyhjixIXM/87hWEINNQESP/g7refDGlFL2M oujNN5IrJmD5yqXpE2imxSDQ1yUvEbzDkoWtf6gWbF5vUt1/C2ZxgyI0CLnkWzNGYoBFtgwnc YhUCm7x3heVp5g/2kPUOwJ3FTjFWGXxjlITzRyHcU9pI/88uZ3WVRH9JMQQ51ntMHmTFoxkwx zvtEz+HaNrqk8PC17i955B/GWoCWheFrv3kP6C08XsvJj1oqUxKdI/mpxIfjIBenthlJ8ERmT IrVOgY6Ns+3q0xKiCm0I6NsfAK8agyT4kHVlYK2yHyIE5Tbkn4H//uyXopOBGpVKquknrUzw/ O2zG8yJPmtxW8heTDwcuOrnX3mpuTW5dU5SCK0y9CVewxw1EIOM0Hb/A/VeQkb+55LgXa+lVC wncmZdAnX6tvCuKcrF2kafX1Wn/eJdB3x1VgeJoblyrv7EtZqmEbv3N8ecZCZ6JR8MMy3MpM/ 6ujGZflzC2g5tYEcUvEepp0EoHWG5Kzs39gpJgFHmRfsAhjCy48zWGTo1oH19ruih1xKm+f7+ RZ6dmtasYGTyT+orqWvulS3veGZB9hBYv062rVmuyyOAIfc1qsoPAOOnxh3NWD+erSWypJssP Y/bX27GJ+3KjXJYQ/am/RFUeqJQEx68znJrbL2owjDmXp7ypRV934ZkWHHpg672G3P7jsdQaf p4ZFOcw70fZg0iYE0usdsesR3CmbxA7iaORB1jnaQ2LwZpk1YYKb79E+9W/VLjkU9b9Mw74Qq 4JzPtyUzettmzWAeRbd+SWZzHWeX5Fo7MXWcrn1GT3aycktSTWfKqMJm2WiGdHLRiEIjP+mYf wSyc9A== X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Mikael! Am 21.01.24 um 11:50 schrieb Mikael Morin: > Hello, > > Le 20/01/2024 =C3=A0 22:58, Harald Anlauf a =C3=A9crit=C2=A0: >> Dear all, >> >> here's the first part of an attempt to fix issues with optional >> dummy arguments as actual arguments to optional dummies.=C2=A0 This pat= ch >> rectifies the case of scalar dummies with the VALUE attribute, >> which in gfortran's argument passing convention are passed on the >> stack when they are of intrinsic type, and have a hidden variable >> for the presence status. >> >> The testcase tries to cover valid combinations of actual and dummy >> argument.=C2=A0 A few tests that are not standard-conforming but would >> still work with gfortran (due to the argument passing convention) >> are left there but commented out with a pointer to the standard >> (thanks, Mikael!). >> >> Regtested on x86_64-pc-linux-gnu.=C2=A0 OK for mainline? >> > Well, not yet. > >> >> diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc >> index 9dd1f4086f4..2f47a75955c 100644 >> --- a/gcc/fortran/trans-expr.cc >> +++ b/gcc/fortran/trans-expr.cc >> @@ -6526,6 +6526,10 @@ gfc_conv_procedure_call (gfc_se * se, >> gfc_symbol * sym, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 gfc_init_se (&argse, NULL); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 argse.want_pointer =3D 1; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 gfc_conv_expr (&argse, e); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (e->symtree->n.sym->attr.dummy >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 && POINTER_TYPE_P (TREE_TYPE (argse.expr))) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 argse.expr =3D gfc_build_addr_expr (NULL= _TREE, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 argse.expr); > > The second part of the condition looks superfluous: if > argse.want_pointer was set, we can expect to get a pointer result. > > But more important, I don't understand the need for this whole part, the > new test seems to pass without it. > And here is an example that regresses with it. > > program p > =C2=A0 type :: t > =C2=A0=C2=A0=C2=A0 integer, allocatable :: c > =C2=A0 end type > =C2=A0 call s2(t()) > contains > =C2=A0 subroutine s1(a) > =C2=A0=C2=A0=C2=A0 integer, value, optional :: a > =C2=A0=C2=A0=C2=A0 if (present(a)) stop 1 > =C2=A0 end subroutine > =C2=A0 subroutine s2(a) > =C2=A0=C2=A0=C2=A0 type(t) :: a > =C2=A0=C2=A0=C2=A0 call s1(a%c) > =C2=A0 end subroutine > end program Thanks for this example! I've taken the liberty to add a slightly extended version of it to the testcase. I was taken astray by the attempt to handle the (invalid by the standard) variant of passing an absent allocatable scalar to an optional scalar dummy with the value attribute under since we use a hidden variable for the present status. Without the code above there is an unprotected pointer dereference. I think that it still could be done, but it is probably not worth it. So I followed your suggestion and removed that part. > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 cond =3D fold_convert (TREE_TYPE (argse.expr), >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 null_pointer_node); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 cond =3D fold_build2_loc (input_location, NE_E= XPR, >> @@ -7256,6 +7260,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol >> * sym, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && e->symt= ree->n.sym->attr.optional >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && (((e->r= ank !=3D 0 && elemental_proc) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || e= ->representation.length || e->ts.type =3D=3D BT_CHARACTER >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || (e->ra= nk =3D=3D 0 && e->symtree->n.sym->attr.value) > > This looks good. > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || (= e->rank !=3D 0 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 && (fsym =3D=3D NULL >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 || (fsym->as >> diff --git a/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> b/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> new file mode 100644 >> index 00000000000..495a6c00d7f >> --- /dev/null >> +++ b/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> @@ -0,0 +1,324 @@ >> +! { dg-do run } >> +! PR fortran/113377 >> +! >> +! Test passing of missing optional scalar dummies of intrinsic type >> + >> +module m_int >> +=C2=A0 implicit none >> +contains >> +=C2=A0 subroutine test_int () >> +=C2=A0=C2=A0=C2=A0 integer :: k =3D 1 >> +=C2=A0=C2=A0=C2=A0 call one=C2=A0=C2=A0=C2=A0=C2=A0 (k) >> +=C2=A0=C2=A0=C2=A0 call one_val (k) >> +=C2=A0=C2=A0=C2=A0 call one_all (k) >> +=C2=A0=C2=A0=C2=A0 call one_ptr (k) >> +=C2=A0 end >> + >> +=C2=A0 subroutine one (i, j) >> +=C2=A0=C2=A0=C2=A0 integer, intent(in)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 :: i >> +=C2=A0=C2=A0=C2=A0 integer=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ,optional :: j >> +=C2=A0=C2=A0=C2=A0 integer, allocatable :: aa >> +=C2=A0=C2=A0=C2=A0 integer, pointer=C2=A0=C2=A0=C2=A0=C2=A0 :: pp =3D>= NULL() >> +=C2=A0=C2=A0=C2=A0 if (present (j)) error stop "j is present" >> +=C2=A0=C2=A0=C2=A0 call two=C2=A0=C2=A0=C2=A0=C2=A0 (i, j) >> +=C2=A0=C2=A0=C2=A0 call two_val (i, j) >> +=C2=A0=C2=A0=C2=A0 call two=C2=A0=C2=A0=C2=A0=C2=A0 (i, aa) >> +=C2=A0=C2=A0=C2=A0 call two=C2=A0=C2=A0=C2=A0=C2=A0 (i, pp) > > To be complete, you could check two_val(i, aa) and two_val(i, pp) as wel= l. > Both seem to pass already without the patch, so not absolutely needed. > Your call. It is already contained in testcase gfortran.dg/value_optional_1.f90, (see call sub there), but then it may be helpful to have it here too. Thus added. >> +=C2=A0 end >> + > > I think the patch is OK with the first trans-expr.cc hunk removed. > Thanks. That's what I have done and pushed as r14-8317-g68862e5c75ef0e. > Mikael Thanks for the review! Harald From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id C5E523858418 for ; Sun, 21 Jan 2024 20:41:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5E523858418 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5E523858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=116.202.254.214 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705869679; cv=none; b=cGxM3RC/JD30q7YRDpGnzrUgPETpWVITWrPLw+TYxkIzJq9JXb88CsNTsPlWTJkKaXC0FYz6pry95VS1yyL/K6bfD8i3SfhilgcF3tZ4MXlYs5yvkkDYO11FMr+BeDHUclLu5LS3Fy1EbJNTE/xj/Ig8XXqx+slprh067COgfBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705869679; c=relaxed/simple; bh=MQlxW3zaxxWD6mQbOySzegfmhaQGweGG//dvvg1w2No=; h=To:From:Subject:Date:Message-ID:Mime-Version; b=RM8ncGJBbLQuNTn/eMlhK0RLpPCt7vPSbU+vyssBwT6DG2hCXZkICfxsRWUtzdaTed6Lc0+1ctiX+ECut7MlU5CZz3NUpKTfaBBDi8upu0StUkjP7KFqM03ITrXXNq5fmmIZ6ltYIWVx1y/pO5BfEnqfIHPqPt4cODNtzpFcFz4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1rRed1-0003KJ-Nm for gcc-patches@gcc.gnu.org; Sun, 21 Jan 2024 21:41:15 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [PATCH] Fortran: passing of optional scalar arguments with VALUE attribute [PR113377] Date: Sun, 21 Jan 2024 21:41:07 +0100 Message-ID: References: <818b7f17-2d2d-476d-af31-14a0702f53bf@orange.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla Thunderbird Content-Language: en-US In-Reply-To: <818b7f17-2d2d-476d-af31-14a0702f53bf@orange.fr> Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,BODY_8BITS,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20240121204107.1k4G2w599blASCcQx3J15MiAfc9LRp0jOQkha0LvodI@z> Hi Mikael! Am 21.01.24 um 11:50 schrieb Mikael Morin: > Hello, > > Le 20/01/2024 à 22:58, Harald Anlauf a écrit : >> Dear all, >> >> here's the first part of an attempt to fix issues with optional >> dummy arguments as actual arguments to optional dummies.  This patch >> rectifies the case of scalar dummies with the VALUE attribute, >> which in gfortran's argument passing convention are passed on the >> stack when they are of intrinsic type, and have a hidden variable >> for the presence status. >> >> The testcase tries to cover valid combinations of actual and dummy >> argument.  A few tests that are not standard-conforming but would >> still work with gfortran (due to the argument passing convention) >> are left there but commented out with a pointer to the standard >> (thanks, Mikael!). >> >> Regtested on x86_64-pc-linux-gnu.  OK for mainline? >> > Well, not yet. > >> >> diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc >> index 9dd1f4086f4..2f47a75955c 100644 >> --- a/gcc/fortran/trans-expr.cc >> +++ b/gcc/fortran/trans-expr.cc >> @@ -6526,6 +6526,10 @@ gfc_conv_procedure_call (gfc_se * se, >> gfc_symbol * sym, >>                  gfc_init_se (&argse, NULL); >>                  argse.want_pointer = 1; >>                  gfc_conv_expr (&argse, e); >> +                if (e->symtree->n.sym->attr.dummy >> +                && POINTER_TYPE_P (TREE_TYPE (argse.expr))) >> +                  argse.expr = gfc_build_addr_expr (NULL_TREE, >> +                                argse.expr); > > The second part of the condition looks superfluous: if > argse.want_pointer was set, we can expect to get a pointer result. > > But more important, I don't understand the need for this whole part, the > new test seems to pass without it. > And here is an example that regresses with it. > > program p >   type :: t >     integer, allocatable :: c >   end type >   call s2(t()) > contains >   subroutine s1(a) >     integer, value, optional :: a >     if (present(a)) stop 1 >   end subroutine >   subroutine s2(a) >     type(t) :: a >     call s1(a%c) >   end subroutine > end program Thanks for this example! I've taken the liberty to add a slightly extended version of it to the testcase. I was taken astray by the attempt to handle the (invalid by the standard) variant of passing an absent allocatable scalar to an optional scalar dummy with the value attribute under since we use a hidden variable for the present status. Without the code above there is an unprotected pointer dereference. I think that it still could be done, but it is probably not worth it. So I followed your suggestion and removed that part. > >>                  cond = fold_convert (TREE_TYPE (argse.expr), >>                           null_pointer_node); >>                  cond = fold_build2_loc (input_location, NE_EXPR, >> @@ -7256,6 +7260,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol >> * sym, >>            && e->symtree->n.sym->attr.optional >>            && (((e->rank != 0 && elemental_proc) >>             || e->representation.length || e->ts.type == BT_CHARACTER >> +           || (e->rank == 0 && e->symtree->n.sym->attr.value) > > This looks good. > >>             || (e->rank != 0 >>                 && (fsym == NULL >>                 || (fsym->as >> diff --git a/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> b/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> new file mode 100644 >> index 00000000000..495a6c00d7f >> --- /dev/null >> +++ b/gcc/testsuite/gfortran.dg/optional_absent_9.f90 >> @@ -0,0 +1,324 @@ >> +! { dg-do run } >> +! PR fortran/113377 >> +! >> +! Test passing of missing optional scalar dummies of intrinsic type >> + >> +module m_int >> +  implicit none >> +contains >> +  subroutine test_int () >> +    integer :: k = 1 >> +    call one     (k) >> +    call one_val (k) >> +    call one_all (k) >> +    call one_ptr (k) >> +  end >> + >> +  subroutine one (i, j) >> +    integer, intent(in)           :: i >> +    integer             ,optional :: j >> +    integer, allocatable :: aa >> +    integer, pointer     :: pp => NULL() >> +    if (present (j)) error stop "j is present" >> +    call two     (i, j) >> +    call two_val (i, j) >> +    call two     (i, aa) >> +    call two     (i, pp) > > To be complete, you could check two_val(i, aa) and two_val(i, pp) as well. > Both seem to pass already without the patch, so not absolutely needed. > Your call. It is already contained in testcase gfortran.dg/value_optional_1.f90, (see call sub there), but then it may be helpful to have it here too. Thus added. >> +  end >> + > > I think the patch is OK with the first trans-expr.cc hunk removed. > Thanks. That's what I have done and pushed as r14-8317-g68862e5c75ef0e. > Mikael Thanks for the review! Harald