[llvm-commits] [llvm] r109596 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
Dan Gohman
gohman at apple.com
Wed Jul 28 10:14:23 PDT 2010
Author: djg
Date: Wed Jul 28 12:14:23 2010
New Revision: 109596
URL: http://llvm.org/viewvc/llvm-project?rev=109596&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=109596&r1=109595&r2=109596&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Jul 28 12:14:23 2010
@@ -96,12 +96,17 @@
/// 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)
More information about the llvm-commits
mailing list