summaryrefslogtreecommitdiff
path: root/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-07-30 22:27:10 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-07-30 22:27:10 +0000
commit3181f5900ff5d9800c38284c7d3427cb6e306c9a (patch)
treee2fce977733b49c461d216d9b66e45e6f7b6a32a /lib/IR/ConstantFold.cpp
parent485c7fd76b32a69c46782a715682ed8831b0873b (diff)
downloadllvm-3181f5900ff5d9800c38284c7d3427cb6e306c9a.tar.gz
llvm-3181f5900ff5d9800c38284c7d3427cb6e306c9a.tar.bz2
llvm-3181f5900ff5d9800c38284c7d3427cb6e306c9a.tar.xz
Respect address space sizes in isEliminableCastPair.
This avoids constant folding bitcast/ptrtoint/inttoptr combinations that have illegal bitcasts between differently sized address spaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187455 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/ConstantFold.cpp')
-rw-r--r--lib/IR/ConstantFold.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp
index da9762fa62..8c5a983701 100644
--- a/lib/IR/ConstantFold.cpp
+++ b/lib/IR/ConstantFold.cpp
@@ -75,7 +75,7 @@ static unsigned
foldConstantCastPair(
unsigned opc, ///< opcode of the second cast constant expression
ConstantExpr *Op, ///< the first cast constant expression
- Type *DstTy ///< desintation type of the first cast
+ Type *DstTy ///< destination type of the first cast
) {
assert(Op && Op->isCast() && "Can't fold cast of cast without a cast!");
assert(DstTy && DstTy->isFirstClassType() && "Invalid cast destination type");
@@ -87,13 +87,14 @@ foldConstantCastPair(
Instruction::CastOps firstOp = Instruction::CastOps(Op->getOpcode());
Instruction::CastOps secondOp = Instruction::CastOps(opc);
- // Assume that pointers are never more than 64 bits wide.
+ // Assume that pointers are never more than 64 bits wide, and only use this
+ // for the middle type. Otherwise we could end up folding away illegal
+ // bitcasts between address spaces with different sizes.
IntegerType *FakeIntPtrTy = Type::getInt64Ty(DstTy->getContext());
// Let CastInst::isEliminableCastPair do the heavy lifting.
return CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy,
- FakeIntPtrTy, FakeIntPtrTy,
- FakeIntPtrTy);
+ 0, FakeIntPtrTy, 0);
}
static Constant *FoldBitCast(Constant *V, Type *DestTy) {