On Fri, Aug 26, 2011 at 02:34:29PM +0200, Michael Matz wrote:
> Hi,
> 
> On Fri, 26 Aug 2011, Richard Guenther wrote:
> 
> > >> I am going to be sending the renaming patch later today or tomorrow. 
> > >> In principle, the things I want to abstract are those that are 
> > >> forcing me to include lto-streamer.h from 
> > >> {tree,gimple,data}-streamer.*. I will know better when I merge this 
> > >> into the pph branch, though.
> > >
> > > Yeah, I think we discussed this already and agreed on that this is a 
> > > sensible plan.
> > 
> > This patch caused http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50165 it 
> > seems that LTO string hashing is seriously broken now.
> 
> Once regstrap passes on x86_64-linux I'm checking this in as obvious.

While you are touching it, I think we should also optimize it as in the
patch below.  I'm afraid no string length optimization would be able to
figure out that it doesn't have to call strlen twice, because the
htab_find_slot isn't pure.

2011-08-26  Jakub Jelinek  <ja...@redhat.com>

        * lto-streamer-in.c (canon_file_name): Avoid calling strlen twice,
        use memcpy instead of strcpy.

--- gcc/lto-streamer-in.c.jj    2011-08-26 14:39:52.000000000 +0200
+++ gcc/lto-streamer-in.c       2011-08-26 14:40:59.543884012 +0200
@@ -98,21 +98,20 @@ canon_file_name (const char *string)
 {
   void **slot;
   struct string_slot s_slot;
+  size_t len = strlen (string);
   s_slot.s = string;
-  s_slot.len = strlen (string);
+  s_slot.len = len;
 
   slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
   if (*slot == NULL)
     {
-      size_t len;
       char *saved_string;
       struct string_slot *new_slot;
 
-      len = strlen (string);
       saved_string = (char *) xmalloc (len + 1);
       new_slot = XCNEW (struct string_slot);
       new_slot->len = len;
-      strcpy (saved_string, string);
+      memcpy (saved_string, string, len + 1);
       new_slot->s = saved_string;
       *slot = new_slot;
       return saved_string;

        Jakub

Reply via email to