Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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.

// OpenCL C++ will throw a more specific error.
Expand Down