diff mbox series

[PUSHED] Off by one final fix.

Message ID 3e6ab53f-7d14-c0c7-f0ac-e36188fbf907@redhat.com
State New
Headers show
Series [PUSHED] Off by one final fix. | expand

Commit Message

Andrew MacLeod Oct. 7, 2020, 2 p.m. UTC
On 10/6/20 2:59 PM, Andrew MacLeod via Gcc-patches wrote:
> On 10/6/20 2:41 PM, Andreas Schwab wrote:
>> On Okt 06 2020, Andrew MacLeod via Gcc-patches wrote:
>>
>>> diff --git a/gcc/value-range.h b/gcc/value-range.h
>>> index 7031a823138..02a952bf81f 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 irnge and  required memory for the vector
>> Typo: irange
>>
>> Andreas.
>>
> Ha. Its all good now.     THIS is actually the final final FINAL patch 
> which is going thru testing.
>
>
And its now in.
diff mbox series

Patch


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.


diff --git a/gcc/value-range.h b/gcc/value-range.h
index 7031a823138..63c96204cda 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 *