diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-28 20:12:04 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-28 20:12:04 +0000 |
commit | a7e5a240935a547d028a43800fdb8b8bcb47386f (patch) | |
tree | 92adfb5df05b97c01c3be040774f3a3c8518982b /llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | |
parent | d5010898ab66a638a7f7e427380a8b419e34561c (diff) | |
download | bcm5719-llvm-a7e5a240935a547d028a43800fdb8b8bcb47386f.tar.gz bcm5719-llvm-a7e5a240935a547d028a43800fdb8b8bcb47386f.zip |
Define a maximum supported alignment value for load, store, and
alloca instructions (constrained by their internal encoding),
and add error checking for it. Fix an instcombine bug which
generated huge alignment values (null is infinitely aligned).
This fixes undefined behavior noticed by John Regehr.
llvm-svn: 109643
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 0d5e30205a0..fdb2dd693d9 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -104,11 +104,15 @@ unsigned InstCombiner::GetOrEnforceKnownAlignment(Value *V, ComputeMaskedBits(V, Mask, KnownZero, KnownOne); unsigned TrailZ = KnownZero.countTrailingOnes(); - // LLVM doesn't support alignments larger than this currently. + // Avoid trouble with rediculously large TrailZ values, such as + // those computed from a null pointer. TrailZ = std::min(TrailZ, unsigned(sizeof(unsigned) * CHAR_BIT - 1)); unsigned Align = 1u << std::min(BitWidth - 1, TrailZ); + // LLVM doesn't support alignments larger than this currently. + Align = std::min(Align, MaximumAlignment); + if (PrefAlign > Align) Align = EnforceKnownAlignment(V, Align, PrefAlign); |