Skip to content

Commit 1838f7f

Browse files
committed
[Clang][SYCL] Fix kernel name mangling for cross-ABI scenarios
In SYCL offload compilation, when the host uses Microsoft ABI and the device uses Itanium ABI (e.g., Windows host with CUDA device), kernel names were mangled differently between host and device code, causing runtime errors when the host tried to find kernels by name. This fix ensures consistent mangling by using the device's mangling context when compiling for cross-ABI scenarios. The logic is implemented in SYCL-specific code (SemaSYCL.cpp) to avoid adding SYCL-specific code to general Clang infrastructure. Removes XFAIL from Printf tests that were failing due to this issue. Fixes #14733.
1 parent 8fd5c48 commit 1838f7f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,9 +5369,24 @@ void SemaSYCL::copyDeviceKernelAttrs(CXXMethodDecl *CallOperator) {
53695369
}
53705370
}
53715371

5372+
static std::unique_ptr<MangleContext>
5373+
createSYCLCrossABIMangleContext(ASTContext &Ctx) {
5374+
// For SYCL offload compilation with cross-ABI scenarios (e.g., Microsoft
5375+
// host + Itanium device on Windows+CUDA), use device mangling context to
5376+
// ensure consistent kernel name mangling between host and device.
5377+
const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo();
5378+
if (AuxTarget && Ctx.getTargetInfo().getCXXABI().isMicrosoft() &&
5379+
AuxTarget->getCXXABI().isItaniumFamily()) {
5380+
return std::unique_ptr<MangleContext>(
5381+
Ctx.createDeviceMangleContext(*AuxTarget));
5382+
}
5383+
// Same ABI or no offload target: use standard mangling
5384+
return std::unique_ptr<MangleContext>(Ctx.createMangleContext());
5385+
}
5386+
53725387
void SemaSYCL::SetSYCLKernelNames() {
53735388
std::unique_ptr<MangleContext> MangleCtx(
5374-
getASTContext().createMangleContext());
5389+
createSYCLCrossABIMangleContext(getASTContext()));
53755390
// We assume the list of KernelDescs is the complete list of kernels needing
53765391
// to be rewritten.
53775392
for (const std::pair<const FunctionDecl *, FunctionDecl *> &Pair :
@@ -5890,7 +5905,7 @@ void SemaSYCL::finalizeFreeFunctionKernels() {
58905905
KernelObjVisitor Visitor{*this};
58915906
Visitor.VisitFunctionParameters(kernel, IntHeader);
58925907
std::unique_ptr<MangleContext> MangleCtx(
5893-
getASTContext().createMangleContext());
5908+
createSYCLCrossABIMangleContext(getASTContext()));
58945909
std::string Name, MangledName;
58955910
std::tie(Name, MangledName) =
58965911
constructFreeFunctionKernelName(kernel, *MangleCtx);

sycl/test-e2e/Printf/mixed-address-space.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for constant and generic address space can be used in the same module.
33
//
44
// UNSUPPORTED: target-amd
5-
// XFAIL: cuda && windows
6-
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14733
75
// FIXME: Drop the test once generic AS support is considered stable and the
86
// dedicated constant AS overload of printf is removed from the library.
97
//

sycl/test-e2e/Printf/percent-symbol.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// [1]: https://en.cppreference.com/w/cpp/io/c/fprintf
66
//
77
// UNSUPPORTED: target-amd
8-
// XFAIL: cuda && windows
9-
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14733
108
// RUN: %{build} -o %t.out
119
// RUN: %{run} %t.out | FileCheck %s
1210
// FIXME: Remove dedicated constant address space testing once generic AS

0 commit comments

Comments
 (0)