https://github.com/vtjnash created 
https://github.com/llvm/llvm-project/pull/183195

In CGOpenMPRuntimeGPU::translateParameter, reference-type captured variables 
were translated to pointer parameters with two address-space annotations:

1. LangAS::opencl_global on the pointee (for map'd variables), which correctly 
produces ptr addrspace(1) in NVPTX IR.
2. getLangASFromTargetAS(NVPTX_local_addr=5) on the pointer itself, annotating 
the parameter as living in NVPTX local (stack) memory.

The second annotation is incorrect at the Clang type-system level: EmitParmDecl 
only supports parameters to be in LangAS::Default (or the special cases for 
OpenCL).

Temporarily add an assert in EmitParmDecl that catches parameters with 
non-default address spaces in non-OpenCL compilations, and fix the violation by 
dropping the NVPTX_local_addr addAddressSpace call.

Should fix the issue noticed in
https://github.com/llvm/llvm-project/pull/181256#discussion_r2821894122, 
allowing removing the special case there for OpenMP, though I haven't tested 
the combination yet. That PR will fix EmitParmDecl to actually support 
non-default address spaces from Sema, and will remove this assert again.

>From 5d09c7345f7a05e6fdbac4b26c0a0d6e3e913151 Mon Sep 17 00:00:00 2001
From: Jameson Nash <[email protected]>
Date: Tue, 24 Feb 2026 22:54:13 +0000
Subject: [PATCH] [OpenMP] Remove NVPTX local addrspace on parameters

In CGOpenMPRuntimeGPU::translateParameter, reference-type captured
variables were translated to pointer parameters with two address-space
annotations:

1. LangAS::opencl_global on the pointee (for map'd variables), which
   correctly produces ptr addrspace(1) in NVPTX IR.
2. getLangASFromTargetAS(NVPTX_local_addr=5) on the pointer itself,
   annotating the parameter as living in NVPTX local (stack) memory.

The second annotation is incorrect at the Clang type-system level:
EmitParmDecl only supports parameters to be in LangAS::Default (or
the special cases for OpenCL).

Temporarily add an assert in EmitParmDecl that catches parameters with
non-default address spaces in non-OpenCL compilations, and fix the
violation by dropping the NVPTX_local_addr addAddressSpace call.

Should fix the issue noticed in
https://github.com/llvm/llvm-project/pull/181256#discussion_r2821894122.
That PR will fix EmitParmDecl to actually support non-default address
spaces from Sema, and will remove this assert again.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---
 clang/lib/CodeGen/CGDecl.cpp             | 2 ++
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index a7bd2f0470cc0..8b5ffde1b73f3 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2685,6 +2685,8 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
     Arg.getAnyValue()->setName(D.getName());
 
   QualType Ty = D.getType();
+  assert((getLangOpts().OpenCL || Ty.getAddressSpace() == LangAS::Default) &&
+         "parameter has non-default address space in non-OpenCL mode");
 
   // Use better IR generation for certain implicit parameters.
   if (auto IPD = dyn_cast<ImplicitParamDecl>(&D)) {
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 0d7714ecbcc76..61f7470acb117 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1816,8 +1816,6 @@ CGOpenMPRuntimeGPU::translateParameter(const FieldDecl 
*FD,
   }
   ArgType = CGM.getContext().getPointerType(PointeeTy);
   QC.addRestrict();
-  enum { NVPTX_local_addr = 5 };
-  QC.addAddressSpace(getLangASFromTargetAS(NVPTX_local_addr));
   ArgType = QC.apply(CGM.getContext(), ArgType);
   if (isa<ImplicitParamDecl>(NativeParam))
     return ImplicitParamDecl::Create(

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to