Index: lib/CodeGen/AtomicExpandPass.cpp =================================================================== --- lib/CodeGen/AtomicExpandPass.cpp +++ lib/CodeGen/AtomicExpandPass.cpp @@ -1691,8 +1691,13 @@ } // 'ptr' argument. - Value *PtrVal = - Builder.CreateBitCast(PointerOperand, Type::getInt8PtrTy(Ctx)); + // note: This assumes all address spaces share a common libfunc + // implementation and that addresses are convertable. For systems without + // that property, we'd need to extend this mechanism to support As-specific + // families of atomic intrinsics. + auto *PtrTypeAS0 = PointerOperand->getType()->getPointerTo(0); + Value *PtrVal = Builder.CreateAddrSpaceCast(PointerOperand, PtrTypeAS0); + PtrVal = Builder.CreateBitCast(PtrVal, Type::getInt8PtrTy(Ctx)); Args.push_back(PtrVal); // 'expected' argument, if present.