diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 3 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 4d7a857de5c..62ef25b6430 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -104,7 +104,8 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { // the first element. If so, return the appropriate GEP instruction. if (PointerType *PTy = dyn_cast<PointerType>(V->getType())) if (PointerType *DPTy = dyn_cast<PointerType>(DestTy)) - if (PTy->getAddressSpace() == DPTy->getAddressSpace()) { + if (PTy->getAddressSpace() == DPTy->getAddressSpace() + && DPTy->getElementType()->isSized()) { SmallVector<Value*, 8> IdxList; Value *Zero = Constant::getNullValue(Type::getInt32Ty(DPTy->getContext())); diff --git a/llvm/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll b/llvm/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll new file mode 100644 index 00000000000..abab9dc5702 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll @@ -0,0 +1,12 @@ +; RUN: opt < %s -instcombine -disable-output + +%opaque_struct = type opaque + +@G = external global [0 x %opaque_struct] + +declare void @foo(%opaque_struct*) + +define void @bar() { + call void @foo(%opaque_struct* bitcast ([0 x %opaque_struct]* @G to %opaque_struct*)) + ret void +} |

