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 B26033852C4F for ; Fri, 18 Nov 2022 16:06:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B26033852C4F 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=1668787596; 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=lYPj9qsYb9SXc5vqXd+bmI/hXViUnno3OCAFZFQbETc=; b=IJutwKxBVjIUkTL6/+1VChX+2yTIvtHI8qOBfiyCFABRuxcLxncng4f0EIBC4CcN/mDsKb gQf2ynJH+7ITkigXJeo1mk6j2XSpdtZF8thJikbM+qXJyYz6doGaqawNeVQw1tLOK4KcEM sNWsws7wyvDEkcjgUWqd8uVJhxnbfnI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-652-WnRs7bGtNhWZG7hvF0jvtw-1; Fri, 18 Nov 2022 11:06:32 -0500 X-MC-Unique: WnRs7bGtNhWZG7hvF0jvtw-1 Received: by mail-qt1-f198.google.com with SMTP id u31-20020a05622a199f00b003a51fa90654so5242528qtc.19 for ; Fri, 18 Nov 2022 08:06:32 -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=lYPj9qsYb9SXc5vqXd+bmI/hXViUnno3OCAFZFQbETc=; b=3TNENNK6OVdd08dmdLXQCCixqOTY+fDpPdLe8YWcDIDdX3oJpLg5BqUDtyEbHdJJ48 yGxX4V2KIlqg9BLYK3016/P8IGCnOqLl5BF3Z4ivTpRXrNUh4CBTgE8/oMKnJhpIs6fa f3eXrUM/HthMYiDbOeZKPUZM78pb0fYGD761gxSMiMT4HnScLORuhg4MX/y5fBYMDP3M 1G49uzLh4oXfbunSYonKOwFBbb1RtNrWpXDdW8hCgieA4XGIgCbE73iShKhZQgwK6Bl9 2EfXcM5Oqzv1By8w2s6SbT/Q55ioCCQkArwYePHctpYOK3Fq3qWN10UaKySPt3iPRMqi Fytg== X-Gm-Message-State: ANoB5pkGQL7UaVnWUi42HwapGoCqrbdatBTZI7IFv+WzSyXNKRvbQbcW Fw36KOBKy1EunHXZtoe8T1MRDquuUlRJK4Bdmrqi3TmieKnQWmWGl0YYa6rCA5iPn9XDW7Vxhpa haPbSjqTYAu+Akw+7kw== X-Received: by 2002:a0c:9b09:0:b0:4c6:10ee:b758 with SMTP id b9-20020a0c9b09000000b004c610eeb758mr7172095qve.130.1668787592259; Fri, 18 Nov 2022 08:06:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ATLRyhfF5BHG7xCOcEI/Xx95xgzYgqj/eGeVqH1qNquPR2lshYvtxmTQ5CRuQ1PJ3RebF6A== X-Received: by 2002:a0c:9b09:0:b0:4c6:10ee:b758 with SMTP id b9-20020a0c9b09000000b004c610eeb758mr7172064qve.130.1668787591922; Fri, 18 Nov 2022 08:06:31 -0800 (PST) Received: from [192.168.1.130] (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 k11-20020a05620a0b8b00b006fbdb9d04b1sm473424qkh.40.2022.11.18.08.06.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 08:06:30 -0800 (PST) Message-ID: <3e8757c8-cb16-9446-6953-5d6de9deeb5b@redhat.com> Date: Fri, 18 Nov 2022 11:06:29 -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> <4fcd1dd6-1691-6974-f181-3c57a4c305c9@redhat.com> <20221117200208.3048de7a@nbbrfq> <8b923e25-db47-4d68-504f-6b3c664349c7@redhat.com> <20221118114938.48a39cbd@nbbrfq> From: Jason Merrill In-Reply-To: <20221118114938.48a39cbd@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: 8bit X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,WEIRD_PORT 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/18/22 05:49, Bernhard Reutner-Fischer wrote: > On Thu, 17 Nov 2022 18:52:36 -0500 > Jason Merrill wrote: > >> On 11/17/22 14:02, Bernhard Reutner-Fischer wrote: >>> On Thu, 17 Nov 2022 09:53:32 -0500 >>> Jason Merrill wrote: > >>>> Instead, you want to copy the location for instantiations, i.e. check >>>> DECL_TEMPLATE_INSTANTIATION instead of !DECL_USE_TEMPLATE. >>> >>> No, that makes no difference. >> >> Hmm, when I stop there when processing the instantiation the template's >> DECL_RESULT has the right location information, e.g. for >> >> template int f() { return 42; } >> >> int main() >> { >> f(); >> } >> >> #1 0x0000000000f950e8 in instantiate_body (pattern=> 0x7ffff7ff5080 f>, args=, d=> 0x7fffe971e600 f>, nested_p=false) at /home/jason/gt/gcc/cp/pt.cc:26470 >> #0 start_preparsed_function (decl1=, >> attrs=, flags=1) at /home/jason/gt/gcc/cp/decl.cc:17252 >> (gdb) p expand_location (input_location) >> $13 = {file = 0x4962370 "wa.C", line = 1, column = 24, data = 0x0, sysp >> = false} >> (gdb) p expand_location (DECL_SOURCE_LOCATION (DECL_RESULT >> (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl1))))) >> $14 = {file = 0x4962370 "wa.C", line = 1, column = 20, data = 0x0, sysp >> = false} > > Yes, that works. Sorry if i was not clear: The thing in the cover > letter in this series does not work, the mini_vector reduced testcase > from the libstdc++-v3/include/ext/bitmap_allocator.h. > class template member function return type location, would that be it? > > AFAIR the problem was that that these member functions get their result > decl late. When they get them, there are no > declspecs->locations[ds_type_spec] around anywhere to tuck that on the > resdecl. While the result decl is clear, there is no obvious way where > to store the ds_type_spec (somewhere in the template, as you told me). > > Back then I tried moving the resdecl building from > start_preparsed_function to grokfndecl but that did not work out easily > IIRC and i ultimately gave up to move stuff around rather blindly. > I also tried to find a spot where i could store the ds_type_spec locus > somewhere in grokmethod, but i think the problem was the same, i had > just the type where i cannot store a locus and did not find a place > where i could smuggle the locus along. Ah, so the problem is deferred parsing of methods, rather than templates. Building the DECL_RESULT sooner does seem like the right approach to handling that, whether that's in grokfndecl or grokmethod. > So, to make that clear. Your template function (?) works: > > $ XXX=1 ./xg++ -B. -S -o /dev/null ../tmp4/return-narrow-2j.cc > ../tmp4/return-narrow-2j.cc: In function ‘int f()’: > ../tmp4/return-narrow-2j.cc:1:20: warning: result decl locus sample > 1 | template int f() { return 42; } > | ^~~ > | the return type > ../tmp4/return-narrow-2j.cc: In function ‘int main()’: > ../tmp4/return-narrow-2j.cc:3:1: warning: result decl locus sample > 3 | int main() > | ^~~ > | the return type > ../tmp4/return-narrow-2j.cc: In instantiation of ‘int f() [with T = int]’: > ../tmp4/return-narrow-2j.cc:5:10: required from here > ../tmp4/return-narrow-2j.cc:1:20: warning: result decl locus sample > 1 | template int f() { return 42; } > | ^~~ > | the return type > > > The class member fn not so much (IMHO, see attached): > > $ XXX=1 ./xg++ -B. -S -o /dev/null ../tmp4/return-narrow-2.cc > ../tmp4/return-narrow-2.cc: In member function ‘const long unsigned int __mini_vector< >::_M_space_left()’: > ../tmp4/return-narrow-2.cc:9:3: warning: result decl locus sample > 9 | { return _M_finish != 0; } > | ^ > | the return type > ../tmp4/return-narrow-2.cc: In instantiation of ‘const long unsigned int __mini_vector< >::_M_space_left() [with = std::pair]’: > ../tmp4/return-narrow-2.cc:11:17: required from here > ../tmp4/return-narrow-2.cc:9:3: warning: result decl locus sample > 9 | { return _M_finish != 0; } > | ^ > | the return type > ../tmp4/return-narrow-2.cc: In instantiation of ‘const long unsigned int __mini_vector< >::_M_space_left() [with = int]’: > ../tmp4/return-narrow-2.cc:12:17: required from here > ../tmp4/return-narrow-2.cc:9:3: warning: result decl locus sample > 9 | { return _M_finish != 0; } > | ^ > | the return type > > >> >>> But really I'm not interested in the template case, i only mentioned >>> them because they don't work and in case somebody wanted to have correct >>> locations. >>> I remember just frustration when i looked at those a year ago. >> >> I'd like to get the template case right while we're looking at it. I >> guess I can add that myself if you're done trying. >> >>> Is the hunk for normal functions OK for trunk? >> >> You also need a testcase for the desired behavior, with e.g. >> { dg-error "23:" } > > I'd have to think about how to test that with trunk, yes. > There are no existing warnings that want to point to the return type, > are there? Good point. Do any of your later patches add such a warning? > Maybe a g++.dg/plugin/result_decl_plugin.c then. > > set plugin_test_list [list > hmz. That strikes me as not all that flexible. > We could glob *_plugin.[cC][c]*, and have foo_plugin.lst contain it's > files. Whatever. > > thanks,