From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by sourceware.org (Postfix) with ESMTPS id 2B84F3858D37; Sun, 17 Mar 2024 21:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B84F3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2B84F3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.12.242.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710709472; cv=none; b=ekP6q2ARX+ZG673iKK75R9RstSISVmwggL13qgVY3iBohFVFnMgYr+nvkNsYGAbPVV+X4J8aZrV3XSYHetOSg280J5jn6psBe+pOq7U0F+DyEfDDroUiyjRFNdsf/TIlFFTdeAglCAwVUhBWraqq1zF0kmXUmWrAPOBM2BMMSZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710709472; c=relaxed/simple; bh=YSv0/BJZVM2AE6FjMZZpgAF5w3TstK7B8m19iqnlURE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=lWhU5WyQ5I/DW3AiblAXYDjtDp0WnY4CrWUXSmV3O006fCXjArAC0db2hvAq3ypI/qpmrCSjS8oFMhnbjYdwRFZaaD4/vblps+jiFKO8EEjuvl36s4jjOd4EtNwa5ZxpLzMaYBQItuy+cpdjipvRPReuztWltSd5Zg2cT3jNqkM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [192.168.1.19] ([86.215.161.51]) by smtp.orange.fr with ESMTPA id lxg4r5fLh3bimlxgArr1rZ; Sun, 17 Mar 2024 22:04:29 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1710709469; bh=olhg2ymi8LTrS4pqLqD0jexiaCOlb+7LEMF++bNZmvU=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=lP5v/Kba4COYtvOsCUBPOiqpwzFJO5ur4ZC9ZoTE54RZYD7ryZ6UptFL6opAgFB9f fSh4/isA/HDucNYQSZhPKItlay2xUpjWsz2WwK5LsXRD2/1uXzXObG/b4ANbDheKe4 vDcOoeuvbXAWuetoxcRufQSvLy/Gr8IbXd+ALqOG9NnaxunReVWVMd9obyFGIQOhz7 /3z7l66sqgCpqGV8URlt7rNP6QHji68qqAJspibhbgVtmT7xgVPanAsY8I0x7EyDQK QgfTtUbxoXXITS4eHyreXaaWrekWH198Tp2EXnSXxpdrpI54fujrZNSDUDPezZFXDs vpUTY0ktU5heQ== X-ME-Helo: [192.168.1.19] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 17 Mar 2024 22:04:29 +0100 X-ME-IP: 86.215.161.51 Message-ID: <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@orange.fr> Date: Sun, 17 Mar 2024 22:04:21 +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: Harald Anlauf , fortran , gcc-patches References: <3fd50892-dbef-d43a-8efe-148a8ffa94a9@orange.fr> <24718b24-981a-730c-4cd3-b6f4727797a0@gmx.de> Content-Language: fr From: Mikael Morin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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: Le 15/03/2024 à 20:32, Harald Anlauf a écrit : > Dear all, > > as there has been some good progress in the handling of optional dummy > arguments, I looked again at this PR and a patch for it that I withdrew > as it turned out incomplete. > > It turned out that it now needs only a minor adjustment for optional > dummy arguments of procedures with bind(c) attribute so that ubsan > checking does not trigger. > > Along this way I extended the previous testcase to exercise to some > extent combinations of bind(c) and non-bind(c) procedures and found > one failure (since at least gcc-9) that is genuine: passing a missing > optional from a bind(c) procedure to an assumed-rank dummy, see > PR114355.  The corresponding test is commented in the testcase. > > Regtested on x86_64-pc-linux-gnu.  OK for mainline? > > Thanks, > Harald > (...) > > From b3079a82a220477704f8156207239e4af4103ea9 Mon Sep 17 00:00:00 2001 > From: Harald Anlauf > Date: Fri, 15 Mar 2024 20:14:07 +0100 > Subject: [PATCH] Fortran: fix for absent array argument passed to optional > dummy [PR101135] > > gcc/fortran/ChangeLog: > > PR fortran/101135 > * trans-array.cc (gfc_get_dataptr_offset): Check for optional > arguments being present before dereferencing data pointer. > > gcc/testsuite/ChangeLog: > > PR fortran/101135 > * gfortran.dg/missing_optional_dummy_6a.f90: Adjust diagnostic pattern. > * gfortran.dg/ubsan/missing_optional_dummy_8.f90: New test. > --- > gcc/fortran/trans-array.cc | 11 ++ > .../gfortran.dg/missing_optional_dummy_6a.f90 | 2 +- > .../ubsan/missing_optional_dummy_8.f90 | 108 ++++++++++++++++++ > 3 files changed, 120 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gfortran.dg/ubsan/missing_optional_dummy_8.f90 > > 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, > > /* Set the target data pointer. */ > offset = gfc_build_addr_expr (gfc_array_dataptr_type (desc), tmp); > + > + /* Check for optional dummy argument being present. Arguments of BIND(C) > + procedures are excepted here since they are handled differently. */ > + if (expr->expr_type == EXPR_VARIABLE > + && expr->symtree->n.sym->attr.dummy > + && expr->symtree->n.sym->attr.optional > + && !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. Thanks for the patch. > + offset = build3_loc (input_location, COND_EXPR, TREE_TYPE (offset), > + gfc_conv_expr_present (expr->symtree->n.sym), offset, > + fold_convert (TREE_TYPE (offset), gfc_index_zero_node)); > + > gfc_conv_descriptor_data_set (block, parm, offset); > } >