summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-07-28 17:14:23 +0000
committerDan Gohman <gohman@apple.com>2010-07-28 17:14:23 +0000
commit9cd20bf7928b55a40d85d3735944b2148a99959c (patch)
tree5784f05787363f79ccbd6dfc78e09a7c28084c6e /llvm/lib/Transforms
parent32f889e552d5964c43ebc27385c2a79fb21fd74a (diff)
downloadbcm5719-llvm-9cd20bf7928b55a40d85d3735944b2148a99959c.tar.gz
bcm5719-llvm-9cd20bf7928b55a40d85d3735944b2148a99959c.zip
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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index fc62bb0cf84..0d5e30205a0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/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)
OpenPOWER on IntegriCloud