summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorMikael Holmen <mikael.holmen@ericsson.com>2017-10-03 06:03:49 +0000
committerMikael Holmen <mikael.holmen@ericsson.com>2017-10-03 06:03:49 +0000
commit6efe507e4291a6271b27eb052eb9dc5596725421 (patch)
treedab0ae2384b3a8ea91ebe3610047481f2e28995c /llvm/lib/IR
parent8ed1aa91bd83793668a0d0b5b306b7a61f632ce9 (diff)
downloadbcm5719-llvm-6efe507e4291a6271b27eb052eb9dc5596725421.tar.gz
bcm5719-llvm-6efe507e4291a6271b27eb052eb9dc5596725421.zip
[Lint] Avoid failed assertion by fetching the proper pointer type
Summary: When checking if a constant expression is a noop cast we fetched the IntPtrType by doing DL->getIntPtrType(V->getType())). However, there can be cases where V doesn't return a pointer, and then getIntPtrType() triggers an assertion. Now we pass DataLayout to isNoopCast so the method itself can determine what the IntPtrType is. Reviewers: arsenm Reviewed By: arsenm Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D37894 llvm-svn: 314763
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Instructions.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 2c49564e328..d6297cb6cae 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -2326,21 +2326,29 @@ bool CastInst::isNoopCast(Instruction::CastOps Opcode,
}
/// @brief Determine if a cast is a no-op.
+bool CastInst::isNoopCast(Instruction::CastOps Opcode,
+ Type *SrcTy,
+ Type *DestTy,
+ const DataLayout &DL) {
+ Type *PtrOpTy = nullptr;
+ if (Opcode == Instruction::PtrToInt)
+ PtrOpTy = SrcTy;
+ else if (Opcode == Instruction::IntToPtr)
+ PtrOpTy = DestTy;
+
+ Type *IntPtrTy = PtrOpTy ? DL.getIntPtrType(PtrOpTy) :
+ DL.getIntPtrType(SrcTy->getContext(), 0);
+
+ return isNoopCast(Opcode, SrcTy, DestTy, IntPtrTy);
+}
+
+/// @brief Determine if a cast is a no-op.
bool CastInst::isNoopCast(Type *IntPtrTy) const {
return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
}
bool CastInst::isNoopCast(const DataLayout &DL) const {
- Type *PtrOpTy = nullptr;
- if (getOpcode() == Instruction::PtrToInt)
- PtrOpTy = getOperand(0)->getType();
- else if (getOpcode() == Instruction::IntToPtr)
- PtrOpTy = getType();
-
- Type *IntPtrTy =
- PtrOpTy ? DL.getIntPtrType(PtrOpTy) : DL.getIntPtrType(getContext(), 0);
-
- return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
+ return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL);
}
/// This function determines if a pair of casts can be eliminated and what
OpenPOWER on IntegriCloud