From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp10.smtpout.orange.fr [80.12.242.132]) by sourceware.org (Postfix) with ESMTPS id 0706C3858D20 for ; Fri, 4 Feb 2022 10:45:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0706C3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orange.fr Received: from [192.168.1.17] ([86.253.179.215]) by smtp.orange.fr with ESMTPA id Fw5gnojaAIz5VFw5nnaNmS; Fri, 04 Feb 2022 11:45:28 +0100 X-ME-Helo: [192.168.1.17] X-ME-Auth: MDU4MTIxYWM4YWI0ZGE4ZTUwZWZmNTExZmI2ZWZlMThkM2ZhYiE5OWRkOGM= X-ME-Date: Fri, 04 Feb 2022 11:45:28 +0100 X-ME-IP: 86.253.179.215 Message-ID: <3fd50892-dbef-d43a-8efe-148a8ffa94a9@orange.fr> Date: Fri, 4 Feb 2022 11:45:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH] PR/101135 - Load of null pointer when passing absent assumed-shape array argument for an optional dummy argument Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: From: Mikael Morin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Feb 2022 10:45:32 -0000 Hello, Le 29/01/2022 à 22:41, Harald Anlauf via Fortran a écrit : > Dear Fortranners, > > compiling with -fsanitize=undefined shows that we did mishandle the > case where a missing optional argument is passed to another procedure. > > Besides the example given in the PR, the existing testcase > fortran.dg/missing_optional_dummy_6a.f90 fails with: > > gcc/testsuite/gfortran.dg/missing_optional_dummy_6a.f90:21:29: runtime error: load of null pointer of type 'integer(kind=4)' > gcc/testsuite/gfortran.dg/missing_optional_dummy_6a.f90:22:30: runtime error: load of null pointer of type 'integer(kind=4)' > gcc/testsuite/gfortran.dg/missing_optional_dummy_6a.f90:27:29: runtime error: load of null pointer of type 'integer(kind=4)' > > The least invasive change - already pointed out by the reporter - is > to check the presence of the argument before dereferencing the data > pointer after the offset calculation. This requires adjusting the > checking pattern for gfortran.dg/missing_optional_dummy_6a.f90. > > Regtesting reminded me that procedures with bind(c) attribute are doing > their own stuff, which is why they need to be excluded here, otherwise > testcase bind-c-contiguous-4.f90 would regress on the expected output. > > I've created a testcase that uses this PR's input as well as the lesson > learned from studying the bind(c) testcase and placed this in the asan > subdirectory. > > There is a potential alternative solution which I did not pursue, as I > think it is more invasive, but also that I didn't succeed to implement: > A non-present dummy array argument should not need to get its descriptor > set up. Pursuing this is probably not the right thing to do during the > current stage of development and could be implemented later. If somebody > believes this is important, feel free to open a PR for this. > I have an other (equally unimportant) concern that it may create an unnecessary conditional when passing a subobject of an optional argument. In that case we can assume that the optional is present. It’s not a correctness issue, so let’s not bother at this stage. > Regtested on x86_64-pc-linux-gnu. OK for mainline? > OK. Thanks.