From 42117ad550c0955f81809a914687285ae2c807b9 Mon Sep 17 00:00:00 2001 From: Premanand M Rao Date: Mon, 28 Apr 2025 14:05:29 -0700 Subject: [PATCH] [SYCL] Addrspacecast needed even in non-alloca sret --- clang/lib/CodeGen/CGCall.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 89611247124fc..5d492ffd31e77 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5346,13 +5346,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, // chosen IndirectAS can happen e.g. when passing the this pointer through // a chain involving stores to / loads from the DefaultAS; we address this // here, symmetrically with the handling we have for normal pointer args. - if (CGM.getCodeGenOpts().UseAllocaASForSrets && - (SRetPtr.getAddressSpace() != RetAI.getIndirectAddrSpace())) { + unsigned RetAddrSpace = CGM.getCodeGenOpts().UseAllocaASForSrets + ? RetAI.getIndirectAddrSpace() + : CGM.getTypes().getTargetAddressSpace(RetTy); + if (SRetPtr.getAddressSpace() != RetAddrSpace) { llvm::Value *V = SRetPtr.getBasePointer(); LangAS SAS = getLangASFromTargetAS(SRetPtr.getAddressSpace()); - LangAS DAS = getLangASFromTargetAS(RetAI.getIndirectAddrSpace()); - llvm::Type *Ty = llvm::PointerType::get(getLLVMContext(), - RetAI.getIndirectAddrSpace()); + LangAS DAS = getLangASFromTargetAS(RetAddrSpace); + llvm::Type *Ty = llvm::PointerType::get(getLLVMContext(), RetAddrSpace); SRetPtr = SRetPtr.withPointer( getTargetHooks().performAddrSpaceCast(*this, V, SAS, DAS, Ty, true),