Skip to content

Commit 416cdcf

Browse files
authored
clang/OpenCL: Fix special casing OpenCL in call emission (#138864)
This essentially reverts 1bf1a15. OpenCL's handling of address spaces has always been a mess, but it's better than it used to be so this hack appears to be unnecessary now. None of the code here should really depend on the language or language address space. The ABI address space to use is already explicit in the ABIArgInfo, so use that instead of guessing it has anything to do with LangAS::Default or getASTAllocaAddressSpace. The below usage of LangAS::Default and getASTAllocaAddressSpace are also suspect, but appears to be a more involved and separate fix.
1 parent b291cfc commit 416cdcf

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,7 +5369,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53695369
NeedCopy = true;
53705370
} else if (I->hasLValue()) {
53715371
auto LV = I->getKnownLValue();
5372-
auto AS = LV.getAddressSpace();
53735372

53745373
bool isByValOrRef =
53755374
ArgInfo.isIndirectAliased() || ArgInfo.getIndirectByVal();
@@ -5378,17 +5377,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53785377
(LV.getAlignment() < getContext().getTypeAlignInChars(I->Ty))) {
53795378
NeedCopy = true;
53805379
}
5381-
if (!getLangOpts().OpenCL) {
5382-
if ((isByValOrRef && (AS != LangAS::Default &&
5383-
AS != CGM.getASTAllocaAddressSpace()))) {
5384-
NeedCopy = true;
5385-
}
5386-
}
5387-
// For OpenCL even if RV is located in default or alloca address space
5388-
// we don't want to perform address space cast for it.
5389-
else if ((isByValOrRef && Addr.getType()->getAddressSpace() !=
5390-
IRFuncTy->getParamType(FirstIRArg)
5391-
->getPointerAddressSpace())) {
5380+
5381+
if (isByValOrRef && Addr.getType()->getAddressSpace() !=
5382+
ArgInfo.getIndirectAddrSpace()) {
53925383
NeedCopy = true;
53935384
}
53945385
}
@@ -5399,6 +5390,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53995390
auto *T = llvm::PointerType::get(
54005391
CGM.getLLVMContext(), CGM.getDataLayout().getAllocaAddrSpace());
54015392

5393+
// FIXME: This should not depend on the language address spaces, and
5394+
// only the contextual values. If the address space mismatches, see if
5395+
// we can look through a cast to a compatible address space value,
5396+
// otherwise emit a copy.
54025397
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
54035398
*this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
54045399
true);

0 commit comments

Comments
 (0)