+2001-03-23 Jakub Jelinek <jakub@redhat.com>
+
+ * decl.c (local_names): Define.
+ (push_local_name): New.
+ (grok_reference_init): Return init if initializing static reference
+ variable with non-constant instead of emitting it.
+ Move expand_static_init call to cp_finish_decl.
+ (layout_var_decl): Call push_local_name.
+ (maybe_commonize_var): Allow inlining functions even if they have
+ static local variables, use comdat_linkage for them if flag_weak.
+ (check_initializer): Call obscure_complex_init if
+ grok_reference_init returned non-zero.
+ (save_function_data): Clear x_local_names.
+ (pop_cp_function_context): Free x_local_names.
+ (mark_inlined_fns): Remove.
+ (mark_lang_function): Mark x_local_names.
+ (lang_mark_tree): Don't mark DECL_ACCESS for DECL_DISCRIMINATOR_P.
+ Mark inlined_fns as tree, remove call to mark_inlined_fns.
+ * class.c (alter_access): Ensure DECL_ACCESS is never set if
+ DECL_DISCRIMINATOR_P.
+ * cp-tree.h (cp_language_function): Add x_local_names.
+ (lang_decl_flags): Add discriminator into u2.
+ (lang_decl_inlined_fns): Remove.
+ (lang_decl): inlined_fns is now a TREE_VEC.
+ (DECL_DISCRIMINATOR_P, DECL_DISCRIMINATOR): Define.
+ * optimize.c (inlinable_function_p): DECL_INLINED_FNS is now a
+ TREE_VEC, not a custom structure.
+ (optimize_function): Likewise.
+ * mangle.c (discriminator_for_local_entity): Discriminate among
+ VAR_DECL local entities.
+ * search.c (dfs_access_in_type): If DECL_DISCRIMINATOR_P, DECL_ACCESS
+ is not valid.
+
2001-03-22 Bryce McKinlay <bryce@albatross.co.nz>
Add support for Java interface method calls.
struct named_label_use_list *x_named_label_uses;
struct named_label_list *x_named_labels;
struct binding_level *bindings;
+ varray_type x_local_names;
const char *cannot_inline;
};
/* This is DECL_ACCESS. */
tree access;
+ /* For VAR_DECL in function, this is DECL_DISCRIMINATOR. */
+ int discriminator;
+
/* In a namespace-scope FUNCTION_DECL, this is
GLOBAL_INIT_PRIORITY. */
int init_priority;
struct unparsed_text;
-struct lang_decl_inlined_fns
-{
- size_t num_fns;
- tree fns[1];
-};
-
struct lang_decl
{
struct lang_decl_flags decl_flags;
/* In a FUNCTION_DECL, this is DECL_CLONED_FUNCTION. */
tree cloned_function;
- /* In a FUNCTION_DECL, this is a list of trees inlined into its body. */
- struct lang_decl_inlined_fns *inlined_fns;
+ /* In a FUNCTION_DECL, these are function data which is to be kept
+ as long as FUNCTION_DECL is kept. */
+ tree inlined_fns;
union
{
#define DECL_INLINED_FNS(NODE) \
(DECL_LANG_SPECIFIC (NODE)->inlined_fns)
+/* Nonzero if NODE has DECL_DISCRIMINATOR and not DECL_ACCESS. */
+#define DECL_DISCRIMINATOR_P(NODE) \
+ (TREE_CODE (NODE) == VAR_DECL \
+ && DECL_FUNCTION_SCOPE_P (NODE))
+
+/* Discriminator for name mangling. */
+#define DECL_DISCRIMINATOR(NODE) \
+ (DECL_LANG_SPECIFIC (NODE)->decl_flags.u2.discriminator)
+
/* Non-zero if the VTT parm has been added to NODE. */
#define DECL_HAS_VTT_PARM_P(NODE) \
(DECL_LANG_SPECIFIC (NODE)->decl_flags.has_vtt_parm_p)
static tree lookup_tag_reverse PARAMS ((tree, tree));
static tree obscure_complex_init PARAMS ((tree, tree));
static tree lookup_name_real PARAMS ((tree, int, int, int));
+static void push_local_name PARAMS ((tree));
static void warn_extern_redeclared_static PARAMS ((tree, tree));
-static void grok_reference_init PARAMS ((tree, tree, tree));
+static tree grok_reference_init PARAMS ((tree, tree, tree));
static tree grokfndecl PARAMS ((tree, tree, tree, tree, int,
enum overload_flags, tree,
tree, int, int, int, int, int, int, tree));
static void mark_named_label_lists PARAMS ((void *, void *));
static void mark_cp_function_context PARAMS ((struct function *));
static void mark_saved_scope PARAMS ((void *));
-static void mark_inlined_fns PARAMS ((struct lang_decl_inlined_fns *));
static void mark_lang_function PARAMS ((struct cp_language_function *));
static void save_function_data PARAMS ((tree));
static void check_function_type PARAMS ((tree, tree));
#define named_label_uses cp_function_chain->x_named_label_uses
+#define local_names cp_function_chain->x_local_names
+
/* A list of objects which have constructors or destructors
which reside in the global scope. The decl is stored in
the TREE_VALUE slot and the initializer is stored
return decl;
}
+/* Remember a local name for name-mangling purposes. */
+
+static void
+push_local_name (decl)
+ tree decl;
+{
+ size_t i, nelts;
+ tree t, name;
+
+ if (!local_names)
+ VARRAY_TREE_INIT (local_names, 8, "local_names");
+
+ name = DECL_NAME (decl);
+
+ nelts = VARRAY_ACTIVE_SIZE (local_names);
+ for (i = 0; i < nelts; i++)
+ {
+ t = VARRAY_TREE (local_names, i);
+ if (DECL_NAME (t) == name)
+ {
+ if (!DECL_LANG_SPECIFIC (decl))
+ retrofit_lang_decl (decl);
+ if (DECL_LANG_SPECIFIC (t))
+ DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
+ else
+ DECL_DISCRIMINATOR (decl) = 1;
+
+ VARRAY_TREE (local_names, i) = decl;
+ return;
+ }
+ }
+
+ VARRAY_PUSH_TREE (local_names, decl);
+}
+
/* Push a tag name NAME for struct/class/union/enum type TYPE.
Normally put it into the inner-most non-tag-transparent scope,
but if GLOBALIZE is true, put it in the inner-most non-class scope.
Quotes on semantics can be found in ARM 8.4.3. */
-static void
+static tree
grok_reference_init (decl, type, init)
tree decl, type, init;
{
|| DECL_IN_AGGR_P (decl) == 0)
&& ! DECL_THIS_EXTERN (decl))
cp_error ("`%D' declared as reference but not initialized", decl);
- return;
+ return NULL_TREE;
}
if (init == error_mark_node)
- return;
+ return NULL_TREE;
if (TREE_CODE (init) == CONSTRUCTOR)
{
cp_error ("ISO C++ forbids use of initializer list to initialize reference `%D'", decl);
- return;
+ return NULL_TREE;
}
if (TREE_CODE (init) == TREE_LIST)
decl);
if (tmp == error_mark_node)
- return;
- else if (tmp != NULL_TREE)
- {
- init = tmp;
- tmp = save_expr (tmp);
- if (building_stmt_tree ())
- {
- /* Initialize the declaration. */
- tmp = build (INIT_EXPR, TREE_TYPE (decl), decl, tmp);
- finish_expr_stmt (tmp);
- }
- else
- DECL_INITIAL (decl) = tmp;
- }
- else
+ return NULL_TREE;
+ else if (tmp == NULL_TREE)
{
cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
- return;
+ return NULL_TREE;
}
- if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
+ if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp))
+ return tmp;
+
+ if (building_stmt_tree ())
{
- expand_static_init (decl, DECL_INITIAL (decl));
- DECL_INITIAL (decl) = NULL_TREE;
+ /* Initialize the declaration. */
+ tmp = build (INIT_EXPR, TREE_TYPE (decl), decl, tmp);
+ finish_expr_stmt (tmp);
}
- return;
+ else
+ DECL_INITIAL (decl) = tmp;
+
+ return NULL_TREE;
}
/* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
else
cp_error ("storage size of `%D' isn't constant", decl);
}
+
+ if (TREE_STATIC (decl)
+ && !DECL_ARTIFICIAL (decl)
+ && current_function_decl
+ && DECL_CONTEXT (decl) == current_function_decl)
+ push_local_name (decl);
}
/* If a local static variable is declared in an inline function, or if
|| DECL_TEMPLATE_INSTANTIATION (current_function_decl))
&& TREE_PUBLIC (current_function_decl))
{
- /* Rather than try to get this right with inlining, we suppress
- inlining of such functions. */
- current_function_cannot_inline
- = "function with static variable cannot be inline";
- DECL_UNINLINABLE (current_function_decl) = 1;
-
/* If flag_weak, we don't need to mess with this, as we can just
make the function weak, and let it refer to its unique local
copy. This works because we don't allow the function to be
cp_warning_at (" you can work around this by removing the initializer", decl);
}
}
+ else
+ comdat_linkage (decl);
}
else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
/* Set it up again; we might have set DECL_INITIAL since the last
}
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)
{
f->base.x_stmt_tree.x_last_expr_type = NULL_TREE;
f->x_named_label_uses = NULL;
f->bindings = NULL;
+ f->x_local_names = NULL;
/* When we get back here again, we will be expanding. */
f->x_expanding_p = 1;
struct function *f;
{
if (f->language)
- free (f->language);
+ {
+ struct cp_language_function *cp =
+ (struct cp_language_function *) f->language;
+ if (cp->x_local_names)
+ VARRAY_FREE (cp->x_local_names);
+ free (f->language);
+ }
f->language = 0;
}
-/* Mark I for GC. */
-
-static void
-mark_inlined_fns (i)
- struct lang_decl_inlined_fns *i;
-{
- int n;
-
- for (n = i->num_fns - 1; n >= 0; n--)
- ggc_mark_tree (i->fns [n]);
- ggc_set_mark (i);
-}
-
/* Mark P for GC. */
static void
ggc_mark_tree (p->x_current_class_ptr);
ggc_mark_tree (p->x_current_class_ref);
ggc_mark_tree (p->x_eh_spec_try_block);
+ ggc_mark_tree_varray (p->x_local_names);
mark_named_label_lists (&p->x_named_labels, &p->x_named_label_uses);
mark_binding_level (&p->bindings);
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)
+ && !DECL_DISCRIMINATOR_P (t))
ggc_mark_tree (ld->decl_flags.u2.access);
else if (DECL_THUNK_P (t))
ggc_mark_tree (ld->decl_flags.u2.vcall_offset);
ggc_mark_tree (ld->befriending_classes);
ggc_mark_tree (ld->context);
ggc_mark_tree (ld->cloned_function);
- if (ld->inlined_fns)
- mark_inlined_fns (ld->inlined_fns);
+ ggc_mark_tree (ld->inlined_fns);
if (TREE_CODE (t) == TYPE_DECL)
ggc_mark_tree (ld->u.sorted_fields);
else if (TREE_CODE (t) == FUNCTION_DECL