public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christophe Lyon <christophe.lyon@linaro.org>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: Jason Merrill <jason@redhat.com>,
	gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ Patch] [PR c++/88146] do not crash synthesizing inherited ctor(...)
Date: Thu, 20 Dec 2018 16:00:00 -0000	[thread overview]
Message-ID: <CAKdteOa=+OmwMi=eaO_nEqJgrQ-tjSV3BKCX1ZoTgUiFoeyjHQ@mail.gmail.com> (raw)
In-Reply-To: <or4lb983no.fsf@lxoliva.fsfla.org>

On Thu, 20 Dec 2018 at 01:04, Alexandre Oliva <aoliva@redhat.com> wrote:
>
> Christophe,
>
> Thanks again for the report.  This was quite an adventure to figure
> out ;-)  See below.
>

Glad I've helped. I wouldn't have been able to do the analysis :)


>
> [PR88146] avoid diagnostics diffs if cdtor_returns_this
>
> Diagnostics for testsuite/g++.dg/cpp0x/inh-ctor32.C varied across
> platforms.  Specifically, on ARM, the diagnostics within the subtest
> derived_ctor::inherited_derived_ctor::constexpr_noninherited_ctor did
> not match those displayed on other platforms, and the test failed.
>
> The difference seemed to have to do with locations assigned to ctors,
> but it was more subtle: on ARM, the instantiation of bor's template
> ctor was nested within the instantiation of bar's template ctor
> inherited from bor.  The reason turned out to be related with the
> internal return type of ctors: arm_cxx_cdtor_returns_this is enabled
> for because of AAPCS, while cxx.cdtor_returns_this is disabled on most
> other platforms.  While convert_to_void returns early with a VOID
> expr, the non-VOID return type of the base ctor CALL_EXPR causes
> convert_to_void to inspect the called decl for nodiscard attributes:
> maybe_warn_nodiscard -> cp_get_fndecl_from_callee ->
> maybe_constant_init -> cxx_eval_outermost_constant_expr ->
> instantiate_constexpr_fns -> nested instantiation.
>
> The internal return type assigned to a cdtor should not affect
> instantiation (constexpr or template) decisions, IMHO.  We know it
> affects diagnostics, but I have a hunch this might bring deeper issues
> with it, so I've arranged for the CALL_EXPR handler in convert_to_void
> to disregard cdtors, regardless of the ABI.
>
>
> The patch is awkward on purpose: it's meant to illustrate both
> portions of the affected code, to draw attention to a potential
> problem, and to get bootstrap-testing coverage for the path that will
> be taken on ARM.  I envision removing the first hunk, and the else
> from the second hunk, once testing is done.
>
> The first hunk is there to highlight where convert_to_void returns
> early on x86, instead of handling the CALL_EXPR.
>
> BTW (here's the potential problem), shouldn't we go into the CALL_EXPR
> case for the volatile void mentioned in comments next to the case, or
> won't that match VOID_TYPE_P?
>
> Finally, I shall mention the possibility of taking the opposite
> direction, and actually looking for nodiscard in cdtor calls so as to
> trigger the constexpr side effects that we've inadvertently triggered
> and observed with the inh-ctor32.C testcase.  It doesn't feel right to
> me, but I've been wrong many times before ;-)
>
> Would a rearranged version of the patch, dropping the redundant tests
> and retaining only the addition of the test for cdtor identifiers, be
> ok to install, provided that it passes regression testing?
>
>
> Note this patch does NOT carry a ChangeLog entry.  That's also on
> purpose, to indicate it's not meant to be included as is.
> ---
>  gcc/cp/cvt.c |   21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
> index eb1687377c3e..1a15af8a6e99 100644
> --- a/gcc/cp/cvt.c
> +++ b/gcc/cp/cvt.c
> @@ -1112,7 +1112,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
>          error_at (loc, "pseudo-destructor is not called");
>        return error_mark_node;
>      }
> -  if (VOID_TYPE_P (TREE_TYPE (expr)))
> +  if (VOID_TYPE_P (TREE_TYPE (expr))
> +      && TREE_CODE (expr) != CALL_EXPR)
>      return expr;
>    switch (TREE_CODE (expr))
>      {
> @@ -1169,6 +1170,24 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
>        break;
>
>      case CALL_EXPR:   /* We have a special meaning for volatile void fn().  */
> +      /* cdtors may return this or void, depending on
> +        targetm.cxx.cdtor_returns_this, but this shouldn't affect our
> +        decisions here: nodiscard cdtors are nonsensical, and we
> +        don't want to call maybe_warn_nodiscard because it may
> +        trigger constexpr or template instantiation in a way that
> +        changes their instantiaton nesting.  This changes the way
> +        contexts are printed in diagnostics, with bad consequences
> +        for the testsuite, but there may be other undesirable
> +        consequences of visiting referenced ctors too soon.  */
> +      if (DECL_P (TREE_OPERAND (expr, 0))
> +         && IDENTIFIER_CDTOR_P (DECL_NAME (TREE_OPERAND (expr, 0))))
> +       return expr;
> +      /* FIXME: Move this test before the one above, after a round of
> +        testing as it is, to get coverage of the behavior we'd get on
> +        ARM.  */
> +      else if (VOID_TYPE_P (TREE_TYPE (expr)))
> +       return expr;
> +
>        maybe_warn_nodiscard (expr, implicit);
>        break;
>
>
>
> --
> Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
> Be the change, be Free!         FSF Latin America board member
> GNU Toolchain Engineer                Free Software Evangelist
> Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

  reply	other threads:[~2018-12-20 15:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07  0:23 Alexandre Oliva
2018-12-14 20:14 ` Alexandre Oliva
2018-12-14 20:42 ` Jason Merrill
2018-12-14 21:41   ` Jason Merrill
2018-12-14 22:34     ` Alexandre Oliva
2018-12-14 22:44       ` Jason Merrill
2018-12-14 23:05         ` Alexandre Oliva
2018-12-15 22:11           ` Jason Merrill
2018-12-19 14:36             ` Christophe Lyon
2018-12-19 18:49               ` Alexandre Oliva
2018-12-19 18:52                 ` Jakub Jelinek
2018-12-20  0:04               ` Alexandre Oliva
2018-12-20 16:00                 ` Christophe Lyon [this message]
2018-12-20 16:18                 ` Jason Merrill
2018-12-28 22:53                   ` Alexandre Oliva
2018-12-29  6:40                     ` Alexandre Oliva
2018-12-29 13:33                       ` Jakub Jelinek
2019-01-04 18:55                       ` Jason Merrill
2019-01-17  4:12                         ` Alexandre Oliva
2018-12-29 10:28                     ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKdteOa=+OmwMi=eaO_nEqJgrQ-tjSV3BKCX1ZoTgUiFoeyjHQ@mail.gmail.com' \
    --to=christophe.lyon@linaro.org \
    --cc=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).