2017-05-05  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (IDENTIFIER_GLOBAL_VALUE): Use get_namespace_value.
	(SET_IDENTIFIER_GLOBAL_VALUE): Use set_global_value.
	(IDENTIFIER_NAMESPACE_VALUE): Delete.
	* name-lookup.h (namespace_binding, set_namespace_binding): Replace
	with ...
	(get_namespace_value, set_global_value): ... these.
	(get_global_value_if_present, is_typename_at_global_scope): Delete.
	* decl.c (poplevel): Use get_namespace_value.
	(grokdeclarator): Use IDENTIFIER_GLOBAL_VALUE.
	* class.c (build_vtbl_initializer): Stash library decl in
	static var. Use IDENTIFIER_GLOBAL_VALUE.
	* except.c (do_get_exception_ptr, do_begin_catch, do_end_catch,
	do_allocate_exception, do_free_exception, build_throw): Likewise.
	* init.c (throw_bad_array_new_length): Likewise.
	* rtti.c (throw_bad_cast, throw_bad_typeid): Likewise.
	* name-lookup.c (arg_assoc_namespace, pushdecl_maybe_friend_1,
	check_for_our_of_scope_variable, push_overloaded_decl_1): Use
	get_namespace_value.
	(set_namespace_binding_1): Rename to
	(set_namespace_binding): ... here.
	(set_global_value): New.
	(lookup_name_innermost_nonclass_level_1, push_namespace): Use
	get_namespace_value.
	* pt.c (listify): Use get_namespace_value.

