This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Inline even functions containing static variables (take 3)
>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
> if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
> - {
> - expand_static_init (decl, DECL_INITIAL (decl));
> - DECL_INITIAL (decl) = NULL_TREE;
> - }
> - return;
> + return DECL_INITIAL (decl);
> +
> + return NULL_TREE;
> }
Like store_init_value, this should only return non-null if the initializer
isn't a valid constant.
> @@ -7607,8 +7644,9 @@ check_initializer (decl, init)
> }
> else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE)
> {
> - grok_reference_init (decl, type, init);
> - init = NULL_TREE;
> + init = grok_reference_init (decl, type, init);
> + if (init)
> + init = obscure_complex_init (decl, init);
> }
> else if (init)
> {
Yes.
> @@ -8047,6 +8085,14 @@ cp_finish_decl (decl, init, asmspec_tree
> else
> abstract_virtuals_error (decl, strip_array_types (type));
> + if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE
> + && init != NULL_TREE)
> + {
> + expand_static_init (decl, init);
> + init = NULL_TREE;
> + DECL_INITIAL (decl) = NULL_TREE;
> + }
> +
I think the existing code in cp_finish_decl will already
handle this.
> @@ -14378,7 +14419,8 @@ lang_mark_tree (t)
> c_mark_lang_decl (&ld->decl_flags.base);
> if (!DECL_GLOBAL_CTOR_P (t)
> && !DECL_GLOBAL_DTOR_P (t)
> - && !DECL_THUNK_P (t))
> + && !DECL_THUNK_P (t)
> + && TREE_CODE (t) != VAR_DECL)
> ggc_mark_tree (ld->decl_flags.u2.access);
This is still wrong.
> @@ -1843,6 +1844,9 @@ struct lang_decl_flags
> /* This is DECL_ACCESS. */
> tree access;
> + /* For VAR_DECL, this is DECL_DISCRIMINATOR. */
> + int discriminator;
This should say "VAR_DECL in a function".
> +/* Nonzero if NODE has DECL_DISCRIMINATOR and not DECL_ACCESS. */
> +#define DECL_DISCRIMINATOR_P(NODE) \
> + (TREE_CODE (NODE) == VAR_DECL && DECL_CONTEXT (NODE) \
> + && TREE_CODE (DECL_CONTEXT (NODE)) == FUNCTION_DECL)
You can use DECL_FUNCTION_SCOPE_P.
Jason