aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2020-10-06 16:52:03 -0400
committerAndrew MacLeod <amacleod@redhat.com>2020-10-07 09:59:56 -0400
commit4e9213027587b807ca7e4bbde706b19102342d37 (patch)
tree97f41665c5165feb27f922df60bc220d17f0bb30 /gcc
parent7c7e841806aecf4187c69fc2ff07813c7be09582 (diff)
downloadgcc-4e9213027587b807ca7e4bbde706b19102342d37.zip
gcc-4e9213027587b807ca7e4bbde706b19102342d37.tar.gz
gcc-4e9213027587b807ca7e4bbde706b19102342d37.tar.bz2
Off by one final fix.
Allocate the memory in an approved portable way. gcc/ChangeLog: 2020-10-06 Andrew MacLeod <amacleod@redhat.com> * value-range.h (irange_allocator::allocate): Allocate in two hunks instead of using the variably-sized trailing array approach.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/value-range.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 7031a823..63c9620 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -668,13 +668,12 @@ irange_allocator::allocate (unsigned num_pairs)
if (num_pairs < 2)
num_pairs = 2;
- struct newir {
- irange range;
- tree mem[2];
- };
- size_t nbytes = (sizeof (newir) + sizeof (tree) * 2 * (num_pairs - 1));
- struct newir *r = (newir *) obstack_alloc (&m_obstack, nbytes);
- return new (r) irange (r->mem, num_pairs);
+ size_t nbytes = sizeof (tree) * 2 * num_pairs;
+
+ // Allocate the irange and required memory for the vector.
+ void *r = obstack_alloc (&m_obstack, sizeof (irange));
+ tree *mem = (tree *) obstack_alloc (&m_obstack, nbytes);
+ return new (r) irange (mem, num_pairs);
}
inline irange *