Skip to content

Conversation

sarnex
Copy link
Member

@sarnex sarnex commented Oct 16, 2025

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.

@sarnex sarnex marked this pull request as ready for review October 16, 2025 21:23
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

@llvm/pr-subscribers-clang

Author: Nick Sarnie (sarnex)

Changes

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 --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.

@sarnex sarnex requested a review from tahonermann October 16, 2025 21:24
Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the conditions for each branch can be expressed more cleanly per my inline comment.

Comment on lines 5209 to 5212
if (S.getASTContext().getTargetInfo().getTriple().isNVPTX()) {
if (S.getASTContext().getTargetInfo().getTriple().isNVPTX() &&
!DeviceKernelAttr::isOpenCLSpelling(AL)) {
handleGlobalAttr(S, D, AL);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be made easier to read and maintain by reversing the order of the if/else branches.

if (DeviceKernelAttr::isOpenCLSpelling(AL)) {
  // Do OpenCL things...
} else if (S.getASTContext().getTargetInfo().getTriple().isNVPTX()) {
  // Do presumed CUDA/HIP kernel things, but only on NVPTX for some reason...
}

Copy link
Member Author

@sarnex sarnex Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. We go into the else branch for OpenCL spelling or non-NVPTX, so I don't think we can only check for the OpenCL spelling if we swap that condition to be the if. I made an attempt in my latest commit, please take a look when you have a chance.

Signed-off-by: Sarnie, Nick <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants