Skip to content

[clang][Sema][SYCL] Fix MSVC STL usage on AMDGPU (#135979) #18097

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
11 changes: 10 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,15 @@ 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 && TI.getTriple().isAMDGPU() &&
CC == CC_X86VectorCall) {
// Assuming SYCL Device AMDGPU CC_X86VectorCall functions are always to be
// emitted on the host. The MSVC STL has CC-based specializations so we
// cannot change the CC to be the default as that will cause a clash with
// another specialization.
A = TI.checkCallingConvention(CC);
if (Aux && 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>