From 6a8df7d870c901c4e9aa7c8e8fe2b06f5e156e46 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Thu, 24 Apr 2025 11:21:10 +0100 Subject: [PATCH] [SYCL] Hide inline definitions of stdio functions MSVC's inline definitions of stdio functions such as printf() are only meant for host code; device code cannot call them. Device code can, however, call ext::oneapi::experimental::printf() which depending on the target is implemented as a call to the global printf(). The availability of a definition of the global host printf() makes it more difficult to handle in device code, so hide it. --- clang/lib/Frontend/InitPreprocessor.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 288effba7a3d9..7259522e88c52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1547,6 +1547,13 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__ENABLE_USM_ADDR_SPACE__"); Builder.defineMacro("SYCL_DISABLE_FALLBACK_ASSERT"); } + + // Despite the name, DeviceTriple is not necessarily the device triple. + if (DeviceTriple.isWindowsMSVCEnvironment()) { + // MSVC inline definitions of stdio functions should not be used for SYCL + // device code. + Builder.defineMacro("_NO_CRT_STDIO_INLINE"); + } } else if (LangOpts.SYCLIsHost && LangOpts.SYCLESIMDBuildHostCode) { Builder.defineMacro("__ESIMD_BUILD_HOST_CODE"); }