[clang] [clang] Ensure we don't process OpenCL kernels as CUDA kernels (PR #163859)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 16 14:24:16 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nick Sarnie (sarnex)

<details>
<summary>Changes</summary>

We've decided the OpenCL spelling of the `DeviceKernel` attr needs separate handling, and add a case to that special handing for NVPTX target.

I wasn't able to come up with a test with any actual difference in behavior. 

It's possible this is NFC but I'm not sure so I'm not adding the tag.

---
Full diff: https://github.com/llvm/llvm-project/pull/163859.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+2-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e6f8748db7644..6978299734ece 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5206,7 +5206,8 @@ static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
 static void handleDeviceKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
   bool IsFunctionTemplate = FD && FD->getDescribedFunctionTemplate();
-  if (S.getASTContext().getTargetInfo().getTriple().isNVPTX()) {
+  if (S.getASTContext().getTargetInfo().getTriple().isNVPTX() &&
+      !DeviceKernelAttr::isOpenCLSpelling(AL)) {
     handleGlobalAttr(S, D, AL);
   } else {
     // OpenCL C++ will throw a more specific error.

``````````

</details>


https://github.com/llvm/llvm-project/pull/163859


More information about the cfe-commits mailing list