From: Yaxun Liu Date: Tue, 26 Feb 2019 22:24:49 +0000 (+0000) Subject: [CUDA][HIP] Check calling convention based on function target X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47a322be417d0197d2e581d5fc1e6da9d64d44fb;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354929 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index a0b4c53b1a..157c18a9e4 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4615,8 +4615,36 @@ bool Sema::CheckCallingConvAttr(const ParsedAttr &Attrs, CallingConv &CC, 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); + bool CheckHost = false, CheckDevice = false; + switch (CudaTarget) { + case CFT_HostDevice: + CheckHost = true; + CheckDevice = true; + break; + case CFT_Host: + CheckHost = true; + break; + case CFT_Device: + case CFT_Global: + CheckDevice = true; + break; + case CFT_InvalidTarget: + llvm_unreachable("unexpected cuda target"); + } + auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI; + auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux; + if (CheckHost && HostTI) + A = HostTI->checkCallingConvention(CC); + if (A == TargetInfo::CCCR_OK && CheckDevice && DeviceTI) + A = DeviceTI->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; diff --git a/test/SemaCUDA/amdgpu-windows-vectorcall.cu b/test/SemaCUDA/amdgpu-windows-vectorcall.cu new file mode 100644 index 0000000000..7636572f69 --- /dev/null +++ b/test/SemaCUDA/amdgpu-windows-vectorcall.cu @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-pc-windows-msvc -fms-compatibility -fcuda-is-device -fsyntax-only -verify %s + +__cdecl void hostf1(); +__vectorcall void (*hostf2)() = hostf1; // expected-error {{cannot initialize a variable of type 'void ((*))() __attribute__((vectorcall))' with an lvalue of type 'void () __attribute__((cdecl))'}}