public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Cc: jason@redhat.com
Subject: Re: [PATCH 1/2] c++: modules and non-dependent auto deduction
Date: Tue, 20 Sep 2022 16:02:02 -0400	[thread overview]
Message-ID: <2d27e230-6f11-c701-71e1-db45ce247d67@acm.org> (raw)
In-Reply-To: <20220920195431.1527042-1-ppalka@redhat.com>

On 9/20/22 15:54, Patrick Palka wrote:
> The modules streaming code seems to rely on the invariant that a
> TEMPLATE_DECL and its DECL_TEMPLATE_RESULT have the same TREE_TYPE.

It does indeed.

> But for a templated VAR_DECL with deduced non-dependent type, the two
> TREE_TYPEs end up diverging: cp_finish_decl deduces the type of the
> initializer ahead of time and updates the TREE_TYPE of the VAR_DECL, but
> neglects to update the corresponding TEMPLATE_DECL as well, which leads
> to a "conflicting global module declaration" error for each of the
> __phase_alignment decls in the below testcase (and for the xtreme-header
> testcases if we try including <barrier>).
> 
> This patch makes cp_finish_decl update the TREE_TYPE of the corresponding
> TEMPLATE_DECL so that the invariant is maintained >
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

Ok, thanks


> 
> gcc/cp/ChangeLog:
> 
> 	* decl.cc (cp_finish_decl): After updating the deduced type of a
> 	VAR_DECL, also update the corresponding TEMPLATE_DECL if there
> 	is one.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/modules/auto-3.h: New test.
> 	* g++.dg/modules/auto-3_a.H: New test.
> 	* g++.dg/modules/auto-3_b.C: New test.
> ---
>   gcc/cp/decl.cc                          |  6 ++++++
>   gcc/testsuite/g++.dg/modules/auto-3.h   | 10 ++++++++++
>   gcc/testsuite/g++.dg/modules/auto-3_a.H |  4 ++++
>   gcc/testsuite/g++.dg/modules/auto-3_b.C |  4 ++++
>   4 files changed, 24 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/modules/auto-3.h
>   create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_a.H
>   create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_b.C
> 
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 070f673c3a2..80467c19254 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -8180,6 +8180,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
>   	  return;
>   	}
>         cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
> +
> +      /* Update the type of the corresponding TEMPLATE_DECL to match.  */
> +      if (DECL_LANG_SPECIFIC (decl)
> +	  && DECL_TEMPLATE_INFO (decl)
> +	  && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
> +	TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
>       }
>   
>     if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3.h b/gcc/testsuite/g++.dg/modules/auto-3.h
> new file mode 100644
> index 00000000000..f129433cbcb
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3.h
> @@ -0,0 +1,10 @@
> +template<class>
> +struct __tree_barrier {
> +  static const auto __phase_alignment_1 = 0;
> +
> +  template<class>
> +  static const auto __phase_alignment_2 = 0;
> +};
> +
> +template<class>
> +inline auto __phase_alignment_3 = 0;
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3_a.H b/gcc/testsuite/g++.dg/modules/auto-3_a.H
> new file mode 100644
> index 00000000000..25a7a73e73e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3_a.H
> @@ -0,0 +1,4 @@
> +// { dg-additional-options "-fmodule-header" }
> +// { dg-module-cmi {} }
> +
> +#include "auto-3.h"
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3_b.C b/gcc/testsuite/g++.dg/modules/auto-3_b.C
> new file mode 100644
> index 00000000000..03b6d46f476
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3_b.C
> @@ -0,0 +1,4 @@
> +// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
> +
> +#include "auto-3.h"
> +import "auto-3_a.H";

-- 
Nathan Sidwell


      parent reply	other threads:[~2022-09-20 20:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 19:54 Patrick Palka
2022-09-20 19:54 ` [PATCH 2/2] c++: xtreme-header modules tests cleanups Patrick Palka
2022-09-20 20:02   ` Nathan Sidwell
2022-09-20 20:02 ` Nathan Sidwell [this message]

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=2d27e230-6f11-c701-71e1-db45ce247d67@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=ppalka@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).