Skip to content

Commit ae0c8a2

Browse files
committed
[Driver][SYCL] Make /MD the default for -fsycl
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 628424a commit ae0c8a2

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 1 addition & 0 deletions
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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,14 +6769,25 @@ 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 = Args.hasArg(options::OPT_fsycl) ||
6773+
getToolChain().getTriple().getEnvironment() == llvm::Triple::SYCLDevice;
6774+
// For SYCL Windows, /MD is the default.
6775+
if (isSYCL)
6776+
RTOptionID = options::OPT__SLASH_MD;
67726777

67736778
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;
6779+
// The /LDd option implies /MTd (/MDd for SYCL). The dependent lib part
6780+
// can be overridden but defining _DEBUG is sticky.
6781+
RTOptionID = isSYCL ? options::OPT__SLASH_MDd : options::OPT__SLASH_MTd;
67776782

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

67816792
StringRef FlagForCRT;
67826793
switch (RTOptionID) {

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

Lines changed: 16 additions & 0 deletions
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++

0 commit comments

Comments
 (0)