diff options
author | Jason Merrill <jason@redhat.com> | 2012-01-16 11:40:26 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-01-16 11:40:26 -0500 |
commit | 7aeb037b25f4624d0a7ea6b1184047135e56b036 (patch) | |
tree | 0a040cd4dffd34e0257f4bd213032cc98bdb37bb /gcc/vec.c | |
parent | 00fbd5c8c7bfa737f289517e5248bf249fdbf1a3 (diff) | |
download | gcc-7aeb037b25f4624d0a7ea6b1184047135e56b036.zip gcc-7aeb037b25f4624d0a7ea6b1184047135e56b036.tar.gz gcc-7aeb037b25f4624d0a7ea6b1184047135e56b036.tar.bz2 |
re PR c++/14179 (out of memory while parsing array with many initializers)
PR c++/14179
* vec.c (vec_gc_o_reserve_1): Use ggc_round_alloc_size.
From-SVN: r183213
Diffstat (limited to 'gcc/vec.c')
-rw-r--r-- | gcc/vec.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -221,6 +221,7 @@ 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); + size_t size; if (!alloc) { @@ -229,7 +230,17 @@ vec_gc_o_reserve_1 (void *vec, int reserve, size_t vec_offset, size_t elt_size, return NULL; } - vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size PASS_MEM_STAT); + /* Calculate the amount of space we want. */ + size = vec_offset + alloc * elt_size; + /* Ask the allocator how much space it will really give us. */ + size = ggc_round_alloc_size (size); + /* Adjust the number of slots accordingly. */ + alloc = (size - vec_offset) / elt_size; + /* And finally, recalculate the amount of space we ask for. */ + size = vec_offset + alloc * elt_size; + + vec = ggc_realloc_stat (vec, size PASS_MEM_STAT); + ((struct vec_prefix *)vec)->alloc = alloc; if (!pfx) ((struct vec_prefix *)vec)->num = 0; |