Skip to content

Commit

Permalink
Merge pull request #6622 from kinke/fixEffectiveAlignment
Browse files Browse the repository at this point in the history
[stable] Fix std.experimental.allocator.common.effectiveAlignment()
  • Loading branch information
wilzbach committed Jul 3, 2018
2 parents c14e879 + cce5771 commit 320d4f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private mixin template BitmappedBlockImpl(bool isShared, bool multiBlock)
auto leadingUlongs = blocks.divideRoundUp(64);
import std.algorithm.comparison : min;
immutable initialAlignment = min(parentAlignment,
1U << trailingZeros(leadingUlongs * 8));
1U << min(31U, trailingZeros(leadingUlongs * 8)));
auto maxSlack = alignment <= initialAlignment
? 0
: alignment - initialAlignment;
Expand Down
7 changes: 5 additions & 2 deletions std/experimental/allocator/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,19 @@ Returns the effective alignment of `ptr`, i.e. the largest power of two that is
a divisor of `ptr`.
*/
@nogc nothrow pure
package uint effectiveAlignment(void* ptr)
package size_t effectiveAlignment(void* ptr)
{
return 1U << trailingZeros(cast(size_t) ptr);
return (cast(size_t) 1) << trailingZeros(cast(size_t) ptr);
}

@nogc nothrow pure
@system unittest
{
int x;
assert(effectiveAlignment(&x) >= int.alignof);

const max = (cast(size_t) 1) << (size_t.sizeof * 8 - 1);
assert(effectiveAlignment(cast(void*) max) == max);
}

/*
Expand Down

0 comments on commit 320d4f8

Please sign in to comment.