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 20AEB3858429 for ; Sun, 17 Mar 2024 22:10:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20AEB3858429 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 20AEB3858429 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=1710713429; cv=none; b=PtQnem42fcXVuLMd0QOLU+0mXCldsDRQWPOLy7raAopaxhX63XKZpJWIs5flMJVLErjLqs9hGS8Yl98NzR4yM23S0digX1Zz1CFvDSfMyplJ2b9AhoXcrL8MO++6xjcOh34cTGE4TvMGc+EPgG3D0i4v7iUlnqLWkCQjLZ+1SgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710713429; c=relaxed/simple; bh=U+PUTseR+mX8ZVawtDuC1mifNblIO7m90ShbA6F4XsI=; h=To:From:Subject:Date:Message-ID:Mime-Version; b=gf1xh0e+KM2Y8EZC1BlF8Tfkq4nztDhFo5br3GiHCnLWt2gsUMzCTMT8t7oCUDAZqj9ZrpyaqQGHXqqMHxpzUZocFH3Fj3FhXE4kNvHN/MR2PmTi2nPQtv76Kw2XVRwO2/H81dnsbe28mxX+vWjzxJYwEu20BdEMsrdbjnGsQxQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1rlyi1-00057U-QC for gcc-patches@gcc.gnu.org; Sun, 17 Mar 2024 23:10:26 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [PATCH, v2] Fortran: fix for absent array argument passed to optional dummy [PR101135] Date: Sun, 17 Mar 2024 23:10:18 +0100 Message-ID: References: <3fd50892-dbef-d43a-8efe-148a8ffa94a9@orange.fr> <24718b24-981a-730c-4cd3-b6f4727797a0@gmx.de> <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@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: <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@orange.fr> Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-7.6 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: <20240317221018.jbJZbMTiisF90UkLngYfCuS149aeBHrMjXkrAM35K-c@z> 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, >> >>    /* 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. 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 >> +    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); >>  } >> > >