Index: testsuite/gcc.dg/tm/20100615-2.c
===================================================================
--- testsuite/gcc.dg/tm/20100615-2.c	(revision 0)
+++ testsuite/gcc.dg/tm/20100615-2.c	(revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O" } */
+
+__attribute__((transaction_safe))
+void Info_RemoveKey (char *s)
+{
+        char    *o = 0;
+        while (1)
+        {
+                s++;
+                while (*s)
+                {
+                        if (!*s)
+                                return;
+                        *o++ = *s++;
+                }
+                *o = 0;
+        }
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 160765)
+++ trans-mem.c	(working copy)
@@ -1268,12 +1268,16 @@ thread_private_new_memory (basic_block e
 
   /* Look in cache first.  */
   elt.val = x;
-  slot = htab_find_slot (tm_new_mem_hash, &elt, NO_INSERT);
-  if (slot)
-    {
-      elt_p = (tm_new_mem_map_t *) *slot;
-      return elt_p->local_new_memory;
-    }
+  slot = htab_find_slot (tm_new_mem_hash, &elt, INSERT);
+  elt_p = (tm_new_mem_map_t *) *slot;
+  if (elt_p)
+    return elt_p->local_new_memory;
+
+  /* Optimistically assume the memory is transaction local during
+     processing.  This catches recursion into this variable.  */
+  *slot = elt_p = XNEW (tm_new_mem_map_t);
+  elt_p->val = val;
+  elt_p->local_new_memory = mem_transaction_local;
 
   /* Search DEF chain to find the original definition of this address.  */
   do
@@ -1353,15 +1357,7 @@ thread_private_new_memory (basic_block e
     retval = mem_non_local;
 
  new_memory_ret:
-  /* A recursive call to thread_private_new_memory() may change the
-     slot from under us if we resize the hash table, so get a fresh
-     slot after all is said and done.  */
-  slot = htab_find_slot (tm_new_mem_hash, &elt, INSERT);
-
-  elt_p = XNEW (tm_new_mem_map_t);
-  elt_p->val = val;
   elt_p->local_new_memory = retval;
-  *slot = elt_p;
   return retval;
 }
 
