From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 813203894C3B; Thu, 17 Nov 2022 08:56:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 813203894C3B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id ud5so3416603ejc.4; Thu, 17 Nov 2022 00:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=wTDTYoKYDlU17v/5dd6Mau3cpT2y5OH0o0kDPe2Hp/g=; b=J9EF40b8WjK4eKriI5JaZhjh6bCw15m6l+ep5G4Y2n4Nr7bG6eXPI5a3U58zxnNsbi HDtAItKTaNwyJch8e2GjiutY5pRCaM88l2VNJ9rQUL+jzqJQFLPUZhwmiRzdj/QbPC6a rpLU7Zu7sqcLyGWpalsU7TjenO7MguuhCuUD9tBtJdCvnSdeO/rZ/sen60WZYfjK7CJ7 Mp3eEmner810hPNqsO74K0ZcvbFwCN3mdmk1/3G95PJeJmrTBB/RE6egeN7ttmjN8le9 f+a+Og49XOKeplb7YJNXY+7aPZgIiWqp0yM+7W6P5ssBuC2LKDSYvRugzFNtKZ1CtStm Y0ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:in-reply-to:message-id:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wTDTYoKYDlU17v/5dd6Mau3cpT2y5OH0o0kDPe2Hp/g=; b=w4YFoqK63YiRL2Q/G5Zg9LYw9Y5DkKPM3jMf8fZxl2vV9nQZrm1P+TUnU6iUCvQ33e IUyMdtFwHtSvM9sOju+XwcTJq476Ko3Mqvl9jrGiB7JdDWPC7LW780VqQxVU9jFEDyup NO3cwcQhdRPmYzgy9y/ZCC4u3L823ABB0Xq2vW+HDV/AIQ0dI+RkO5VaFolPWZih77ZG uJAMdggeDlEs1d4kgZbbBqk28UOl0I8hlT2un+7bo5jDtVaOpaZbT7QVZ7jbOugSFMha aZDZJm19NFvHOXHzUfFpfTuDS57Dnm+7dEMOjHb3LY/KlIY85fXJcHxg/QX6aYfHOFmC 0DKw== X-Gm-Message-State: ANoB5plf/jah0guvkg9GpQazeismqoJavN2CyrBeiIMw/edbM28AYm1F gOHnEg4X0r28cMBOT5dK5wI= X-Google-Smtp-Source: AA0mqf4hQtg9tRrTxngYewjGq/g4fhjf7BN33Sbyw8oXZXhetmB2Nynm44yZk749JkWz9vXxG/ZBDw== X-Received: by 2002:a17:906:f6da:b0:7ad:86f9:1d70 with SMTP id jo26-20020a170906f6da00b007ad86f91d70mr1294680ejb.179.1668675411165; Thu, 17 Nov 2022 00:56:51 -0800 (PST) Received: from nbbrfq (80-110-214-113.static.upcbusiness.at. [80.110.214.113]) by smtp.gmail.com with ESMTPSA id fi13-20020a056402550d00b004580862ffdbsm248446edb.59.2022.11.17.00.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 00:56:50 -0800 (PST) Date: Thu, 17 Nov 2022 09:56:47 +0100 From: Bernhard Reutner-Fischer To: Jason Merrill Cc: rep.dot.nop@gmail.com, gcc-patches@gcc.gnu.org, Bernhard Reutner-Fischer , Nathan Sidwell Subject: Re: [PATCH 2/5] c++: Set the locus of the function result decl Message-ID: <20221117095647.42fefe06@nbbrfq> In-Reply-To: References: <20221112234543.95441-1-aldot@gcc.gnu.org> <20221112234543.95441-3-aldot@gcc.gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/uJhxs2C5cEpJOY/EDdEOaQd" X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: --MP_/uJhxs2C5cEpJOY/EDdEOaQd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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: > >=20 > > * decl.cc (start_function): Set the result decl source location to > > the location of the typespec. > >=20 > > --- > > Bootstrapped and regtested on x86_86-unknown-linux with no regressions. > > Ok for trunk? > >=20 > > Cc: Nathan Sidwell > > Cc: Jason Merrill > > --- > > gcc/cp/decl.cc | 15 ++++++++++++++- > > 1 file changed, 14 insertions(+), 1 deletion(-) > >=20 > > 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 *declspec= s, > > tree attrs) > > { > > tree decl1; > > + tree result; > > + bool ret; =20 >=20 > We now prefer to declare new variables as late as possible, usually when= =20 > they are initialized. Moved. Ok like attached? Bootstrapped and regtested fine. > > decl1 =3D grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs= ); > > invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1); > > @@ -17461,7 +17463,18 @@ start_function (cp_decl_specifier_seq *declspe= cs, > > gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)), > > integer_type_node)); > > =20 > > - return start_preparsed_function (decl1, attrs, /*flags=3D*/SF_DEFAUL= T); > > + ret =3D start_preparsed_function (decl1, attrs, /*flags=3D*/SF_DEFAU= LT); > > + > > + /* decl1 might be ggc_freed here. */ > > + decl1 =3D current_function_decl; > > + > > + /* Set the result decl source location to the location of the typesp= ec. */ > > + if (TREE_CODE (decl1) =3D=3D FUNCTION_DECL > > + && declspecs->locations[ds_type_spec] !=3D UNKNOWN_LOCATION > > + && (result =3D DECL_RESULT (decl1)) !=3D NULL_TREE > > + && DECL_SOURCE_LOCATION (result) =3D=3D input_location) > > + DECL_SOURCE_LOCATION (result) =3D declspecs->locations[ds_type_spe= c]; =20 >=20 > One way to handle the template case would be for the code in=20 > start_preparsed_function that sets DECL_RESULT to check whether decl1 is= =20 > a template instantiation, and in that case copy the location from the=20 > template's DECL_RESULT, i.e. >=20 > 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. 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); } =20 + /* 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)))) + DECL_SOURCE_LOCATION (DECL_RESULT (decl1)) + =3D DECL_SOURCE_LOCATION ( + 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 !=3D 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 =3D 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. >=20 > > + return ret; > > } > > =0C > > /* Returns true iff an EH_SPEC_BLOCK should be created in the body of= =20 >=20 --MP_/uJhxs2C5cEpJOY/EDdEOaQd Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0002-c-Set-the-locus-of-the-function-result-decl.patch >From 5595eb2d3056f6bca3d2b80bc8b2796d86da0ce8 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 13 Nov 2022 00:45:40 +0100 Subject: [PATCH 2/5] c++: Set the locus of the function result decl gcc/cp/ChangeLog: * decl.cc (start_function): Set the result decl source location to the location of the typespec. --- gcc/cp/decl.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 890cfcabd35..ed7226b82f0 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17527,7 +17527,19 @@ 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); + bool ret = start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT); + + /* decl1 might be ggc_freed here. */ + decl1 = current_function_decl; + + tree result; + /* 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]; + return ret; } /* Returns true iff an EH_SPEC_BLOCK should be created in the body of -- 2.30.2 --MP_/uJhxs2C5cEpJOY/EDdEOaQd--