Index: class.c
===================================================================
--- class.c	(revision 247647)
+++ class.c	(working copy)
@@ -9769,11 +9769,18 @@ build_vtbl_initializer (tree binfo,
 	  /* Likewise for deleted virtuals.  */
 	  else if (DECL_DELETED_FN (fn_original))
 	    {
-	      fn = get_identifier ("__cxa_deleted_virtual");
-	      if (!get_global_value_if_present (fn, &fn))
-		fn = push_library_fn (fn, (build_function_type_list
-					   (void_type_node, NULL_TREE)),
-				      NULL_TREE, ECF_NORETURN);
+	      static tree fn;
+
+	      if (!fn)
+		{
+		  tree name = get_identifier ("__cxa_deleted_virtual");
+		  fn = IDENTIFIER_GLOBAL_VALUE (name);
+		  if (!fn)
+		    fn = push_library_fn
+		      (name,
+		       build_function_type_list (void_type_node, NULL_TREE),
+		       NULL_TREE, ECF_NORETURN);
+		}
 	      if (!TARGET_VTABLE_USES_DESCRIPTORS)
 		init = fold_convert (vfunc_ptr_type_node,
 				     build_fold_addr_expr (fn));
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 247647)
+++ cp-tree.h	(working copy)
@@ -554,13 +554,9 @@ struct GTY(()) ptrmem_cst {
 typedef struct ptrmem_cst * ptrmem_cst_t;
 
 #define IDENTIFIER_GLOBAL_VALUE(NODE) \
-  namespace_binding ((NODE), global_namespace)
+  get_namespace_value (NULL_TREE, (NODE))
 #define SET_IDENTIFIER_GLOBAL_VALUE(NODE, VAL) \
-  set_namespace_binding ((NODE), global_namespace, (VAL))
-#define IDENTIFIER_NAMESPACE_VALUE(NODE) \
-  namespace_binding ((NODE), current_namespace)
-#define SET_IDENTIFIER_NAMESPACE_VALUE(NODE, VAL) \
-  set_namespace_binding ((NODE), current_namespace, (VAL))
+  set_global_value ((NODE), (VAL))
 
 #define CLEANUP_P(NODE)		TREE_LANG_FLAG_0 (TRY_BLOCK_CHECK (NODE))
 
Index: decl.c
===================================================================
--- decl.c	(revision 247647)
+++ decl.c	(working copy)
@@ -687,16 +687,13 @@ poplevel (int keep, int reverse, int fun
 	  && DECL_NAME (link))
 	{
 	  tree name = DECL_NAME (link);
-	  cxx_binding *ob;
-	  tree ns_binding;
 
-	  ob = outer_binding (name,
-			      IDENTIFIER_BINDING (name),
-			      /*class_p=*/true);
+	  cxx_binding *ob = outer_binding (name,
+					   IDENTIFIER_BINDING (name),
+					   /*class_p=*/true);
+	  tree ns_binding = NULL_TREE;
 	  if (!ob)
-	    ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
-	  else
-	    ns_binding = NULL_TREE;
+	    ns_binding = get_namespace_value (current_namespace, name);
 
 	  if (ob && ob->scope == current_binding_level->level_chain)
 	    /* We have something like:
@@ -10148,7 +10145,8 @@ grokdeclarator (const cp_declarator *dec
 		    gcc_assert (flags == NO_SPECIAL);
 		    flags = TYPENAME_FLAG;
 		    sfk = sfk_conversion;
-		    if (is_typename_at_global_scope (dname))
+		    tree glob = IDENTIFIER_GLOBAL_VALUE (dname);
+		    if (glob && TREE_CODE (glob) == TYPE_DECL)
 		      name = identifier_to_locale (IDENTIFIER_POINTER (dname));
 		    else
 		      name = "<invalid operator>";
Index: except.c
===================================================================
--- except.c	(revision 247647)
+++ except.c	(working copy)
@@ -154,14 +154,17 @@ declare_library_fn (tree name, tree retu
 static tree
 do_get_exception_ptr (void)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_get_exception_ptr");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void* __cxa_get_exception_ptr (void *) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, ptr_type_node,
-			       ECF_NOTHROW | ECF_PURE | ECF_LEAF | ECF_TM_PURE);
+      tree name = get_identifier ("__cxa_get_exception_ptr");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	/* Declare void* __cxa_get_exception_ptr (void *) throw().  */
+	fn = declare_library_fn
+	  (name, ptr_type_node, ptr_type_node,
+	   ECF_NOTHROW | ECF_PURE | ECF_LEAF | ECF_TM_PURE);
     }
 
   return cp_build_function_call_nary (fn, tf_warning_or_error,
@@ -174,22 +177,29 @@ do_get_exception_ptr (void)
 static tree
 do_begin_catch (void)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_begin_catch");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void* __cxa_begin_catch (void *) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, ptr_type_node, ECF_NOTHROW);
+      tree name = fn = get_identifier ("__cxa_begin_catch");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	{
+	  /* Declare void* __cxa_begin_catch (void *) throw().  */
+	  fn = declare_library_fn
+	    (name, ptr_type_node, ptr_type_node, ECF_NOTHROW);
 
-      /* Create its transactional-memory equivalent.  */
-      if (flag_tm)
-	{
-	  tree fn2 = get_identifier ("_ITM_cxa_begin_catch");
-	  if (!get_global_value_if_present (fn2, &fn2))
-	    fn2 = declare_library_fn (fn2, ptr_type_node,
-				      ptr_type_node, ECF_NOTHROW | ECF_TM_PURE);
-	  record_tm_replacement (fn, fn2);
+	  /* Create its transactional-memory equivalent.  */
+	  if (flag_tm)
+	    {
+	      tree itm_name = get_identifier ("_ITM_cxa_begin_catch");
+	      tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+	      if (!itm_fn)
+		itm_fn = declare_library_fn
+		  (itm_name, ptr_type_node, ptr_type_node,
+		   ECF_NOTHROW | ECF_TM_PURE);
+	      record_tm_replacement (fn, itm_fn);
+	    }
 	}
     }
 
@@ -221,26 +231,32 @@ dtor_nothrow (tree type)
 static tree
 do_end_catch (tree type)
 {
-  tree fn, cleanup;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_end_catch");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void __cxa_end_catch ().
-         This can throw if the destructor for the exception throws.  */
-      fn = push_void_library_fn (fn, void_list_node, 0);
-
-      /* Create its transactional-memory equivalent.  */
-      if (flag_tm)
+      tree name = get_identifier ("__cxa_end_catch");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
 	{
-	  tree fn2 = get_identifier ("_ITM_cxa_end_catch");
-	  if (!get_global_value_if_present (fn2, &fn2))
-	    fn2 = push_void_library_fn (fn2, void_list_node, ECF_TM_PURE);
-	  record_tm_replacement (fn, fn2);
+	  /* Declare void __cxa_end_catch ().
+	     This can throw if the destructor for the exception throws.  */
+	  fn = push_void_library_fn (name, void_list_node, 0);
+
+	  /* Create its transactional-memory equivalent.  */
+	  if (flag_tm)
+	    {
+	      tree itm_name = get_identifier ("_ITM_cxa_end_catch");
+	      tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+	      if (!itm_fn)
+		itm_fn = push_void_library_fn
+		  (itm_name, void_list_node, ECF_TM_PURE);
+	      record_tm_replacement (fn, itm_fn);
+	    }
 	}
     }
 
-  cleanup = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
+  tree cleanup = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
   TREE_NOTHROW (cleanup) = dtor_nothrow (type);
 
   return cleanup;
@@ -500,23 +516,28 @@ finish_eh_spec_block (tree raw_raises, t
 static tree
 do_allocate_exception (tree type)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_allocate_exception");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void *__cxa_allocate_exception(size_t) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, size_type_node,
-			        ECF_NOTHROW | ECF_MALLOC);
-
-      if (flag_tm)
-	{
-	  tree fn2 = get_identifier ("_ITM_cxa_allocate_exception");
-	  if (!get_global_value_if_present (fn2, &fn2))
-	    fn2 = declare_library_fn (fn2, ptr_type_node,
-				      size_type_node, 
-				      ECF_NOTHROW | ECF_MALLOC | ECF_TM_PURE);
-	  record_tm_replacement (fn, fn2);
+      tree name = get_identifier ("__cxa_allocate_exception");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	{
+	  /* Declare void *__cxa_allocate_exception(size_t) throw().  */
+	  fn = declare_library_fn (name, ptr_type_node, size_type_node,
+				   ECF_NOTHROW | ECF_MALLOC);
+
+	  if (flag_tm)
+	    {
+	      tree itm_name = get_identifier ("_ITM_cxa_allocate_exception");
+	      tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+	      if (!itm_fn)
+		itm_fn = declare_library_fn
+		  (itm_name, ptr_type_node, size_type_node, 
+		   ECF_NOTHROW | ECF_MALLOC | ECF_TM_PURE);
+	      record_tm_replacement (fn, itm_fn);
+	    }
 	}
     }
 
@@ -530,23 +551,28 @@ do_allocate_exception (tree type)
 static tree
 do_free_exception (tree ptr)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_free_exception");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void __cxa_free_exception (void *) throw().  */
-      fn = declare_library_fn (fn, void_type_node, ptr_type_node,
-			       ECF_NOTHROW | ECF_LEAF);
-
-      if (flag_tm)
-	{
-	  tree fn2 = get_identifier ("_ITM_cxa_free_exception");
-	  if (!get_global_value_if_present (fn2, &fn2))
-	    fn2 = declare_library_fn (fn2, void_type_node,
-				      ptr_type_node,
-				      ECF_NOTHROW | ECF_LEAF | ECF_TM_PURE);
-	  record_tm_replacement (fn, fn2);
+      tree name = get_identifier ("__cxa_free_exception");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	{
+	  /* Declare void __cxa_free_exception (void *) throw().  */
+	  fn = declare_library_fn (name, void_type_node, ptr_type_node,
+				   ECF_NOTHROW | ECF_LEAF);
+
+	  if (flag_tm)
+	    {
+	      tree itm_name = get_identifier ("_ITM_cxa_free_exception");
+	      tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+	      if (!itm_fn)
+		itm_fn = declare_library_fn
+		  (itm_name, void_type_node, ptr_type_node,
+		   ECF_NOTHROW | ECF_LEAF | ECF_TM_PURE);
+	      record_tm_replacement (fn, itm_fn);
+	    }
 	}
     }
 
@@ -588,8 +614,6 @@ wrap_cleanups_r (tree *tp, int *walk_sub
 tree
 build_throw (tree exp)
 {
-  tree fn;
-
   if (exp == error_mark_node)
     return exp;
 
@@ -616,6 +640,7 @@ build_throw (tree exp)
 
   if (exp)
     {
+      static tree throw_fn;
       tree throw_type;
       tree temp_type;
       tree cleanup;
@@ -631,23 +656,28 @@ build_throw (tree exp)
 	  cleanup_type = build_pointer_type (tmp);
 	}
 
-      fn = get_identifier ("__cxa_throw");
-      if (!get_global_value_if_present (fn, &fn))
+      if (!throw_fn)
 	{
-	  /* Declare void __cxa_throw (void*, void*, void (*)(void*)).  */
-	  /* ??? Second argument is supposed to be "std::type_info*".  */
-	  tmp = build_function_type_list (void_type_node,
-					  ptr_type_node, ptr_type_node,
-					  cleanup_type, NULL_TREE);
-	  fn = push_throw_library_fn (fn, tmp);
-
-	  if (flag_tm)
+	  tree name = get_identifier ("__cxa_throw");
+	  throw_fn = IDENTIFIER_GLOBAL_VALUE (name);
+	  if (!throw_fn)
 	    {
-	      tree fn2 = get_identifier ("_ITM_cxa_throw");
-	      if (!get_global_value_if_present (fn2, &fn2))
-		fn2 = push_throw_library_fn (fn2, tmp);
-	      apply_tm_attr (fn2, get_identifier ("transaction_pure"));
-	      record_tm_replacement (fn, fn2);
+	      /* Declare void __cxa_throw (void*, void*, void (*)(void*)).  */
+	      /* ??? Second argument is supposed to be "std::type_info*".  */
+	      tmp = build_function_type_list (void_type_node,
+					      ptr_type_node, ptr_type_node,
+					      cleanup_type, NULL_TREE);
+	      throw_fn = push_throw_library_fn (name, tmp);
+
+	      if (flag_tm)
+		{
+		  tree itm_name = get_identifier ("_ITM_cxa_throw");
+		  tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+		  if (!itm_fn)
+		    itm_fn = push_throw_library_fn (itm_name, tmp);
+		  apply_tm_attr (itm_fn, get_identifier ("transaction_pure"));
+		  record_tm_replacement (throw_fn, itm_fn);
+		}
 	    }
 	}
 
@@ -739,22 +769,22 @@ build_throw (tree exp)
       cleanup = NULL_TREE;
       if (type_build_dtor_call (TREE_TYPE (object)))
 	{
-	  tree fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)),
-				     complete_dtor_identifier, 0);
-	  fn = BASELINK_FUNCTIONS (fn);
-	  mark_used (fn);
+	  tree dtor_fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)),
+					  complete_dtor_identifier, 0);
+	  dtor_fn = BASELINK_FUNCTIONS (dtor_fn);
+	  mark_used (dtor_fn);
 	  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (object)))
 	    {
-	      cxx_mark_addressable (fn);
+	      cxx_mark_addressable (dtor_fn);
 	      /* Pretend it's a normal function.  */
-	      cleanup = build1 (ADDR_EXPR, cleanup_type, fn);
+	      cleanup = build1 (ADDR_EXPR, cleanup_type, dtor_fn);
 	    }
 	}
       if (cleanup == NULL_TREE)
 	cleanup = build_int_cst (cleanup_type, 0);
 
       /* ??? Indicate that this function call throws throw_type.  */
