mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 11:33:24 +02:00
When user code intentionally dereferences null, the alignment of the
dereference is theoretically infinite. Put a cap on the computed alignment to avoid overflow, noticed by John Regehr. llvm-svn: 109596
This commit is contained in:
parent
041bd99662
commit
5295c21189
@ -96,12 +96,17 @@ static unsigned EnforceKnownAlignment(Value *V,
|
||||
/// increase the alignment of the ultimate object, making this check succeed.
|
||||
unsigned InstCombiner::GetOrEnforceKnownAlignment(Value *V,
|
||||
unsigned PrefAlign) {
|
||||
unsigned BitWidth = TD ? TD->getTypeSizeInBits(V->getType()) :
|
||||
sizeof(PrefAlign) * CHAR_BIT;
|
||||
assert(V->getType()->isPointerTy() &&
|
||||
"GetOrEnforceKnownAlignment expects a pointer!");
|
||||
unsigned BitWidth = TD ? TD->getPointerSizeInBits() : 64;
|
||||
APInt Mask = APInt::getAllOnesValue(BitWidth);
|
||||
APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
|
||||
ComputeMaskedBits(V, Mask, KnownZero, KnownOne);
|
||||
unsigned TrailZ = KnownZero.countTrailingOnes();
|
||||
|
||||
// LLVM doesn't support alignments larger than this currently.
|
||||
TrailZ = std::min(TrailZ, unsigned(sizeof(unsigned) * CHAR_BIT - 1));
|
||||
|
||||
unsigned Align = 1u << std::min(BitWidth - 1, TrailZ);
|
||||
|
||||
if (PrefAlign > Align)
|
||||
|
Loading…
Reference in New Issue
Block a user