[C++ PATCH] Fix -frepo (PR c++/34178, c++/34340, take 3)
Jakub Jelinek
jakub@redhat.com
Fri Dec 7 22:53:00 GMT 2007
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
More information about the Gcc-patches
mailing list