Skip to content

Commit fa49c3a

Browse files
committed
[CUDA][HIP] Check calling convention based on function target
MSVC header files using vectorcall to differentiate overloaded functions, which causes failure for AMDGPU target. This is because clang does not check function calling convention based on function target. This patch checks calling convention using the proper target info. Differential Revision: https://reviews.llvm.org/D57716 llvm-svn: 354929
1 parent 305b6b9 commit fa49c3a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Diff for: clang/lib/Sema/SemaDeclAttr.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -4615,8 +4615,36 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC,
46154615
default: llvm_unreachable("unexpected attribute kind");
46164616
}
46174617

4618+
TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK;
46184619
const TargetInfo &TI = Context.getTargetInfo();
4619-
TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
4620+
auto *Aux = Context.getAuxTargetInfo();
4621+
if (LangOpts.CUDA) {
4622+
auto CudaTarget = IdentifyCUDATarget(FD);
4623+
bool CheckHost = false, CheckDevice = false;
4624+
switch (CudaTarget) {
4625+
case CFT_HostDevice:
4626+
CheckHost = true;
4627+
CheckDevice = true;
4628+
break;
4629+
case CFT_Host:
4630+
CheckHost = true;
4631+
break;
4632+
case CFT_Device:
4633+
case CFT_Global:
4634+
CheckDevice = true;
4635+
break;
4636+
case CFT_InvalidTarget:
4637+
llvm_unreachable("unexpected cuda target");
4638+
}
4639+
auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI;
4640+
auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux;
4641+
if (CheckHost && HostTI)
4642+
A = HostTI->checkCallingConvention(CC);
4643+
if (A == TargetInfo::CCCR_OK && CheckDevice && DeviceTI)
4644+
A = DeviceTI->checkCallingConvention(CC);
4645+
} else {
4646+
A = TI.checkCallingConvention(CC);
4647+
}
46204648
if (A != TargetInfo::CCCR_OK) {
46214649
if (A == TargetInfo::CCCR_Warning)
46224650
Diag(Attrs.getLoc(), diag::warn_cconv_ignored) << Attrs;

Diff for: clang/test/SemaCUDA/amdgpu-windows-vectorcall.cu

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-pc-windows-msvc -fms-compatibility -fcuda-is-device -fsyntax-only -verify %s
2+
3+
__cdecl void hostf1();
4+
__vectorcall void (*hostf2)() = hostf1; // expected-error {{cannot initialize a variable of type 'void ((*))() __attribute__((vectorcall))' with an lvalue of type 'void () __attribute__((cdecl))'}}

0 commit comments

Comments
 (0)