OSDN Git Service

2011-08-18 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / vec.c
index 3e60580..c1d0034 100644 (file)
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -1,5 +1,6 @@
 /* Vector API for GNU compiler.
-   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010
+   Free Software Foundation, Inc.
    Contributed by Nathan Sidwell <nathan@codesourcery.com>
 
 This file is part of GCC.
@@ -27,20 +28,12 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 #include "system.h"
+#include "coretypes.h"
 #include "ggc.h"
 #include "vec.h"
-#include "coretypes.h"
-#include "toplev.h"
+#include "diagnostic-core.h"
 #include "hashtab.h"
 
-struct vec_prefix 
-{
-  unsigned num;
-  unsigned alloc;
-  void *vec[1];
-};
-
-
 #ifdef GATHER_STATISTICS
 
 /* Store information about each particular vector.  */
@@ -190,10 +183,10 @@ calculate_allocation (const struct vec_prefix *pfx, int reserve, bool exact)
     /* If there's no prefix, and we've not requested anything, then we
        will create a NULL vector.  */
     return 0;
-  
+
   /* We must have run out of room.  */
   gcc_assert (alloc - num < (unsigned) reserve);
-  
+
   if (exact)
     /* Exact size.  */
     alloc = num + reserve;
@@ -208,7 +201,7 @@ calculate_allocation (const struct vec_prefix *pfx, int reserve, bool exact)
       else
        /* Grow slower when large.  */
        alloc = (alloc * 3 / 2);
-      
+
       /* If this is still too small, set it to the right size. */
       if (alloc < num + reserve)
        alloc = num + reserve;
@@ -228,19 +221,19 @@ vec_gc_o_reserve_1 (void *vec, int reserve, size_t vec_offset, size_t elt_size,
 {
   struct vec_prefix *pfx = (struct vec_prefix *) vec;
   unsigned alloc = calculate_allocation (pfx, reserve, exact);
-  
+
   if (!alloc)
     {
       if (pfx)
         ggc_free (pfx);
       return NULL;
     }
-  
+
   vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size PASS_MEM_STAT);
   ((struct vec_prefix *)vec)->alloc = alloc;
   if (!pfx)
     ((struct vec_prefix *)vec)->num = 0;
-  
+
   return vec;
 }
 
@@ -253,7 +246,7 @@ void *
 vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_gc_o_reserve_1 (vec, reserve,
-                            offsetof (struct vec_prefix, vec),
+                            sizeof (struct vec_prefix),
                             sizeof (void *), false
                             PASS_MEM_STAT);
 }
@@ -267,7 +260,7 @@ void *
 vec_gc_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_gc_o_reserve_1 (vec, reserve,
-                            offsetof (struct vec_prefix, vec),
+                            sizeof (struct vec_prefix),
                             sizeof (void *), true
                             PASS_MEM_STAT);
 }
@@ -316,7 +309,7 @@ vec_heap_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
   if (vec)
     free_overhead (pfx);
 #endif
-  
+
   vec = xrealloc (vec, vec_offset + alloc * elt_size);
   ((struct vec_prefix *)vec)->alloc = alloc;
   if (!pfx)
@@ -326,7 +319,7 @@ vec_heap_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
     register_overhead ((struct vec_prefix *)vec,
                       vec_offset + alloc * elt_size PASS_MEM_STAT);
 #endif
-  
+
   return vec;
 }
 
@@ -336,7 +329,7 @@ void *
 vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_heap_o_reserve_1 (vec, reserve,
-                              offsetof (struct vec_prefix, vec),
+                              sizeof (struct vec_prefix),
                               sizeof (void *), false
                               PASS_MEM_STAT);
 }
@@ -347,7 +340,7 @@ void *
 vec_heap_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_heap_o_reserve_1 (vec, reserve,
-                              offsetof (struct vec_prefix, vec),
+                              sizeof (struct vec_prefix),
                               sizeof (void *), true
                               PASS_MEM_STAT);
 }
@@ -442,8 +435,8 @@ vec_stack_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
   if (newvec && vec)
     {
       ((struct vec_prefix *) newvec)->num = ((struct vec_prefix *) vec)->num;
-      memcpy (((struct vec_prefix *) newvec)->vec,
-             ((struct vec_prefix *) vec)->vec,
+      memcpy (((struct vec_prefix *) newvec)+1,
+             ((struct vec_prefix *) vec)+1,
              ((struct vec_prefix *) vec)->num * elt_size);
     }
   return newvec;
@@ -455,7 +448,7 @@ void *
 vec_stack_p_reserve (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_stack_o_reserve_1 (vec, reserve,
-                               offsetof (struct vec_prefix, vec),
+                               sizeof (struct vec_prefix),
                                sizeof (void *), false
                                PASS_MEM_STAT);
 }
@@ -466,7 +459,7 @@ void *
 vec_stack_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
 {
   return vec_stack_o_reserve_1 (vec, reserve,
-                               offsetof (struct vec_prefix, vec),
+                               sizeof (struct vec_prefix),
                                sizeof (void *), true
                                PASS_MEM_STAT);
 }