decl.c (annotate_value): Look up expression for insertion in the cache at the end.
authorAlexandre Oliva <aoliva@redhat.com>
Mon, 19 Sep 2011 12:32:02 +0000 (12:32 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Mon, 19 Sep 2011 12:32:02 +0000 (12:32 +0000)
* gcc-interface/decl.c (annotate_value): Look up expression for
insertion in the cache at the end.

From-SVN: r178970

gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c

index 6b8d1ebf0d293b4cf4f24576fd1365ad12421c3b..1d0a10cf32eb85f63fe6a02fb7dc00801ff66b89 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-19  Alexandre Oliva  <aoliva@redhat.com>
+
+       * gcc-interface/decl.c (annotate_value): Look up expression for
+       insertion in the cache at the end.
+
 2011-09-19  Arnaud Charlet  <charlet@adacore.com>
 
        * gcc-interface/Make-lang.in: Update dependencies.
index 0854d5da89be8e523378e5dd205261d75f231b84..a6bfd37c41f752cd7723d8884e2ba2b6d0954611 100644 (file)
@@ -7471,23 +7471,26 @@ annotate_value (tree gnu_size)
 {
   TCode tcode;
   Node_Ref_Or_Val ops[3], ret;
-  struct tree_int_map **h = NULL;
+  struct tree_int_map in;
   int i;
 
   /* See if we've already saved the value for this node.  */
   if (EXPR_P (gnu_size))
     {
-      struct tree_int_map in;
+      struct tree_int_map *e;
+
       if (!annotate_value_cache)
         annotate_value_cache = htab_create_ggc (512, tree_int_map_hash,
                                                tree_int_map_eq, 0);
       in.base.from = gnu_size;
-      h = (struct tree_int_map **)
-           htab_find_slot (annotate_value_cache, &in, INSERT);
+      e = (struct tree_int_map *)
+           htab_find (annotate_value_cache, &in);
 
-      if (*h)
-       return (Node_Ref_Or_Val) (*h)->to;
+      if (e)
+       return (Node_Ref_Or_Val) e->to;
     }
+  else
+    in.base.from = NULL_TREE;
 
   /* If we do not return inside this switch, TCODE will be set to the
      code to use for a Create_Node operand and LEN (set above) will be
@@ -7588,8 +7591,17 @@ annotate_value (tree gnu_size)
   ret = Create_Node (tcode, ops[0], ops[1], ops[2]);
 
   /* Save the result in the cache.  */
-  if (h)
+  if (in.base.from)
     {
+      struct tree_int_map **h;
+      /* We can't assume the hash table data hasn't moved since the
+        initial look up, so we have to search again.  Allocating and
+        inserting an entry at that point would be an alternative, but
+        then we'd better discard the entry if we decided not to cache
+        it.  */
+      h = (struct tree_int_map **)
+           htab_find_slot (annotate_value_cache, &in, INSERT);
+      gcc_assert (!*h);
       *h = ggc_alloc_tree_int_map ();
       (*h)->base.from = gnu_size;
       (*h)->to = ret;