diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 7cb93f3c5b050..1e16e03e23341 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -7733,9 +7733,29 @@ static void processFunctionInstantiation(Sema &S, FD->setInstantiationIsPending(false); } +static std::unique_ptr createSYCLMangleContext(ASTContext &Ctx) { + // For SYCL offload compilation with cross-ABI scenarios (e.g., Microsoft host + // + Itanium device on Windows+CUDA), use device mangling context to ensure + // consistent kernel name mangling between host and device compilations. + const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo(); + if (AuxTarget && Ctx.getTargetInfo().getCXXABI().isMicrosoft() && + AuxTarget->getCXXABI().isItaniumFamily()) { + return std::unique_ptr( + Ctx.createDeviceMangleContext(*AuxTarget)); + } + // Same ABI or no offload target: use standard mangling + return std::unique_ptr(Ctx.createMangleContext()); +} + void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) { + // For SYCL compilation (both host and device), use device-aware mangle + // context to ensure consistent kernel name mangling across different + // backends (CUDA/HIP) and between host and device compilations. std::unique_ptr MangleCtx( - getASTContext().createMangleContext()); + (LangOpts.SYCLIsHost || LangOpts.SYCLIsDevice) + ? createSYCLMangleContext(getASTContext()) + : std::unique_ptr( + getASTContext().createMangleContext())); std::deque DelayedImplicitInstantiations; while (!PendingLocalImplicitInstantiations.empty() || (!LocalOnly && !PendingInstantiations.empty())) {