yaxunl updated this revision to Diff 185375.
yaxunl retitled this revision from "Let AMDGPU compile MSVC headers containing
vectorcall" to "[CUDA][HIP] Check calling convention based on function target".
yaxunl edited the summary of this revision.
yaxunl added a reviewer: tra.
yaxunl added a comment.
My last fix is not right. This patch fixes the issue by checking calling
convention based on whether it is host or device function.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57716/new/
https://reviews.llvm.org/D57716
Files:
lib/Sema/SemaDeclAttr.cpp
test/SemaCUDA/amdgpu-windows-vectorcall.cu
Index: test/SemaCUDA/amdgpu-windows-vectorcall.cu
===================================================================
--- /dev/null
+++ test/SemaCUDA/amdgpu-windows-vectorcall.cu
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple
x86_64-pc-windows-msvc -fms-compatibility -fcuda-is-device -fsyntax-only
-verify %s
+
+// expected-no-diagnostics
+template<class _Ty>
+ struct A
+ {
+ };
+
+template<class _Ret, class _Arg0, class _Types> struct A<_Ret (__cdecl
_Arg0::*)(_Types) > { };
+template<class _Ret, class _Arg0, class _Types> struct A<_Ret (__vectorcall
_Arg0::*)(_Types) > {};
+
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4614,8 +4614,31 @@
default: llvm_unreachable("unexpected attribute kind");
}
+ TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK;
const TargetInfo &TI = Context.getTargetInfo();
- TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
+ auto *Aux = Context.getAuxTargetInfo();
+ if (LangOpts.CUDA) {
+ auto CUDATarget = IdentifyCUDATarget(FD);
+ if (CUDATarget == CFT_HostDevice) {
+ A = TI.checkCallingConvention(CC);
+ if (A == TargetInfo::CCCR_OK && Aux)
+ A = Aux->checkCallingConvention(CC);
+ } else if (LangOpts.CUDAIsDevice) {
+ if (CUDATarget == CFT_Device || CUDATarget == CFT_Global) {
+ A = TI.checkCallingConvention(CC);
+ } else if (CUDATarget == CFT_Host && Aux) {
+ A = Aux->checkCallingConvention(CC);
+ }
+ } else {
+ if ((CUDATarget == CFT_Device || CUDATarget == CFT_Global) && Aux) {
+ A = Aux->checkCallingConvention(CC);
+ } else if (CUDATarget == CFT_Host) {
+ A = TI.checkCallingConvention(CC);
+ }
+ }
+ } else {
+ A = TI.checkCallingConvention(CC);
+ }
if (A != TargetInfo::CCCR_OK) {
if (A == TargetInfo::CCCR_Warning)
Diag(Attrs.getLoc(), diag::warn_cconv_ignored) << Attrs;
Index: test/SemaCUDA/amdgpu-windows-vectorcall.cu
===================================================================
--- /dev/null
+++ test/SemaCUDA/amdgpu-windows-vectorcall.cu
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-pc-windows-msvc -fms-compatibility -fcuda-is-device -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+template<class _Ty>
+ struct A
+ {
+ };
+
+template<class _Ret, class _Arg0, class _Types> struct A<_Ret (__cdecl _Arg0::*)(_Types) > { };
+template<class _Ret, class _Arg0, class _Types> struct A<_Ret (__vectorcall _Arg0::*)(_Types) > {};
+
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4614,8 +4614,31 @@
default: llvm_unreachable("unexpected attribute kind");
}
+ TargetInfo::CallingConvCheckResult A = TargetInfo::CCCR_OK;
const TargetInfo &TI = Context.getTargetInfo();
- TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
+ auto *Aux = Context.getAuxTargetInfo();
+ if (LangOpts.CUDA) {
+ auto CUDATarget = IdentifyCUDATarget(FD);
+ if (CUDATarget == CFT_HostDevice) {
+ A = TI.checkCallingConvention(CC);
+ if (A == TargetInfo::CCCR_OK && Aux)
+ A = Aux->checkCallingConvention(CC);
+ } else if (LangOpts.CUDAIsDevice) {
+ if (CUDATarget == CFT_Device || CUDATarget == CFT_Global) {
+ A = TI.checkCallingConvention(CC);
+ } else if (CUDATarget == CFT_Host && Aux) {
+ A = Aux->checkCallingConvention(CC);
+ }
+ } else {
+ if ((CUDATarget == CFT_Device || CUDATarget == CFT_Global) && Aux) {
+ A = Aux->checkCallingConvention(CC);
+ } else if (CUDATarget == CFT_Host) {
+ A = TI.checkCallingConvention(CC);
+ }
+ }
+ } else {
+ A = TI.checkCallingConvention(CC);
+ }
if (A != TargetInfo::CCCR_OK) {
if (A == TargetInfo::CCCR_Warning)
Diag(Attrs.getLoc(), diag::warn_cconv_ignored) << Attrs;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits