diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index ae7af8f1473..90fde4db192 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -89,9 +89,13 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const { // At this point we have only various mismatches of the first class types // remaining and ptr->ptr. Just select the lossless conversions. Everything - // else is not lossless. - if (this->isPointerTy()) - return Ty->isPointerTy(); + // else is not lossless. Conservatively assume we can't losslessly convert + // between pointers with different address spaces. + if (const PointerType *PTy = dyn_cast(this)) { + if (const PointerType *OtherPTy = dyn_cast(Ty)) + return PTy->getAddressSpace() == OtherPTy->getAddressSpace(); + return false; + } return false; // Other types have no identity values }