From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6A4273AA8C20 for ; Thu, 17 Nov 2022 14:53:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A4273AA8C20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668696816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=75OT7IDyz+/MzbxNOi1Ksg+IIUv6lUuNLzwl03G4ScA=; b=EN88USqscXjbDPjyRCAVQLd38ELsXaqJHYi1t9D00t22K+zrFPe6YNhGH8/IHFqkTd09NW egxU0gnnhFo4pQGVu/MPSYS2wB9R02A13GvMUNGj4OgA4d2/EbUUPn5YWR2NKnFP6IREzS VHtMD6VQu0x2gTs1epSprN/DoPZ7ku4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-668-ytp8ICXdM8ShmVJGZ4I3yw-1; Thu, 17 Nov 2022 09:53:35 -0500 X-MC-Unique: ytp8ICXdM8ShmVJGZ4I3yw-1 Received: by mail-qt1-f200.google.com with SMTP id ew11-20020a05622a514b00b003a524196d31so1849151qtb.2 for ; Thu, 17 Nov 2022 06:53:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kW+KffQHBRbYsFKxIfWMChvnoXtHzhjCcoM1ahuadcI=; b=SZzgH1hBgjHoz6LvNMsNfmmyeucPwxTZLLEZzkI8NU3gKkL9LZq5/wE3dR6HfdsRbc t5yXzVYd57WXV87DT84TMY7w9HotRopbLl1QsJrb145g3LG7HBCQO2VsItbQsAfZPMF7 AyOqbAOlbfIVNqaoCuJPtvqqgmm61sraqr6B+VeQvDUc4P7jSUcTKg6HbNvKRzq8aMvA 0tsJvzyR9YGw224jkIdZkE+V196fEr2yzRGmnw1ilRtuMpWpLrqm8TjSHgHsBYFvqtff LC435jscn3jkDtdr54gTN3bPsfp1ijDj1t4T2uP7SWtUVk1E0903Eubc1oEEdwzS8EIy bijg== X-Gm-Message-State: ANoB5pmGgjL13GkUqAOvBGQ7Jdeu5LgXVeAs03bxo/hr/cJuicos+tUj SXNTgXpM2wyPzxNHbKTkYMcU57c7MtzxAKyXwB0jZ+5DkomP8G1pQc30VMrIJIb/VOlVs+nQd49 nLNu7eeOPyeKpSiQ7og== X-Received: by 2002:ad4:48d0:0:b0:4bb:7584:748d with SMTP id v16-20020ad448d0000000b004bb7584748dmr2585426qvx.117.1668696814573; Thu, 17 Nov 2022 06:53:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7VZDbfrLA9uY4Vy/LJ11D4nmiPMrl0V2WQi+XlBXooePCeq7XE4A9yo/ZDrpdbeTGI9Ce65w== X-Received: by 2002:ad4:48d0:0:b0:4bb:7584:748d with SMTP id v16-20020ad448d0000000b004bb7584748dmr2585388qvx.117.1668696814044; Thu, 17 Nov 2022 06:53:34 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id bp44-20020a05620a45ac00b006fb93acc788sm590550qkb.6.2022.11.17.06.53.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Nov 2022 06:53:33 -0800 (PST) Message-ID: <4fcd1dd6-1691-6974-f181-3c57a4c305c9@redhat.com> Date: Thu, 17 Nov 2022 09:53:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 2/5] c++: Set the locus of the function result decl To: Bernhard Reutner-Fischer Cc: gcc-patches@gcc.gnu.org, Bernhard Reutner-Fischer , Nathan Sidwell References: <20221112234543.95441-1-aldot@gcc.gnu.org> <20221112234543.95441-3-aldot@gcc.gnu.org> <20221117095647.42fefe06@nbbrfq> From: Jason Merrill In-Reply-To: <20221117095647.42fefe06@nbbrfq> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: On 11/17/22 03:56, Bernhard Reutner-Fischer wrote: > On Tue, 15 Nov 2022 18:52:41 -0500 > Jason Merrill wrote: > >> On 11/12/22 13:45, Bernhard Reutner-Fischer wrote: >>> gcc/cp/ChangeLog: >>> >>> * decl.cc (start_function): Set the result decl source location to >>> the location of the typespec. >>> >>> --- >>> Bootstrapped and regtested on x86_86-unknown-linux with no regressions. >>> Ok for trunk? >>> >>> Cc: Nathan Sidwell >>> Cc: Jason Merrill >>> --- >>> gcc/cp/decl.cc | 15 ++++++++++++++- >>> 1 file changed, 14 insertions(+), 1 deletion(-) >>> >>> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc >>> index 6e98ea35a39..ed40815e645 100644 >>> --- a/gcc/cp/decl.cc >>> +++ b/gcc/cp/decl.cc >>> @@ -17449,6 +17449,8 @@ start_function (cp_decl_specifier_seq *declspecs, >>> tree attrs) >>> { >>> tree decl1; >>> + tree result; >>> + bool ret; >> >> We now prefer to declare new variables as late as possible, usually when >> they are initialized. > > Moved. Ok like attached? Bootstrapped and regtested fine. > >>> decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs); >>> invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1); >>> @@ -17461,7 +17463,18 @@ start_function (cp_decl_specifier_seq *declspecs, >>> gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)), >>> integer_type_node)); >>> >>> - return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT); >>> + ret = start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT); >>> + >>> + /* decl1 might be ggc_freed here. */ >>> + decl1 = current_function_decl; >>> + >>> + /* Set the result decl source location to the location of the typespec. */ >>> + if (TREE_CODE (decl1) == FUNCTION_DECL >>> + && declspecs->locations[ds_type_spec] != UNKNOWN_LOCATION >>> + && (result = DECL_RESULT (decl1)) != NULL_TREE >>> + && DECL_SOURCE_LOCATION (result) == input_location) >>> + DECL_SOURCE_LOCATION (result) = declspecs->locations[ds_type_spec]; >> >> One way to handle the template case would be for the code in >> start_preparsed_function that sets DECL_RESULT to check whether decl1 is >> a template instantiation, and in that case copy the location from the >> template's DECL_RESULT, i.e. >> >> DECL_RESULT (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl1))) > > Well, that would probably work if something would set the location of > that template result decl properly, which nothing does out of the box. Hmm, it should get set by your patch, since templates go through start_function like normal functions. > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index ed7226b82f0..65d78c82a2d 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -17230,6 +17231,17 @@ start_preparsed_function (tree decl1, tree attrs, int flags) > cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl); > } > > + /* Set the result decl source location to the location of the typespec. */ > + if (DECL_RESULT (decl1) > + && !DECL_USE_TEMPLATE (decl1) > + && DECL_TEMPLATE_INFO (decl1) > + && DECL_TI_TEMPLATE (decl1) > + && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl1)) > + && DECL_RESULT (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl1)))) This condition is true only for the template definition, for which you haven't gotten to your start_function change yet. Instead, you want to copy the location for instantiations, i.e. check DECL_TEMPLATE_INSTANTIATION instead of !DECL_USE_TEMPLATE. > + DECL_SOURCE_LOCATION (DECL_RESULT (decl1)) > + = DECL_SOURCE_LOCATION ( Open paren goes on the new line. > + DECL_RESULT (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl1)))); > /* Record the decl so that the function name is defined. > If we already have a decl for this name, and it is a FUNCTION_DECL, > use the old decl. */ > > (gdb) call inform(DECL_SOURCE_LOCATION (DECL_RESULT (decl1)), "decl1 result locus before") > ../tmp4/return-narrow-2.cc:7:3: note: decl1 result locus before > 7 | { return _M_finish != 0; } > | ^ > (gdb) n > (gdb) call inform(DECL_SOURCE_LOCATION (DECL_RESULT (decl1)), "decl1 result locus from TI") > ../tmp4/return-narrow-2.cc:7:3: note: decl1 result locus from TI > (gdb) p DECL_SOURCE_LOCATION (DECL_RESULT (decl1)) > $1 = 267168 > > I'm leaving the template case alone for now, maybe i'm motivated later > on to again look at grokfndecl and/or grokmethod to fill in the proper > location. For starters i only need normal functions. > But many thanks for the hint on where the template stuff is, i thought > i would not need it at all but had hoped that there is a spot where > both declspec are at hand and something is "derived" from the templates. > >> >>> + return ret; >>> } >>> >>> /* Returns true iff an EH_SPEC_BLOCK should be created in the body of >> >