Skip to content

Commit d31184e

Browse files
authored
[Driver][SYCL] Make /MD the default for -fsycl (#2478)
When using -fsycl on Windows, make /MD the default behavior. Any usage of /MT will not be allowed and the driver will error upon usage.
1 parent 129ee44 commit d31184e

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def err_drv_invalid_Xsycl_frontend_with_args : Error<
132132
"invalid -Xsycl-target-frontend argument: '%0', options requiring arguments are unsupported">;
133133
def err_drv_bad_fpga_device_count : Error<
134134
"More than one FPGA specific device binary found in input objects">;
135+
def err_drv_unsupported_opt_dpcpp : Error<"option '%0' unsupported with DPC++">;
135136
def err_drv_argument_only_allowed_with : Error<
136137
"invalid argument '%0' only allowed with '%1'">;
137138
def err_drv_argument_not_allowed_with : Error<

clang/lib/Driver/ToolChains/Clang.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -6769,14 +6769,26 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
67696769
bool *EmitCodeView) const {
67706770
unsigned RTOptionID = options::OPT__SLASH_MT;
67716771
bool isNVPTX = getToolChain().getTriple().isNVPTX();
6772+
bool isSYCL =
6773+
Args.hasArg(options::OPT_fsycl) ||
6774+
getToolChain().getTriple().getEnvironment() == llvm::Triple::SYCLDevice;
6775+
// For SYCL Windows, /MD is the default.
6776+
if (isSYCL)
6777+
RTOptionID = options::OPT__SLASH_MD;
67726778

67736779
if (Args.hasArg(options::OPT__SLASH_LDd))
6774-
// The /LDd option implies /MTd. The dependent lib part can be overridden,
6775-
// but defining _DEBUG is sticky.
6776-
RTOptionID = options::OPT__SLASH_MTd;
6780+
// The /LDd option implies /MTd (/MDd for SYCL). The dependent lib part
6781+
// can be overridden but defining _DEBUG is sticky.
6782+
RTOptionID = isSYCL ? options::OPT__SLASH_MDd : options::OPT__SLASH_MTd;
67776783

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

67816793
StringRef FlagForCRT;
67826794
switch (RTOptionID) {

clang/lib/Driver/ToolChains/MSVC.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
375375

376376
if (!C.getDriver().IsCLMode() && !Args.hasArg(options::OPT_nostdlib) &&
377377
Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
378-
if (Args.hasArg(options::OPT__SLASH_MDd) ||
379-
Args.hasArg(options::OPT__SLASH_MTd))
378+
if (Args.hasArg(options::OPT__SLASH_MDd))
380379
CmdArgs.push_back("-defaultlib:sycld.lib");
381380
else
382381
CmdArgs.push_back("-defaultlib:sycl.lib");

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: clang-driver
2+
3+
// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
4+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
5+
// RUN: %clang_cl -### -MD -fsycl -c %s 2>&1 \
6+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
7+
// RUN: %clang_cl -### -MDd -fsycl -c %s 2>&1 \
8+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
9+
// CHK-DEFAULT: "-D_MT" "-D_DLL"
10+
// CHK-DEFAULT: "--dependent-lib=msvcrt{{d*}}"
11+
12+
// RUN: %clang_cl -### -MT -fsycl -c %s 2>&1 \
13+
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
14+
// RUN: %clang_cl -### -MTd -fsycl -c %s 2>&1 \
15+
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
16+
// CHK-ERROR: option 'MT{{d*}}' unsupported with DPC++

clang/test/Driver/sycl-offload.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,8 @@
589589
// CHECK-LINK-NOLIBSYCL: "{{.*}}link{{(.exe)?}}"
590590
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl.lib"
591591

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

sycl/test/regression/msvc_crt.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: %CPU_RUN_PLACEHOLDER %t1.exe
33
// RUN: %clang_cl -fsycl /MDd -o %t2.exe %s
44
// RUN: %CPU_RUN_PLACEHOLDER %t2.exe
5-
// RUN: %clang_cl -fsycl /MT -o %t3.exe %s
6-
// RUN: %CPU_RUN_PLACEHOLDER %t3.exe
75
// REQUIRES: system-windows
86
//==-------------- msvc_crt.cpp - SYCL MSVC CRT test -----------------------==//
97
//

0 commit comments

Comments
 (0)