Skip to content

Commit 098b878

Browse files
committed
Do not pass -D_DLL and -D_MT to device compilation.
Otherwise, the errors reported during device code compilation because device code cannot handle implib call.
1 parent 244290b commit 098b878

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6258,6 +6258,19 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62586258
if (Args.hasFlag(options::OPT_fsycl_esimd, options::OPT_fno_sycl_esimd,
62596259
false))
62606260
CmdArgs.push_back("-fsycl-explicit-simd");
6261+
6262+
if (!D.IsCLMode()) {
6263+
// SYCL library is guaranteed to work correctly only with dynamic
6264+
// MSVC runtime.
6265+
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
6266+
if (Args.hasFlag(options::OPT_fsycl_device_only, OptSpecifier(), false))
6267+
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
6268+
if (AuxT.isWindowsMSVCEnvironment()) {
6269+
CmdArgs.push_back("-D_MT");
6270+
CmdArgs.push_back("-D_DLL");
6271+
CmdArgs.push_back("--dependent-lib=msvcrt");
6272+
}
6273+
}
62616274
}
62626275
if (IsSYCLOffloadDevice && JA.getType() == types::TY_SYCL_Header) {
62636276
// Generating a SYCL Header
@@ -6275,20 +6288,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62756288
CmdArgs.push_back("-D__ENABLE_USM_ADDR_SPACE__");
62766289
}
62776290

6278-
if ((IsSYCL || UseSYCLTriple) && !D.IsCLMode()) {
6279-
// SYCL library is guaranteed to work correctly only with dynamic
6280-
// MSVC runtime.
6281-
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
6282-
if (Args.hasFlag(options::OPT_fsycl_device_only, OptSpecifier(), false))
6283-
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
6284-
if (AuxT.isWindowsMSVCEnvironment()) {
6285-
CmdArgs.push_back("-D_MT");
6286-
CmdArgs.push_back("-D_DLL");
6287-
if (IsSYCL && !IsSYCLOffloadDevice && SYCLDeviceInput)
6288-
CmdArgs.push_back("--dependent-lib=msvcrt");
6289-
}
6290-
}
6291-
62926291
if (IsHIP)
62936292
CmdArgs.push_back("-fcuda-allow-variadic-functions");
62946293

clang/test/Driver/sycl-MD-default.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
// CHK-DEFAULT: "-D_MT" "-D_DLL"
1414
// CHK-DEFAULT: "--dependent-lib=msvcrt{{d*}}"
1515

16-
// RUN: %clang -### -fsycl-device-only -c %s 2>&1 \
17-
// RUN: | FileCheck -check-prefix=CHK-DEFAULT-DEF %s
18-
// RUN: %clangxx -### -fsycl -c %s 2>&1 \
19-
// RUN: | FileCheck -check-prefix=CHK-DEFAULT-DEF %s
20-
// CHK-DEFAULT-DEF: "-D_MT" "-D_DLL"
21-
2216
// RUN: %clang_cl -### -MT -fsycl -c %s 2>&1 \
2317
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
2418
// RUN: %clang_cl -### -MTd -fsycl -c %s 2>&1 \

0 commit comments

Comments
 (0)