From 30392bf19168190fff7cdd2afd48a86714aa9bf4 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sun, 31 Aug 2014 19:19:57 +0000 Subject: [PATCH] Consider addrspaces in canLosslesslyBitCastTo() Make this conservatively correct and report false for different address spaces, which might require a nontrivial translation. Based on the few uses of this, I don't think this currently breaks anything. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216846 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Type.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 }