-      tmp = cp_build_function_call_nary (fn, tf_warning_or_error,
+      tmp = cp_build_function_call_nary (throw_fn, tf_warning_or_error,
 					 ptr, throw_type, cleanup, NULL_TREE);
 
       /* Tack on the initialization stuff.  */
@@ -763,21 +793,24 @@ build_throw (tree exp)
   else
     {
       /* Rethrow current exception.  */
+      static tree rethrow_fn;
 
-      tree fn = get_identifier ("__cxa_rethrow");
-      if (!get_global_value_if_present (fn, &fn))
+      if (!rethrow_fn)
 	{
-	  /* Declare void __cxa_rethrow (void).  */
-	  fn = push_throw_library_fn
-	    (fn, build_function_type_list (void_type_node, NULL_TREE));
-	}
+	  tree name = get_identifier ("__cxa_rethrow");
+	  rethrow_fn = IDENTIFIER_GLOBAL_VALUE (name);
+	  if (!rethrow_fn)
+	    /* Declare void __cxa_rethrow (void).  */
+	    rethrow_fn = push_throw_library_fn
+	      (name, build_function_type_list (void_type_node, NULL_TREE));
 
-      if (flag_tm)
-	apply_tm_attr (fn, get_identifier ("transaction_pure"));
+	  if (flag_tm)
+	    apply_tm_attr (rethrow_fn, get_identifier ("transaction_pure"));
+	}
 
       /* ??? Indicate that this function call allows exceptions of the type
 	 of the enclosing catch block (if known).  */
-      exp = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
+      exp = cp_build_function_call_vec (rethrow_fn, NULL, tf_warning_or_error);
     }
 
   exp = build1 (THROW_EXPR, void_type_node, exp);
