Skip to content

[SYCL][Driver] Make /MD default with -fsycl for clang/clang++ drivers #2480

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 14 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6258,6 +6258,19 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasFlag(options::OPT_fsycl_esimd, options::OPT_fno_sycl_esimd,
false))
CmdArgs.push_back("-fsycl-explicit-simd");

if (!D.IsCLMode()) {
// SYCL library is guaranteed to work correctly only with dynamic
// MSVC runtime.
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
if (Args.hasFlag(options::OPT_fsycl_device_only, OptSpecifier(), false))
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
if (AuxT.isWindowsMSVCEnvironment()) {
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("-D_DLL");
CmdArgs.push_back("--dependent-lib=msvcrt");
}
}
}
if (IsSYCLOffloadDevice && JA.getType() == types::TY_SYCL_Header) {
// Generating a SYCL Header
Expand Down Expand Up @@ -6836,8 +6849,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
// Add SYCL dependent library
if (Args.hasArg(options::OPT_fsycl) &&
!Args.hasArg(options::OPT_nolibsycl)) {
if (RTOptionID == options::OPT__SLASH_MDd ||
RTOptionID == options::OPT__SLASH_MTd)
if (RTOptionID == options::OPT__SLASH_MDd)
CmdArgs.push_back("--dependent-lib=sycld");
else
CmdArgs.push_back("--dependent-lib=sycl");
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.MakeArgString(std::string("-out:") + Output.getFilename()));

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
!C.getDriver().IsCLMode())
CmdArgs.push_back("-defaultlib:libcmt");
!C.getDriver().IsCLMode()) {
if (Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl))
CmdArgs.push_back("-defaultlib:msvcrt");
else
CmdArgs.push_back("-defaultlib:libcmt");
}

if (!C.getDriver().IsCLMode() && !Args.hasArg(options::OPT_nostdlib) &&
Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-MD-default.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// REQUIRES: clang-driver

// RUN: %clang -### -fsycl -c -target x86_64-unknown-windows-msvc %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// RUN: %clangxx -### -fsycl -c -target x86_64-unknown-windows-msvc %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// RUN: %clang_cl -### -MD -fsycl -c %s 2>&1 \
Expand Down