This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] [PR c++/84943] allow folding of array indexing indirect_ref
- From: Jason Merrill <jason at redhat dot com>
- To: Alexandre Oliva <aoliva at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>
- Date: Tue, 3 Apr 2018 11:47:50 -0400
- Subject: Re: [PATCH] [PR c++/84943] allow folding of array indexing indirect_ref
- References: <ork1u3k95q.fsf@lxoliva.fsfla.org> <CADzB+2k6sJiQcZ+u5iAAdh=SAPy5ie4rZnjg6vFmakPYORmz4Q@mail.gmail.com> <orwoy2py0o.fsf@lxoliva.fsfla.org> <CADzB+2nnSeH1Oe37kG9iWVMrgBGwgxNDKE0SWP9oFqJYvDXR_Q@mail.gmail.com> <CADzB+2kPvPute770350hRx8qACVyvE7ni+-aFLPuxBWEZShuaw@mail.gmail.com> <CADzB+2koRicaeyWMKYu9wpNbFwGHK9qTz2hrTfRbi75r9OeYkQ@mail.gmail.com> <ora7usiuyp.fsf@lxoliva.fsfla.org> <CADzB+2=HUuzBLdg=txnvGBpCEdcQ5-g=cSOJTpU6Kkp+keEnNA@mail.gmail.com> <ortvsyxxq6.fsf@lxoliva.fsfla.org> <orpo3mwcv3.fsf@lxoliva.fsfla.org> <ora7uq6m2d.fsf@lxoliva.fsfla.org> <CADzB+2=75YwaJHL0YF=F4iPwLjh=t3mG24JMG0pdQF5o3TrFfg@mail.gmail.com> <ord0zkzrs1.fsf@lxoliva.fsfla.org> <CADzB+2kL+sKadsXKJvA5CJnTSXK4wpFknWJ1tUFVkq1Y9G+dXg@mail.gmail.com> <or1sfwohtj.fsf@lxoliva.fsfla.org>
On Tue, Apr 3, 2018 at 3:44 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Apr 2, 2018, Jason Merrill <jason@redhat.com> wrote:
>
>> On Sat, Mar 31, 2018 at 2:24 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
>>> On Mar 30, 2018, Jason Merrill <jason@redhat.com> wrote:
>>>
>>>> I don't think we need this; if arg is overloaded, we take the
>>>> type_unknown_p early exit, so the code lower down is always dealing
>>>> with a single function.
>>>
>>> Aah, that's why it seemed to me that we had already resolved overloads
>>> when we got there.
>>>
>>> As a bonus, I added the tf_conv test before another mark_used call I'd
>>> missed in the previous patch.
>
>> What if we check tf_conv in mark_used itself rather than at all the call sites?
>
> There are other uses of mark_used, but presumably we want them all to
> be more conservative under tf_conv, so... Here's what I'm testing. Ok
> if it passes?
>
>
> [PR c++/84943] mark function as used when taking its address
>
> fn[0]() ICEd because we would fold the INDIRECT_REF used for the
> array indexing while building the address for the call, after not
> finding the decl hiding there at first. But the decl would be exposed
> by the folding, and then lower layers would complain we had the decl,
> after all, but it wasn't one of the artificial or special functions
> that could be called without being marked as used.
>
> This patch arranges for a FUNCTION_DECL to be marked as used when
> taking its address, just like we already did when taking the address
> of a static function to call it as a member function (i.e. using the
> obj.fn() notation). However, we shouldn't mark functions as used when
> just performing overload resolution, lest we might instantiate
> templates we shouldn't, as in g++.dg/overload/template1.C, so we
> adjust mark_used to return early when testing conversions.
>
>
> for gcc/cp/ChangeLog
>
> PR c++/84943
> * typeck.c (cp_build_addr_expr_1): Mark FUNCTION_DECL as
> used.
> * decl2.c (mark_used): Return without effects if tf_conv.
>
> for gcc/testsuite/ChangeLog
>
> PR c++/84943
> * g++.dg/pr84943.C: New.
> * g++.dg/pr84943-2.C: New.
> ---
> gcc/cp/decl2.c | 6 ++++
> gcc/cp/typeck.c | 3 ++
> gcc/testsuite/g++.dg/pr84943-2.C | 64 ++++++++++++++++++++++++++++++++++++++
> gcc/testsuite/g++.dg/pr84943.C | 8 +++++
> 4 files changed, 81 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/pr84943-2.C
> create mode 100644 gcc/testsuite/g++.dg/pr84943.C
>
> diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
> index fa753749e1a6..740e85b35617 100644
> --- a/gcc/cp/decl2.c
> +++ b/gcc/cp/decl2.c
> @@ -5201,6 +5201,12 @@ maybe_instantiate_decl (tree decl)
> bool
> mark_used (tree decl, tsubst_flags_t complain)
> {
> + /* If we're just testing conversions or resolving overloads, we
> + don't want any permanent effects like forcing functions to be
> + output or instantiating templates. */
> + if ((complain & tf_conv))
> + return false;
I think we want to return true.
Jason