Skip to content

[Driver][SYCL] Make /MD the default for -fsycl #2478

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
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
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def err_drv_invalid_Xsycl_frontend_with_args : Error<
"invalid -Xsycl-target-frontend argument: '%0', options requiring arguments are unsupported">;
def err_drv_bad_fpga_device_count : Error<
"More than one FPGA specific device binary found in input objects">;
def err_drv_unsupported_opt_dpcpp : Error<"option '%0' unsupported with DPC++">;
def err_drv_argument_only_allowed_with : Error<
"invalid argument '%0' only allowed with '%1'">;
def err_drv_argument_not_allowed_with : Error<
Expand Down
20 changes: 16 additions & 4 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6769,14 +6769,26 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
bool *EmitCodeView) const {
unsigned RTOptionID = options::OPT__SLASH_MT;
bool isNVPTX = getToolChain().getTriple().isNVPTX();
bool isSYCL =
Args.hasArg(options::OPT_fsycl) ||
getToolChain().getTriple().getEnvironment() == llvm::Triple::SYCLDevice;
// For SYCL Windows, /MD is the default.
if (isSYCL)
RTOptionID = options::OPT__SLASH_MD;

if (Args.hasArg(options::OPT__SLASH_LDd))
// The /LDd option implies /MTd. The dependent lib part can be overridden,
// but defining _DEBUG is sticky.
RTOptionID = options::OPT__SLASH_MTd;
// The /LDd option implies /MTd (/MDd for SYCL). The dependent lib part
// can be overridden but defining _DEBUG is sticky.
RTOptionID = isSYCL ? options::OPT__SLASH_MDd : options::OPT__SLASH_MTd;

if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group)) {
RTOptionID = A->getOption().getID();
if (isSYCL && (RTOptionID == options::OPT__SLASH_MT ||
RTOptionID == options::OPT__SLASH_MTd))
// Use of /MT or /MTd is not supported for SYCL.
getToolChain().getDriver().Diag(diag::err_drv_unsupported_opt_dpcpp)
<< A->getOption().getName();
}

StringRef FlagForCRT;
switch (RTOptionID) {
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,

if (!C.getDriver().IsCLMode() && !Args.hasArg(options::OPT_nostdlib) &&
Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
if (Args.hasArg(options::OPT__SLASH_MDd) ||
Args.hasArg(options::OPT__SLASH_MTd))
if (Args.hasArg(options::OPT__SLASH_MDd))
CmdArgs.push_back("-defaultlib:sycld.lib");
else
CmdArgs.push_back("-defaultlib:sycl.lib");
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Driver/sycl-MD-default.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// REQUIRES: clang-driver

// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// RUN: %clang_cl -### -MD -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// RUN: %clang_cl -### -MDd -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
// CHK-DEFAULT: "-D_MT" "-D_DLL"
// CHK-DEFAULT: "--dependent-lib=msvcrt{{d*}}"

// RUN: %clang_cl -### -MT -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
// RUN: %clang_cl -### -MTd -fsycl -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
// CHK-ERROR: option 'MT{{d*}}' unsupported with DPC++
3 changes: 1 addition & 2 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,8 @@
// CHECK-LINK-NOLIBSYCL: "{{.*}}link{{(.exe)?}}"
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl.lib"

/// Check sycld.lib is chosen with /MDd and /MTd
/// Check sycld.lib is chosen with /MDd
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
// RUN: %clang_cl -fsycl /MTd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycld"
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycld.lib"

Expand Down
2 changes: 0 additions & 2 deletions sycl/test/regression/msvc_crt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// RUN: %CPU_RUN_PLACEHOLDER %t1.exe
// RUN: %clang_cl -fsycl /MDd -o %t2.exe %s
// RUN: %CPU_RUN_PLACEHOLDER %t2.exe
// RUN: %clang_cl -fsycl /MT -o %t3.exe %s
// RUN: %CPU_RUN_PLACEHOLDER %t3.exe
// REQUIRES: system-windows
//==-------------- msvc_crt.cpp - SYCL MSVC CRT test -----------------------==//
//
Expand Down