From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from msa.smtpout.orange.fr (smtp-76.smtpout.orange.fr [80.12.242.76]) by sourceware.org (Postfix) with ESMTPS id EA4123858C98; Mon, 18 Mar 2024 18:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA4123858C98 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 EA4123858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.12.242.76 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710787639; cv=none; b=rN5uesrx989Ns+VJIQTvK1rYvfTJQZXryydmP+UG372/l5dPtseRND/v4NY9GY6MQ/u51dVaSYGTkZ9t+NRuki7evoqf5J4duVSVaPCJ8SQTPXGPnN3lUkJn54gJMq/rw10uDCA3OaqlrVrLIK0PVrRaqoRLFZhxgRCWwx9z6rA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710787639; c=relaxed/simple; bh=LCVFHnVb62wX74kvPjY1F7j7mRmQNxQYF9TLTtyISB8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=l//a1Qm4+s+6y4CMJgGWw1hGWDqWAHOLgKsYHUiD2VCk4qcq72c2kk1/BpeXOI0BUPYsYb2A5eEcFYwCmycEO+7tkSDjcxnUWF/pgmu9hr9Is4Hu0Y20dFIMun1jIfzG0eU98MzyaxjHLzjglbofX60MPJPba4isUOcOTHMxsMw= 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 mI0xrdUUKBnpimI0xrWqiH; Mon, 18 Mar 2024 19:47:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1710787636; bh=W/TBmXzWrfT7l8ich8YEhAio51N8iFB3O/zpfyZAjoA=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=YJB71hCjuSzt8DAMVxBh8ZGZdwZR0oCMCizsisl3ikdvy3K86/U9+ZMW1glFfIbYl lzpmG0SFydBkgAFTOSxAbzO9w32jESUFeHEm2aRpHAdKxe9xe8FhFuIYCJ00jQ4jyo OtPXFIfNtBL5NeAFwPK1x+q5YXr3rNZtPShAlzCeYP4+xvlCwEbA/F8cv3SZZ7Lfge zB5IrKz+bCt/1quFAFmF0MaYydXVlR/08ovhtAwiSaE7utsrXsqIhg9d7x3l80nd2V sCfjPFWL35tOjds2zkXPegSSRY2zCkWF2WkoRGc26O8gSWqHqHllGk0GbtCtZZ9l2r flkng1xFKqBrw== X-ME-Helo: [192.168.1.19] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Mon, 18 Mar 2024 19:47:16 +0100 X-ME-IP: 86.215.161.51 Message-ID: Date: Mon, 18 Mar 2024 19:47:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH, v2] Fortran: fix for absent array argument passed to optional dummy [PR101135] Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: <3fd50892-dbef-d43a-8efe-148a8ffa94a9@orange.fr> <24718b24-981a-730c-4cd3-b6f4727797a0@gmx.de> <2b9052c6-43b2-4c7e-b905-e1ceaa52cb94@orange.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=-9.6 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_NONE,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 17/03/2024 à 23:10, Harald Anlauf a écrit : > 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... No problem, as said it is conservatively correct. > (After the patch it would pass, but I didn't dare to change the dg-do). > Did it include cases not covered by the new testcase (which was quite complete already)? > I have pushed the patch as-is, but feel free to post testcases > not covered (or improperly covered) to narrow this down further... > The case I had in mind would only be a missed optimization, and probably not that important, so let's move on.