From: Jakub Jelinek <jakub@redhat.com>
To: Mark Mitchell <mark@codesourcery.com>
Cc: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [C++ PATCH] Fix -frepo (PR c++/34178, c++/34340, take 3)
Date: Fri, 07 Dec 2007 22:53:00 -0000 [thread overview]
Message-ID: <20071207225143.GK13207@devserv.devel.redhat.com> (raw)
In-Reply-To: <47598920.7090900@codesourcery.com>
On Fri, Dec 07, 2007 at 09:55:44AM -0800, Mark Mitchell wrote:
> Jakub Jelinek wrote:
>
> > No, I'm talking about the original compilation, which creates the .rpo file.
> >
> > Perhaps even shorter testcase with ./cc1plus -frepo testcase.C is:
> > struct A { int a; };
> > template <typename T> struct D { static const A b; };
> > template<typename T> const A D<T>::b = { 2 };
> > template class D<A>;
> > int main () { }
> >
> > Here there is just one static data member.
> > finish_static_data_member_decl marks D<T>::b as TREE_USED because it is
> > const.
>
> Do you really mean D<T> or D<A>? TREE_USED on D<T>::b should not matter
> as that's not a real thing; only D<A>::b might show up in the object file.
I meant of course D<A>, sorry.
> Anyhow, the explicit instantiation directive should result in us
> emitting D<A>::b. I don't think that -frepo should cause us not to emit
> things that the user has explicitly instantiated.
>
> I would expect that the right code in repo_emit_p would be:
>
> /* Variables that can appear in integral constant-expressions must
> be instantiated so that the values of th variables are
> available. */
> if (DECL_INTEGRAL_CONSTANT_VAR_P (decl))
> return 2;
> /* Explicit instantiations should be handled normally even when using
> a repository. */
> if (DECL_EXPLICIT_INSTANTIATION (decl))
> return 2;
>
> Does that work?
That seems to work too, for make check-g++ at least (but there are just
very few -frepo testcases, which is probably why this could be broken for so
long).
2007-12-07 Jakub Jelinek <jakub@redhat.com>
PR c++/34178
PR c++/34340
* repo.c (repo_emit_p): Return 2 for DECL_INTEGRAL_CONSTANT_VAR_P
in class scope rather than DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
Return 2 also if DECL_EXPLICIT_INSTANTIATION.
* decl2.c (import_export_decl): Don't make VAR_DECLs import_p when
flag_use_repository and repo_emit_p returned 2.
* g++.dg/template/repo6.C: New test.
* g++.dg/template/repo7.C: New test.
* g++.dg/template/repo8.C: New test.
--- gcc/cp/decl2.c.jj 2007-12-07 12:21:03.000000000 +0100
+++ gcc/cp/decl2.c 2007-12-07 22:24:35.000000000 +0100
@@ -2230,7 +2230,8 @@ import_export_decl (tree decl)
{
/* DECL is an implicit instantiation of a function or static
data member. */
- if (flag_implicit_templates
+ if ((flag_implicit_templates
+ && !flag_use_repository)
|| (flag_implicit_inline_templates
&& TREE_CODE (decl) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl)))
--- gcc/cp/repo.c.jj 2007-12-07 12:21:03.000000000 +0100
+++ gcc/cp/repo.c 2007-12-07 22:26:43.000000000 +0100
@@ -304,16 +304,19 @@ repo_emit_p (tree decl)
&& (!TYPE_LANG_SPECIFIC (type)
|| !CLASSTYPE_TEMPLATE_INSTANTIATION (type)))
return 2;
- /* Static data members initialized by constant expressions must
+ /* Const static data members initialized by constant expressions must
be processed where needed so that their definitions are
available. */
- if (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
+ if (DECL_INTEGRAL_CONSTANT_VAR_P (decl)
&& DECL_CLASS_SCOPE_P (decl))
return 2;
}
else if (!DECL_TEMPLATE_INSTANTIATION (decl))
return 2;
+ if (DECL_EXPLICIT_INSTANTIATION (decl))
+ return 2;
+
/* For constructors and destructors, the repository contains
information about the clones -- not the original function --
because only the clones are emitted in the object file. */
--- gcc/testsuite/g++.dg/template/repo6.C.jj 2007-12-07 22:24:35.000000000 +0100
+++ gcc/testsuite/g++.dg/template/repo6.C 2007-12-07 22:24:35.000000000 +0100
@@ -0,0 +1,25 @@
+// PR c++/34178
+// { dg-options "-frepo" }
+// { dg-final { cleanup-repo-files } }
+// { dg-require-host-local "" }
+
+template<typename T>
+class A
+{
+private:
+ static const int x;
+ static int y;
+
+public:
+ int getX () { return x + y; }
+};
+
+template<typename T> const int A<T>::x = 0;
+template<typename T> int A<T>::y = 0;
+
+int
+main ()
+{
+ A<int> a;
+ return a.getX();
+}
--- gcc/testsuite/g++.dg/template/repo7.C.jj 2007-12-07 22:24:35.000000000 +0100
+++ gcc/testsuite/g++.dg/template/repo7.C 2007-12-07 22:24:35.000000000 +0100
@@ -0,0 +1,24 @@
+// PR c++/34340
+// { dg-options "-frepo" }
+// { dg-final { cleanup-repo-files } }
+// { dg-require-host-local "" }
+
+struct A
+{
+ int a;
+};
+
+template <typename T> struct D
+{
+ static const A b;
+};
+
+template<typename T> const A D<T>::b = { 2 };
+template class D<A>;
+
+const A *x = &D<A>::b;
+
+int
+main ()
+{
+}
--- gcc/testsuite/g++.dg/template/repo8.C.jj 2007-12-07 22:24:35.000000000 +0100
+++ gcc/testsuite/g++.dg/template/repo8.C 2007-12-07 22:24:35.000000000 +0100
@@ -0,0 +1,23 @@
+// PR c++/34340
+// { dg-options "-frepo" }
+// { dg-final { cleanup-repo-files } }
+// { dg-require-host-local "" }
+
+struct A
+{
+ int a;
+};
+
+template <typename T> struct D
+{
+ static const A b;
+};
+
+template<typename T> const A D<T>::b = { 2 };
+
+const A *x = &D<A>::b;
+
+int
+main ()
+{
+}
Jakub
next prev parent reply other threads:[~2007-12-07 22:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-27 22:30 [C++ PATCH] Fix -frepo (PR c++/34178) Jakub Jelinek
2007-12-05 15:14 ` [C++ PATCH] Fix -frepo (PR c++/34178, take 2) Jakub Jelinek
2007-12-06 1:03 ` Mark Mitchell
2007-12-06 10:48 ` Jakub Jelinek
2007-12-07 4:28 ` Mark Mitchell
2007-12-07 10:35 ` [C++ PATCH] Fix -frepo (PR c++/34178, c++/34340, take 3) Jakub Jelinek
2007-12-07 17:55 ` Mark Mitchell
2007-12-07 22:53 ` Jakub Jelinek [this message]
2007-12-08 1:27 ` Mark Mitchell
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=20071207225143.GK13207@devserv.devel.redhat.com \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=mark@codesourcery.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).