Skip to content

[HIP][SPIRV] Implicit new/delete should be cdecl on host #152023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,14 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
}

auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
// The MSVC STL has explicit cdecl on its (host-side) allocation function
// specializations for the allocation, so in order to prevent a CC clash
// we set cdecl on the host-side implicit decls, knowing these do not get
// emitted when compiling for device.
if (getLangOpts().CUDAIsDevice && ExtraAttr &&
isa<CUDAHostAttr>(ExtraAttr) &&
Context.getTargetInfo().getTriple().isSPIRV())
EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallingConv::CC_C);
QualType FnType = Context.getFunctionType(Return, Params, EPI);
FunctionDecl *Alloc = FunctionDecl::Create(
Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, FnType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv32 -verify
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64 -verify
// RUN: %clang_cc1 %s -fcuda-is-device -std=c++17 -triple spirv64-amd-amdhsa -verify

// expected-no-diagnostics

namespace std
{
enum class align_val_t : __SIZE_TYPE__ {};
struct nothrow_t { explicit nothrow_t() = default; };
extern nothrow_t const nothrow;
}

void* __attribute__((cdecl)) operator new(__SIZE_TYPE__);
void* __attribute__((cdecl)) operator new[](__SIZE_TYPE__);
void* __attribute__((cdecl)) operator new(__SIZE_TYPE__, ::std::align_val_t);
void* __attribute__((cdecl)) operator new[](__SIZE_TYPE__, ::std::align_val_t);

void __attribute__((cdecl)) operator delete(void*) noexcept;
void __attribute__((cdecl)) operator delete[](void*) noexcept;
void __attribute__((cdecl)) operator delete(void*, __SIZE_TYPE__) noexcept;
void __attribute__((cdecl)) operator delete[](void*, __SIZE_TYPE__) noexcept;
void __attribute__((cdecl)) operator delete(void*, ::std::align_val_t) noexcept;
void __attribute__((cdecl)) operator delete[](void*, ::std::align_val_t) noexcept;
void __attribute__((cdecl)) operator delete(void*, __SIZE_TYPE__, ::std::align_val_t) noexcept;
void __attribute__((cdecl)) operator delete[](void*, __SIZE_TYPE__, ::std::align_val_t) noexcept;