@@ -124,9 +124,10 @@ static std::string architecture_string(T value, const char *s)
124
124
125
125
using max_alloc_sizet = uint64_t ;
126
126
// / The maximum allocation size is determined by the number of bits that
127
- // / are left in the pointer of width \p pointer_width after allowing for the
128
- // / signed bit, and the bits used for the objects ID (determined by
129
- // / \p object_bits).
127
+ // / are left in the pointer of width \p pointer_width.
128
+ // /
129
+ // / The offset needs to be able to represent up to the allocation_size, and
130
+ // / down to -allocation_size, hence 2^(pointer_width - object_bits - 1)
130
131
// / \param pointer_width: The width of the pointer
131
132
// / \param object_bits : The number of bits used to represent the ID
132
133
// / \return The size in bytes of the maximum allocation supported.
@@ -136,9 +137,14 @@ max_malloc_size(std::size_t pointer_width, std::size_t object_bits)
136
137
PRECONDITION (pointer_width >= 1 );
137
138
PRECONDITION (object_bits < pointer_width - 1 );
138
139
PRECONDITION (object_bits >= 1 );
139
- const auto bits_for_offset = pointer_width - object_bits - 1 ;
140
- PRECONDITION (bits_for_offset < std::numeric_limits<max_alloc_sizet>::digits);
141
- return ((max_alloc_sizet)1 ) << (max_alloc_sizet)bits_for_offset;
140
+ const auto offset_bits = pointer_width - object_bits;
141
+ // We require the offset to be able to express upto allocation_size - 1,
142
+ // but also down to -allocation_size + 1, therefore the size is allowable
143
+ // is number of bits, less the signed bit.
144
+ const auto bits_for_positive_offset = offset_bits - 1 ;
145
+ PRECONDITION (
146
+ bits_for_positive_offset < std::numeric_limits<max_alloc_sizet>::digits);
147
+ return ((max_alloc_sizet)1 ) << (max_alloc_sizet)bits_for_positive_offset;
142
148
}
143
149
144
150
void ansi_c_internal_additions (std::string &code)
0 commit comments