Skip to content

Commit 4e2c211

Browse files
committed
Use target's default CC if available; extend test.
1 parent dbef117 commit 4e2c211

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,12 +3499,17 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
34993499
auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
35003500
// The MSVC STL has explicit cdecl on its (host-side) allocation function
35013501
// specializations for the allocation, so in order to prevent a CC clash
3502-
// we set cdecl on the host-side implicit decls, knowing these do not get
3503-
// emitted when compiling for device.
3502+
// we use the host's CC, if available, or CC_C as a fallback, for the
3503+
// host-side implicit decls, knowing these do not get emitted when compiling
3504+
// for device.
35043505
if (getLangOpts().CUDAIsDevice && ExtraAttr &&
35053506
isa<CUDAHostAttr>(ExtraAttr) &&
3506-
Context.getTargetInfo().getTriple().isSPIRV())
3507-
EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallingConv::CC_C);
3507+
Context.getTargetInfo().getTriple().isSPIRV()) {
3508+
if (auto *ATI = Context.getAuxTargetInfo())
3509+
EPI.ExtInfo = EPI.ExtInfo.withCallingConv(ATI->getDefaultCallingConv());
3510+
else
3511+
EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallingConv::CC_C);
3512+
}
35083513
QualType FnType = Context.getFunctionType(Return, Params, EPI);
35093514
FunctionDecl *Alloc = FunctionDecl::Create(
35103515
Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, FnType,

clang/test/SemaHIP/amdgcnspirv-implicit-alloc-function-calling-conv.hip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv32 -verify
22
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64 -verify
33
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64-amd-amdhsa -verify
4+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv32 -aux-triple x86_64-unknown-linux-gnu -verify
5+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu -verify
6+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -verify
7+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv32 -aux-triple x86_64-pc-windows-msvc -verify
8+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64 -aux-triple x86_64-pc-windows-msvc -verify
9+
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64-amd-amdhsa -aux-triple x86_64-pc-windows-msvc -verify
410

511
// expected-no-diagnostics
612

0 commit comments

Comments
 (0)