===================================================================
@@ -641,6 +641,7 @@ void debug_varpool_node_set (varpool_nod
void free_varpool_node_set (varpool_node_set);
void ipa_discover_readonly_nonaddressable_vars (void);
bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
+bool varpool_externally_visible_p (struct varpool_node *, bool);
/* In predict.c */
bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
@@ -681,6 +682,7 @@ bool const_value_known_p (tree);
bool varpool_for_node_and_aliases (struct varpool_node *,
bool (*) (struct varpool_node *, void *),
void *, bool);
+void varpool_add_new_variable (tree);
/* Walk all reachable static variables. */
#define FOR_EACH_STATIC_VARIABLE(node) \
===================================================================
@@ -262,7 +262,7 @@ get_emutls_init_templ_addr (tree decl)
if (DECL_EXTERNAL (to))
varpool_node (to);
else
- varpool_finalize_decl (to);
+ varpool_add_new_variable (to);
return build_fold_addr_expr (to);
}
@@ -334,7 +334,7 @@ new_emutls_decl (tree decl, tree alias_o
if (DECL_EXTERNAL (to))
varpool_node (to);
else if (!alias_of)
- varpool_finalize_decl (to);
+ varpool_add_new_variable (to);
else
varpool_create_variable_alias (to,
varpool_node_for_asm
===================================================================
@@ -647,7 +647,7 @@ cgraph_externally_visible_p (struct cgra
/* Return true when variable VNODE should be considered externally visible.
*/
-static bool
+bool
varpool_externally_visible_p (struct varpool_node *vnode, bool aliased)
{
if (!DECL_COMDAT (vnode->decl) && !TREE_PUBLIC (vnode->decl))
===================================================================
@@ -414,6 +414,20 @@ varpool_finalize_decl (tree decl)
varpool_assemble_pending_decls ();
}
+/* Add the variable DECL to the varpool.
+ Unlike varpool_finalize_decl function is intended to be used
+ by middle end and allows insertion of new variable at arbitrary point
+ of compilation. */
+void
+varpool_add_new_variable (tree decl)
+{
+ struct varpool_node *node;
+ varpool_finalize_decl (decl);
+ node = varpool_node (decl);
+ if (varpool_externally_visible_p (node, false))
+ node->externally_visible = true;
+}
+
/* Return variable availability. See cgraph.h for description of individual
return values. */
enum availability