From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22411 invoked by alias); 7 Dec 2007 22:53:55 -0000 Received: (qmail 22391 invoked by uid 22791); 7 Dec 2007 22:53:54 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 07 Dec 2007 22:53:48 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.1) with ESMTP id lB7Mpig3024095; Fri, 7 Dec 2007 17:51:45 -0500 Received: from devserv.devel.redhat.com (devserv.devel.redhat.com [10.10.36.72]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id lB7Mpi8g026957; Fri, 7 Dec 2007 17:51:44 -0500 Received: from devserv.devel.redhat.com (localhost.localdomain [127.0.0.1]) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id lB7MpiGO001370; Fri, 7 Dec 2007 17:51:44 -0500 Received: (from jakub@localhost) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11/Submit) id lB7MpiZi001368; Fri, 7 Dec 2007 17:51:44 -0500 Date: Fri, 07 Dec 2007 22:53:00 -0000 From: Jakub Jelinek To: Mark Mitchell Cc: Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [C++ PATCH] Fix -frepo (PR c++/34178, c++/34340, take 3) Message-ID: <20071207225143.GK13207@devserv.devel.redhat.com> Reply-To: Jakub Jelinek References: <20071127215831.GX16835@devserv.devel.redhat.com> <20071205151120.GA25112@devserv.devel.redhat.com> <47574A61.1060200@codesourcery.com> <20071206104553.GG25112@devserv.devel.redhat.com> <4758CBCB.3030604@codesourcery.com> <20071207103256.GD13207@devserv.devel.redhat.com> <47598920.7090900@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47598920.7090900@codesourcery.com> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg00368.txt.bz2 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 struct D { static const A b; }; > > template const A D::b = { 2 }; > > template class D; > > int main () { } > > > > Here there is just one static data member. > > finish_static_data_member_decl marks D::b as TREE_USED because it is > > const. > > Do you really mean D or D? TREE_USED on D::b should not matter > as that's not a real thing; only D::b might show up in the object file. I meant of course D, sorry. > Anyhow, the explicit instantiation directive should result in us > emitting D::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 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 +class A +{ +private: + static const int x; + static int y; + +public: + int getX () { return x + y; } +}; + +template const int A::x = 0; +template int A::y = 0; + +int +main () +{ + A 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 struct D +{ + static const A b; +}; + +template const A D::b = { 2 }; +template class D; + +const A *x = &D::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 struct D +{ + static const A b; +}; + +template const A D::b = { 2 }; + +const A *x = &D::b; + +int +main () +{ +} Jakub