From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id F14663858D37; Sun, 17 Mar 2024 22:10:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F14663858D37 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 F14663858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710713424; cv=none; b=rqlUFOU9twJbEw/lII14zkPt2c/iDaeaebIzn/dbBT7p4JN6PJwK5esuYmQhK4DE/Ga8kB6rMjQ4zIhVRpZ+BkxweeDGwGnFysEOV3A28autaaUWfpS7sHyARFKZ0TD/3fjPv8PqkDhm9LM/F/3vhB+UV5DYoqAQge1yQFsgX6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710713424; c=relaxed/simple; bh=YNoA9vHZNpNcI6lC8K28bshg+TlaLCxrs7mt7foWXaE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=uLkQYi8tl7YdbwHKmP3HHf2K12B2CRhTZXByuyswpt7Tn+ex52iICPpeuawe7hQ5rwmBmD1AxfJEPy6p2KESAILEMDhN8hVlXiPnDeEjlN/I2ut/T6mnJOEIZlmt+1I/88YiHXt7di08OWERL+R3tRF7QOrPBrgWPCjES7Tvxpo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1710713420; x=1711318220; i=anlauf@gmx.de; bh=27E07aT7g3wxEBb9MxxusV4gTSliKdIX+pgOtUNl54g=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=lD40mrUHjFMuERcIZ42nfr8KigosFcyCJ+QgjsEQypQIcw+TCwS3k6hodI5curEK 7SdfuOw5EPB5kqZ+cVN1k9g0QiJIikbsOacR9Vcr0k0RZnG3cv6u1xs6IRPKaj5Ah 2oUWdRCKz/V8s3fVGTvaJmlxackFs9c03oF9Il1C+hQFMg+NAWsOt4W3Ln2FGhOs3 b124Evp9iUyDbGZ0gr67KL089MgDX95SypF0CsRG6x+rehiiGshlpJNnmNKWxhVEy wzFsgAYtPgef7jo2sVGNgoM3UJ9dcUsXwGFQlaHk2iQ2BzySMwRoYNexBnZWczE/5 Hym+U9KOd1lSgBu7YA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.251.4.113]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MI5UD-1rWqAG4611-00FF0s; Sun, 17 Mar 2024 23:10:20 +0100 Message-ID: Date: Sun, 17 Mar 2024 23:10:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH, v2] Fortran: fix for absent array argument passed to optional dummy [PR101135] To: Mikael Morin , fortran , gcc-patches Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <3fd50892-dbef-d43a-8efe-148a8ffa94a9@orange.fr> <24718b24-981a-730c-4cd3-b6f4727797a0@gmx.de> <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@orange.fr> Content-Language: en-US From: Harald Anlauf In-Reply-To: <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@orange.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:g+wWIHDLzAlfAnTF6zApm1hKPdvNQ9fxyV436Yg4GBCSWs54ESr nkB8HBP0NP55wb5RasYRMeAUNqmUMch5wtRjJGI7BDtE4tYjBXePz7c/DLGSD5puYV7EyLt g2WaXOI1ldnpUV2JMgZ5YOysnnFC1maaPqgSv+V+E1X+JikDUM5kPsbYmr0hvLU9+AySuxL FaFCmpjIXLq1r35sVa9HQ== UI-OutboundReport: notjunk:1;M01:P0:wI4Y2SqOj2Q=;XyzN1IH4b6zhKYjduProep0HtpN Jt3G6TP/qLnBlouttflpmovaUtnFkgP1QvXBtRquR4l41z7rcqWXYnA9RiQSL7omqvAvxPG99 OoOLvZWhaqrnCwPuxllS5CTJ6nMwHxGSxd1Se0lSyzkvXe2D9EaliTYGMm2cysq4oXW5CPZHN DEtO6YMHM7M+T45FnxhXlr02pO6gw5uu8T2gN82/ekuIg+C33V3SzCl1KdH3AUedHridJYbWJ GREkcRoQjwfUg5pfy2T1lYrgEcxtMWBJV8xh4g9K22vqBy6MT98h/g9L2i5kokrewnJRN3/U9 PyQ+9guJ4G7032+y1ASb6zuAvg8hwVCyebW/I0k5HMOmhENUAUfktTFjH+/ChdgFivqrPNA09 3uWtIoH18akm1LBsY1GZUFWWXgKR/t3mNsNOFi89Tc7qfe7AYdK++zC0f+dqJZ5zx2GJuyymk DlHk1RtGiNIIutDe8TKoPfRK8L+23G0VTpxUO58SmD4Nq0Gmh8DlAUtWxuTfVS1gDfNmyWqao Z+gXpHzyz1TgZfZjpy+jBx+cw8ubWMMrtgkTVus09IalRGW6lVvatqc/dF0cG76pU/uDlxUEp vWkXjkUD5O1v0vAWOVwzcD5qU0benA3azgKE8w7geMu2Q8Z45ACRVMeWvoKB72aK2JCUCB46C bNj/WtBohqz+Ho7LDgDOHCCrbTfash2bDgjgEay9cRTpmRCOVNnwpENPsDTKS+9fd8yNw4K2D l4wNgS5dDH3+KIS+0CmyIhZS0gNZZtvRrNHLoLAH1xob7UCFUntR85e/5/ug7ya4Iot4czfj4 5kbMt4VwIesI/hZUndv6UeP6r40U/p7/gA1bRu0eQHsA8= X-Spam-Status: No, score=-10.8 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, On 3/17/24 22:04, Mikael Morin wrote: >> diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc >> index 3673fa40720..a7717a8107e 100644 >> --- a/gcc/fortran/trans-array.cc >> +++ b/gcc/fortran/trans-array.cc >> @@ -7526,6 +7526,17 @@ gfc_get_dataptr_offset (stmtblock_t *block, >> tree parm, tree desc, tree offset, >> >> =C2=A0=C2=A0 /* Set the target data pointer.=C2=A0 */ >> =C2=A0=C2=A0 offset =3D gfc_build_addr_expr (gfc_array_dataptr_type (de= sc), tmp); >> + >> +=C2=A0 /* Check for optional dummy argument being present.=C2=A0 Argum= ents of >> BIND(C) >> +=C2=A0=C2=A0=C2=A0=C2=A0 procedures are excepted here since they are h= andled >> differently.=C2=A0 */ >> +=C2=A0 if (expr->expr_type =3D=3D EXPR_VARIABLE >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && expr->symtree->n.sym->attr.dummy >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && expr->symtree->n.sym->attr.optional >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && !is_CFI_desc (NULL, expr)) > > I think the condition could additionally check the lack of subreferences= . > But it's maybe not worth the trouble, and the patch is conservatively > correct as is, so OK. I have thought about the conditions here for some time and did not find better ones. They need to be broad enough to catch the case in gfortran.dg/missing_optional_dummy_6a.f90 that (according to the tree-dump) was not properly handled previously and would have triggered ubsan at some point in the future when someone tried to change that testcase from currently dg-do compile to dg-do run... (After the patch it would pass, but I didn't dare to change the dg-do). I have pushed the patch as-is, but feel free to post testcases not covered (or improperly covered) to narrow this down further... > Thanks for the patch. Thanks for the review! Harald >> +=C2=A0=C2=A0=C2=A0 offset =3D build3_loc (input_location, COND_EXPR, T= REE_TYPE (offset), >> +=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_present (expr->symtree->n.sym), offset, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 fold_convert (TREE_TYPE (offset), gfc_index_zero_node)); >> + >> =C2=A0=C2=A0 gfc_conv_descriptor_data_set (block, parm, offset); >> =C2=A0} >> > >