diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-28 17:14:23 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-28 17:14:23 +0000 |
commit | 33591af872045194dc00321041affb92810183b4 (patch) | |
tree | b02247daec28a286915db98fc39eb88fe73c4a0e /lib/Transforms/InstCombine | |
parent | 67d0498d533eedab90e5b6399669c420abbde7c6 (diff) | |
download | llvm-33591af872045194dc00321041affb92810183b4.tar.gz llvm-33591af872045194dc00321041affb92810183b4.tar.bz2 llvm-33591af872045194dc00321041affb92810183b4.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109596 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index fc62bb0cf8..0d5e30205a 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -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) |