Skip to content

[SYCL] Hide inline definitions of stdio functions #18174

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

Merged
merged 2 commits into from
Apr 28, 2025
Merged
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
19 changes: 13 additions & 6 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,18 +1535,25 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (LangOpts.GPURelocatableDeviceCode)
Builder.defineMacro("SYCL_EXTERNAL", "__attribute__((sycl_device))");

const llvm::Triple &DeviceTriple = TI.getTriple();
const llvm::Triple::SubArchType DeviceSubArch = DeviceTriple.getSubArch();
if (DeviceTriple.isNVPTX() || DeviceTriple.isAMDGPU() ||
(DeviceTriple.isSPIR() &&
DeviceSubArch != llvm::Triple::SPIRSubArch_fpga) ||
// This gets called twice, once with TI set to the host TargetInfo, once
// with TI set to the device TargetInfo.
const llvm::Triple &Triple = TI.getTriple();
const llvm::Triple::SubArchType SubArch = Triple.getSubArch();
if (Triple.isNVPTX() || Triple.isAMDGPU() ||
(Triple.isSPIR() && SubArch != llvm::Triple::SPIRSubArch_fpga) ||
LangOpts.SYCLIsNativeCPU)
Builder.defineMacro("SYCL_USE_NATIVE_FP_ATOMICS");
// Enable generation of USM address spaces for FPGA.
if (DeviceSubArch == llvm::Triple::SPIRSubArch_fpga) {
if (SubArch == llvm::Triple::SPIRSubArch_fpga) {
Builder.defineMacro("__ENABLE_USM_ADDR_SPACE__");
Builder.defineMacro("SYCL_DISABLE_FALLBACK_ASSERT");
}

if (Triple.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");
}
Expand Down