Skip to content

Commit cec6c48

Browse files
authored
[clang][Sema][SYCL] Fix MSVC STL usage on AMDGPU (#135979) (#18097)
Cherry pick upstream commit llvm/llvm-project@257b727 Closes: #7738 Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent 4aaa8dd commit cec6c48

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5544,12 +5544,12 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC,
55445544
}
55455545

55465546
TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK;
5547+
auto *Aux = Context.getAuxTargetInfo();
55475548
// CUDA functions may have host and/or device attributes which indicate
55485549
// their targeted execution environment, therefore the calling convention
55495550
// of functions in CUDA should be checked against the target deduced based
55505551
// on their host/device attributes.
55515552
if (LangOpts.CUDA) {
5552-
auto *Aux = Context.getAuxTargetInfo();
55535553
assert(FD || CFT != CUDAFunctionTarget::InvalidTarget);
55545554
auto CudaTarget = FD ? CUDA().IdentifyTarget(FD) : CFT;
55555555
bool CheckHost = false, CheckDevice = false;
@@ -5574,6 +5574,15 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC,
55745574
A = HostTI->checkCallingConvention(CC);
55755575
if (A == TargetInfo::CCCR_OK && CheckDevice && DeviceTI)
55765576
A = DeviceTI->checkCallingConvention(CC);
5577+
} else if (LangOpts.SYCLIsDevice && TI.getTriple().isAMDGPU() &&
5578+
CC == CC_X86VectorCall) {
5579+
// Assuming SYCL Device AMDGPU CC_X86VectorCall functions are always to be
5580+
// emitted on the host. The MSVC STL has CC-based specializations so we
5581+
// cannot change the CC to be the default as that will cause a clash with
5582+
// another specialization.
5583+
A = TI.checkCallingConvention(CC);
5584+
if (Aux && A != TargetInfo::CCCR_OK)
5585+
A = Aux->checkCallingConvention(CC);
55775586
} else {
55785587
A = TI.checkCallingConvention(CC);
55795588
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
template <typename F> struct A{};
3+
4+
template <typename Ret, typename C, typename... Args> struct A<Ret ( C::*)(Args...) noexcept> { static constexpr int value = 0; };
5+
template <typename Ret, typename C, typename... Args> struct A<Ret (__vectorcall C::*)(Args...) noexcept> { static constexpr int value = 1; };
6+
7+
template <typename F> constexpr int A_v = A<F>::value;
8+
9+
struct B
10+
{
11+
void f() noexcept {}
12+
void __vectorcall g() noexcept {}
13+
};
14+
15+
int main()
16+
{
17+
return A_v<decltype(&B::f)> + A_v<decltype(&B::g)>;
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -isystem %S/Inputs/ -fsycl-is-device -triple amdgcn-amd-hsa -aux-triple x86_64-pc-windows-msvc -fsyntax-only -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
#include <vectorcall.hpp>

0 commit comments

Comments
 (0)