Index: init.c
===================================================================
--- init.c	(revision 247647)
+++ init.c	(working copy)
@@ -2402,10 +2402,16 @@ diagnose_uninitialized_cst_or_ref_member
 tree
 throw_bad_array_new_length (void)
 {
-  tree fn = get_identifier ("__cxa_throw_bad_array_new_length");
-  if (!get_global_value_if_present (fn, &fn))
-    fn = push_throw_library_fn (fn, build_function_type_list (sizetype,
-							      NULL_TREE));
+  static tree fn;
+  if (!fn)
+    {
+      tree name = get_identifier ("__cxa_throw_bad_array_new_length");
+
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	fn = push_throw_library_fn
+	  (name, build_function_type_list (sizetype, NULL_TREE));
+    }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
 }
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 247647)
+++ name-lookup.c	(working copy)
@@ -37,6 +37,8 @@ static cxx_binding *cxx_binding_make (tr
 static cp_binding_level *innermost_nonclass_level (void);
 static void set_identifier_type_value_with_scope (tree id, tree decl,
 						  cp_binding_level *b);
+static void set_namespace_binding (tree name, tree scope, tree val);
+
 /* The bindings for a particular name in a particular scope.  */
 
 struct scope_binding {
@@ -213,7 +215,7 @@ arg_assoc_namespace (struct arg_lookup *
       if (arg_assoc_namespace (k, TREE_PURPOSE (value)))
 	return true;
 
-  value = namespace_binding (k->name, scope);
+  value = get_namespace_value (scope, k->name);
   if (!value)
     return false;
 
@@ -1248,7 +1250,7 @@ pushdecl_maybe_friend_1 (tree x, bool is
       /* In case this decl was explicitly namespace-qualified, look it
 	 up in its namespace context.  */
       if (DECL_NAMESPACE_SCOPE_P (x) && namespace_bindings_p ())
-	t = namespace_binding (name, DECL_CONTEXT (x));
+	t = get_namespace_value (DECL_CONTEXT (x), name);
       else
 	t = lookup_name_innermost_nonclass_level (name);
 
@@ -1265,7 +1267,7 @@ pushdecl_maybe_friend_1 (tree x, bool is
 	  t = innermost_non_namespace_value (name);
 	  /* Or in the innermost namespace.  */
 	  if (! t)
-	    t = namespace_binding (name, DECL_CONTEXT (x));
+	    t = get_namespace_value (DECL_CONTEXT (x), name);
 	  /* Does it have linkage?  Note that if this isn't a DECL, it's an
 	     OVERLOAD, which is OK.  */
 	  if (t && DECL_P (t) && ! (TREE_STATIC (t) || DECL_EXTERNAL (t)))
@@ -1519,7 +1521,7 @@ pushdecl_maybe_friend_1 (tree x, bool is
 	{
 	  tree decl;
 
-	  decl = IDENTIFIER_NAMESPACE_VALUE (name);
+	  decl = get_namespace_value (current_namespace, name);
 	  if (decl && TREE_CODE (decl) == OVERLOAD)
 	    decl = OVL_FUNCTION (decl);
 
@@ -1556,7 +1558,7 @@ pushdecl_maybe_friend_1 (tree x, bool is
 		  || TREE_CODE (x) == NAMESPACE_DECL
 		  || TREE_CODE (x) == CONST_DECL
 		  || TREE_CODE (x) == TEMPLATE_DECL))
-	    SET_IDENTIFIER_NAMESPACE_VALUE (name, x);
+	    set_namespace_binding (name, current_namespace, x);
 
 	  /* If new decl is `static' and an `extern' was seen previously,
 	     warn about it.  */
@@ -1566,7 +1568,7 @@ pushdecl_maybe_friend_1 (tree x, bool is
       else
 	{
 	  /* Here to install a non-global value.  */
-	  tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name);
+	  tree oldglobal = get_namespace_value (current_namespace, name);
 	  tree oldlocal = NULL_TREE;
 	  cp_binding_level *oldscope = NULL;
 	  cxx_binding *oldbinding = outer_binding (name, NULL, true);
@@ -1605,7 +1607,8 @@ pushdecl_maybe_friend_1 (tree x, bool is
 		oldlocal = DECL_SHADOWED_FOR_VAR (oldlocal);
 
 	      if (oldlocal == NULL_TREE)
-		oldlocal = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (d));
+		oldlocal
+		  = get_namespace_value (current_namespace, DECL_NAME (d));
 	    }
 
 	  /* If this is an extern function declaration, see if we
@@ -1969,7 +1972,7 @@ check_for_out_of_scope_variable (tree de
     shadowed = DECL_HAS_SHADOWED_FOR_VAR_P (shadowed)
       ? DECL_SHADOWED_FOR_VAR (shadowed) : NULL_TREE;
   if (!shadowed)
-    shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (decl));
+    shadowed = get_namespace_value (current_namespace, DECL_NAME (decl));
   if (shadowed)
     {
       if (!DECL_ERROR_REPORTED (decl))
@@ -2931,7 +2934,7 @@ push_overloaded_decl_1 (tree decl, int f
   int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
 
   if (doing_global)
-    old = namespace_binding (name, DECL_CONTEXT (decl));
+    old = get_namespace_value (DECL_CONTEXT (decl), name);
   else
     old = lookup_name_innermost_nonclass_level (name);
 
@@ -4016,20 +4019,22 @@ namespace_binding_1 (tree name, tree sco
   return binding ? binding->value : NULL_TREE;
 }
 
+/* Return the binding for NAME in NS.  If NS is NULL, look in
+   global_namespace.  */
+
 tree
-namespace_binding (tree name, tree scope)
+get_namespace_value (tree ns, tree name)
 {
-  tree ret;
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  ret = namespace_binding_1 (name, scope);
+  if (!ns)
+    ns = global_namespace;
+  tree ret = namespace_binding_1 (name, ns);
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
   return ret;
 }
 
-/* Set the binding value for name in scope.  */
-
 static void
-set_namespace_binding_1 (tree name, tree scope, tree val)
+set_namespace_binding (tree name, tree scope, tree val)
 {
   cxx_binding *b;
 
@@ -4047,13 +4052,16 @@ set_namespace_binding_1 (tree name, tree
     supplement_binding (b, val);
 }
 
-/* Wrapper for set_namespace_binding_1.  */
+/* Set NAME in the global namespace to VAL.  Does not add it to the
+   list of things in the namespace.  */
 
 void
-set_namespace_binding (tree name, tree scope, tree val)
+set_global_value (tree name, tree val)
 {
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  set_namespace_binding_1 (name, scope, val);
+
+  set_namespace_binding (name, global_namespace, val);
+
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
 }
 
@@ -5815,7 +5823,7 @@ lookup_name_innermost_nonclass_level_1 (
 
   if (b->kind == sk_namespace)
     {
-      t = IDENTIFIER_NAMESPACE_VALUE (name);
+      t = get_namespace_value (current_namespace, name);
 
       /* extern "C" function() */
       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
@@ -6467,7 +6475,7 @@ push_namespace (tree name)
   if (anon)
     {
       name = anon_identifier;
-      d = IDENTIFIER_NAMESPACE_VALUE (name);
+      d = get_namespace_value (current_namespace, name);
       if (d)
 	/* Reopening anonymous namespace.  */
 	need_new = false;
@@ -6476,7 +6484,7 @@ push_namespace (tree name)
   else
     {
       /* Check whether this is an extended namespace definition.  */
-      d = IDENTIFIER_NAMESPACE_VALUE (name);
+      d = get_namespace_value (current_namespace, name);
       if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
 	{
 	  tree dna = DECL_NAMESPACE_ALIAS (d);
Index: name-lookup.h
===================================================================
--- name-lookup.h	(revision 247647)
+++ name-lookup.h	(working copy)
@@ -311,8 +311,8 @@ extern tree pushdecl_with_scope (tree, c
 extern tree lookup_name_prefer_type (tree, int);
 extern tree lookup_name_real (tree, int, int, bool, int, int);
 extern tree lookup_type_scope (tree, tag_scope);
-extern tree namespace_binding (tree, tree);
-extern void set_namespace_binding (tree, tree, tree);
+extern tree get_namespace_value (tree ns, tree id);
+extern void set_global_value (tree id, tree val);
 extern bool hidden_name_p (tree);
 extern tree remove_hidden_names (tree);
 extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false);
@@ -342,26 +342,4 @@ extern tree innermost_non_namespace_valu
 extern cxx_binding *outer_binding (tree, cxx_binding *, bool);
 extern void cp_emit_debug_info_for_using (tree, tree);
 
-/* Set *DECL to the (non-hidden) declaration for ID at global scope,
-   if present and return true; otherwise return false.  */
-
-inline bool
-get_global_value_if_present (tree id, tree *decl)
-{
-  tree global_value = namespace_binding (id, global_namespace);
-  if (global_value)
-    *decl = global_value;
-  return global_value != NULL;
-}
-
-/* True is the binding of IDENTIFIER at global scope names a type.  */
-
-inline bool
-is_typename_at_global_scope (tree id)
-{
-  tree global_value = namespace_binding (id, global_namespace);
-
-  return global_value && TREE_CODE (global_value) == TYPE_DECL;
-}
-
 #endif /* GCC_CP_NAME_LOOKUP_H */
Index: pt.c
===================================================================
--- pt.c	(revision 247647)
+++ pt.c	(working copy)
@@ -24731,7 +24731,7 @@ make_constrained_auto (tree con, tree ar
 static tree
 listify (tree arg)
 {
-  tree std_init_list = namespace_binding (init_list_identifier, std_node);
+  tree std_init_list = get_namespace_value (std_node, init_list_identifier);
   tree argvec;
   if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list))
     {    
Index: rtti.c
===================================================================
--- rtti.c	(revision 247647)
+++ rtti.c	(working copy)
@@ -202,10 +202,15 @@ build_headof (tree exp)
 static tree
 throw_bad_cast (void)
 {
-  tree fn = get_identifier ("__cxa_bad_cast");
-  if (!get_global_value_if_present (fn, &fn))
-    fn = push_throw_library_fn (fn, build_function_type_list (ptr_type_node,
-							      NULL_TREE));
+  static tree fn;
+  if (!fn)
+    {
+      tree name = get_identifier ("__cxa_bad_cast");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	fn = push_throw_library_fn
+	  (name, build_function_type_list (ptr_type_node, NULL_TREE));
+    }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
 }
@@ -216,14 +221,17 @@ throw_bad_cast (void)
 static tree
 throw_bad_typeid (void)
 {
-  tree fn = get_identifier ("__cxa_bad_typeid");
-  if (!get_global_value_if_present (fn, &fn))
+  static tree fn;
+  if (!fn)
     {
-      tree t;
-
-      t = build_reference_type (const_type_info_type_node);
-      t = build_function_type_list (t, NULL_TREE);
-      fn = push_throw_library_fn (fn, t);
+      tree name = get_identifier ("__cxa_bad_typeid");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+	{
+	  tree t = build_reference_type (const_type_info_type_node);
+	  t = build_function_type_list (t, NULL_TREE);
+	  fn = push_throw_library_fn (name, t);
+	}
     }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
