Skip to content

[clang][Sema][SYCL] Fix SYCL AMDGPU compilation on Windows #17983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5544,12 +5544,12 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC,
}

TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK;
auto *Aux = Context.getAuxTargetInfo();
// CUDA functions may have host and/or device attributes which indicate
// their targeted execution environment, therefore the calling convention
// of functions in CUDA should be checked against the target deduced based
// on their host/device attributes.
if (LangOpts.CUDA) {
auto *Aux = Context.getAuxTargetInfo();
assert(FD || CFT != CUDAFunctionTarget::InvalidTarget);
auto CudaTarget = FD ? CUDA().IdentifyTarget(FD) : CFT;
bool CheckHost = false, CheckDevice = false;
Expand All @@ -5574,6 +5574,12 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC,
A = HostTI->checkCallingConvention(CC);
if (A == TargetInfo::CCCR_OK && CheckDevice && DeviceTI)
A = DeviceTI->checkCallingConvention(CC);
} else if (LangOpts.SYCLIsDevice && (Aux && Aux->getTriple().isOSWindows()) &&
TI.getTriple().isAMDGPU() &&
getSourceManager().isInSystemHeader(Attrs.getScopeLoc())) {
Copy link
Contributor

@Fznamznon Fznamznon Apr 16, 2025

Choose a reason for hiding this comment

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

I don't really know what will happen if the function with a wrong calling convention will reach codegen for the device. But in general, I would not limit this fix to windows and system headers because in SYCL the users are free to do everything in the host code. To prevent errors from device code emission, we usually use DiagIfDeviceCode functions, but I'm not really a fan of them due to their bugginess .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, let me remove that part and propose it upstream, thanks

A = TI.checkCallingConvention(CC);
if (A != TargetInfo::CCCR_OK)
A = Aux->checkCallingConvention(CC);
} else {
A = TI.checkCallingConvention(CC);
}
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaSYCL/Inputs/vectorcall.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

template <typename F> struct A{};

template <typename Ret, typename C, typename... Args> struct A<Ret ( C::*)(Args...) noexcept> { static constexpr int value = 0; };
template <typename Ret, typename C, typename... Args> struct A<Ret (__vectorcall C::*)(Args...) noexcept> { static constexpr int value = 1; };

template <typename F> constexpr int A_v = A<F>::value;

struct B
{
void f() noexcept {}
void __vectorcall g() noexcept {}
};

int main()
{
return A_v<decltype(&B::f)> + A_v<decltype(&B::g)>;
}
5 changes: 5 additions & 0 deletions clang/test/SemaSYCL/sycl-cconv-win.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple amdgcn-amd-hsa -aux-triple x86_64-pc-windows-msvc -fsyntax-only -verify %s

// expected-no-diagnostics

#include <vectorcall.hpp>