diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-01-07 07:06:59 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-01-07 07:06:59 +0000 |
commit | 60e47ef8900544e2519d773c3870080161f14812 (patch) | |
tree | 21bd1600c0b15e5dc17d6a1436a5c328b0b4dc60 /gcc/cp/pt.c | |
parent | fbda03059d519370ebc553bdf56e41309659c53a (diff) | |
download | gcc-60e47ef8900544e2519d773c3870080161f14812.tar.gz |
* decl2.c (comdat_linkage): Don't set DECL_DEFER_OUTPUT.
* pt.c (instantiate_decl): Defer comdat templates that might not be
needed.
* cp-tree.h (DECL_NEEDED_P): Also true if !DECL_COMDAT.
* decl2.c (finish_vtable_vardecl): Don't check !DECL_COMDAT.
(finish_file): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@31269 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/pt.c')
-rw-r--r-- | gcc/cp/pt.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4d76cfc57c6..4ccb986660b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9385,6 +9385,7 @@ instantiate_decl (d) int pattern_defined; int line = lineno; char *file = input_filename; + tree old_fn = current_function_decl; /* This function should only be used to instantiate templates for functions and static member variables. */ @@ -9510,14 +9511,15 @@ instantiate_decl (d) && DECL_INITIAL (d) == NULL_TREE && DECL_INITIAL (code_pattern) != NULL_TREE) /* We need to set up DECL_INITIAL regardless of pattern_defined if - the variable is a static const initialized in the class body. */; - else if (! pattern_defined - || (! (TREE_CODE (d) == FUNCTION_DECL && DECL_INLINE (d) && nested) - && ! at_eof)) - { - /* Defer all templates except inline functions used in another - function. We restore the source position here because it's used - by add_pending_template. */ + the variable is a static const initialized in the class body. */; + else if (pattern_defined && nested + && TREE_CODE (d) == FUNCTION_DECL && DECL_INLINE (d)) + /* An inline function used in another function; instantiate it now so + we can inline it. */; + else if (! pattern_defined || ! at_eof) + { + /* Defer all other templates. We restore the source position + here because it's used by add_pending_template. */ lineno = line; input_filename = file; @@ -9537,6 +9539,25 @@ instantiate_decl (d) goto out; } + /* If this instantiation is COMDAT, we don't know whether or not we + will really need to write it out. If we can't be sure, mark it + DECL_DEFER_OUTPUT. NOTE: This increases memory consumption, + since we keep some instantiations in memory rather than write + them out immediately and forget them. A better approach would be + to wait until we know we need them to do the instantiation, but + that would break templates with static locals, because we + generate the functions to destroy statics before we determine + which functions are needed. A better solution would be to + generate the ctor and dtor functions as we go. */ + + if (TREE_CODE (d) == FUNCTION_DECL + && DECL_COMDAT (d) + && ! DECL_NEEDED_P (d) + /* If the function that caused us to be instantiated is needed, we + will be needed, too. */ + && (! nested || ! DECL_NEEDED_P (old_fn))) + DECL_DEFER_OUTPUT (d) = 1; + /* We're now committed to instantiating this template. Mark it as instantiated so that recursive calls to instantiate_decl do not try to instantiate it again. */ |