aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2018-01-05 16:18:47 +0000
committerDavide Italiano <davide@freebsd.org>2018-01-05 16:18:47 +0000
commit554f68be445c7d4f0dbd33ccdaa4ce77f76f79e5 (patch)
tree31d3c19edc18fefc3b3baac2e1e71736213c2c59 /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parentfa13848da8e16c1721bf68b42c92a6726c1fc9e0 (diff)
downloadllvm-554f68be445c7d4f0dbd33ccdaa4ce77f76f79e5.zip
llvm-554f68be445c7d4f0dbd33ccdaa4ce77f76f79e5.tar.gz
llvm-554f68be445c7d4f0dbd33ccdaa4ce77f76f79e5.tar.bz2
[BasicAA] Fix linearization of shifts beyond the bitwidth.
Thanks to Simon Pilgrim for the reduced testcase. Fixes PR35821. llvm-svn: 321873
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 537813b..5a2401f 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -285,6 +285,19 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
case Instruction::Shl:
V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
+
+ // We're trying to linearize an expression of the kind:
+ // shl i8 -128, 36
+ // where the shift count exceeds the bitwidth of the type.
+ // We can't decompose this further (the expression would return
+ // a poison value).
+ if (Offset.getBitWidth() < RHS.getLimitedValue() ||
+ Scale.getBitWidth() < RHS.getLimitedValue()) {
+ Scale = 1;
+ Offset = 0;
+ return V;
+ }
+
Offset <<= RHS.getLimitedValue();
Scale <<= RHS.getLimitedValue();
// the semantics of nsw and nuw for left shifts don't match those of