aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-02-05 19:04:36 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-02-05 19:04:36 +0000
commitfaf601ee936a440027447fa11ef400cf53bc1acf (patch)
treea7a2ae5d256cb4048a7c081ae723ddde45397d5c /lib/Analysis
parent7d80dad40741ecc2e45943f685bf539eeed2ba51 (diff)
downloadexternal_llvm-faf601ee936a440027447fa11ef400cf53bc1acf.zip
external_llvm-faf601ee936a440027447fa11ef400cf53bc1acf.tar.gz
external_llvm-faf601ee936a440027447fa11ef400cf53bc1acf.tar.bz2
ConstantFolding: Fix a crash when encoutering a truncating inttoptr.
This was introduced in r173293. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ConstantFolding.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 400ce72..91424b2 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -545,14 +545,18 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0,
// constant. This happens frequently when iterating over a global array.
if (Opc == Instruction::Sub && TD) {
GlobalValue *GV1, *GV2;
- APInt Offs1(TD->getPointerSizeInBits(), 0),
- Offs2(TD->getPointerSizeInBits(), 0);
+ unsigned PtrSize = TD->getPointerSizeInBits();
+ unsigned OpSize = TD->getTypeSizeInBits(Op0->getType());
+ APInt Offs1(PtrSize, 0), Offs2(PtrSize, 0);
if (IsConstantOffsetFromGlobal(Op0, GV1, Offs1, *TD))
if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) &&
GV1 == GV2) {
// (&GV+C1) - (&GV+C2) -> C1-C2, pointer arithmetic cannot overflow.
- return ConstantInt::get(Op0->getType(), Offs1-Offs2);
+ // PtrToInt may change the bitwidth so we have convert to the right size
+ // first.
+ return ConstantInt::get(Op0->getType(), Offs1.zextOrTrunc(OpSize) -
+ Offs2.zextOrTrunc(OpSize));
}
}