[clang] [clang][CodeGen][OpenCL] Fix `alloca` handling (PR #113930)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 4 20:32:09 PST 2025
================
@@ -103,11 +103,15 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
if (AllocaAddr)
*AllocaAddr = Alloca;
llvm::Value *V = Alloca.getPointer();
+ assert((!getLangOpts().OpenCL ||
+ CGM.getTarget().getTargetAddressSpace(getASTAllocaAddressSpace()) ==
+ CGM.getTarget().getTargetAddressSpace(LangAS::opencl_private)) &&
+ "For OpenCL allocas must allocate in the private address space!");
// Alloca always returns a pointer in alloca address space, which may
// be different from the type defined by the language. For example,
// in C++ the auto variables are in the default address space. Therefore
// cast alloca to the default address space when necessary.
- if (getASTAllocaAddressSpace() != LangAS::Default) {
+ if (!getLangOpts().OpenCL && getASTAllocaAddressSpace() != LangAS::Default) {
----------------
arsenm wrote:
This whole casting block should be deleted. A memory temporary should be the natural alloca type. Any user that wants the cast should handle this in the narrow use case.
This cannot be language dependent. The current behavior is ABI breaking for aggregates passed on the stack (see the device enqueue tests for an example, the byref temporary argument is broken to be a flat pointer). We are also just creating a lot of unnecessary casting spam for later passes to clean up in most contexts
https://github.com/llvm/llvm-project/pull/113930
More information about the cfe-commits
mailing list