Skip to content

Commit 4b993a7

Browse files
authored
Revert "[SYCL][Driver] Link with sycl libs at link step of clang-cl -fsycl (#12793)" (#13326)
This reverts commit d6eecfa. This was commit was trying to cover the scenario: ``` clang-cl -I[path to sycl headers] sycl_program.cpp clang-cl -fsycl sycl_program.obj ``` and automatically link with sycl library at link step in such case. But problem is that at link step there is no way to know if -fsycl -MDd option was used at compile step or not. if -fsycl -MDd is used at compilation step then driver adds --dependent-lib=msvcrtd --dependent-lib=sycl7d options: `clang-cl -fsycl -MDd sycl_program.cpp # --dependent-lib=msvcrtd --dependent-lib=sycl7d` If then user links the program like this (without -MDd): `clang-cl -fsycl sycl_program.obj` then we will also link with sycl7 library (release version) which will cause a problem. Because at link step we don't know if we need to use debug of release version of the library. So, from my understanding this case: ``` clang-cl -I[path to sycl headers] sycl_program.cpp clang-cl -fsycl sycl_program.obj ``` can't be supported and needs to be considered as user's mistake.
1 parent 800da2b commit 4b993a7

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,18 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
135135
CmdArgs.push_back("-defaultlib:oldnames");
136136
}
137137

138-
if ((Args.hasArg(options::OPT_fsycl) &&
138+
if ((!C.getDriver().IsCLMode() && Args.hasArg(options::OPT_fsycl) &&
139139
!Args.hasArg(options::OPT_nolibsycl)) ||
140140
Args.hasArg(options::OPT_fsycl_host_compiler_EQ)) {
141141
CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
142142
TC.getDriver().Dir + "/../lib"));
143-
if (!Args.hasArg(options::OPT__SLASH_MDd) &&
144-
!isDependentLibAdded(Args, "msvcrtd")) {
143+
// When msvcrtd is added via --dependent-lib, we add the sycld
144+
// equivalent. Do not add the -defaultlib as it conflicts.
145+
if (!isDependentLibAdded(Args, "msvcrtd")) {
145146
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
146147
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION "-preview.lib");
147148
else
148149
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION ".lib");
149-
} else {
150-
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
151-
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION
152-
"-previewd.lib");
153-
else
154-
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION "d.lib");
155150
}
156151
CmdArgs.push_back("-defaultlib:sycl-devicelib-host.lib");
157152
}

clang/test/Driver/sycl-offload.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@
486486
// RUN: %clang -fsycl -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL %s
487487
// RUN: %clang_cl -fsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-CL %s
488488
// CHECK-LINK-SYCL-CL: "--dependent-lib=sycl{{[0-9]*}}"
489-
// CHECK-LINK-SYCL-CL: "-defaultlib:sycl{{[0-9]*}}.lib"
489+
// CHECK-LINK-SYCL-CL-NOT: "-defaultlib:sycl{{[0-9]*}}.lib"
490490
// CHECK-LINK-SYCL: "-defaultlib:sycl{{[0-9]*}}.lib"
491491

492492
/// Check no SYCL runtime is linked with -nolibsycl
@@ -837,16 +837,3 @@
837837
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK: --dependent-lib=sycl{{[0-9]*}}-previewd
838838
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}.lib
839839
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}-preview.lib
840-
841-
842-
/// Check that at link step of "clang-cl -fsycl" we pull in sycl.lib even if at the compilation step sycl libraries were not provided (this is possible if user compiles manually without -fsycl by provided paths to the headers).
843-
// RUN: %clang_cl -### -fsycl -nolibsycl -target x86_64-unknown-windows-msvc -c %s 2>&1 | FileCheck -check-prefix FSYCL-CL-COMPILE-NOLIBS-CHECK %s
844-
// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck -check-prefix FSYCL-CL-LINK-CHECK %s
845-
// FSYCL-CL-COMPILE-NOLIBS-CHECK-NOT: "--dependent-lib=sycl{{[0-9]*}}"
846-
// FSYCL-CL-LINK-CHECK: "-defaultlib:sycl{{[0-9]*}}.lib"
847-
848-
/// Check that at link step of "clang-cl -fsycl /MDd" we pull in sycld.lib even if at the compilation step sycl libraries were not provided (this is possible if user compiles manually without -fsycl by provided paths to the headers).
849-
// RUN: %clang_cl -### -fsycl -nolibsycl /MDd -target x86_64-unknown-windows-msvc -c %s 2>&1 | FileCheck -check-prefix FSYCL-CL-COMPILE-NOLIBS-MDd-CHECK %s
850-
// RUN: %clang_cl -### -fsycl /MDd %s 2>&1 | FileCheck -check-prefix FSYCL-CL-LINK--MDd-CHECK %s
851-
// FSYCL-CL-COMPILE-NOLIBS-MDd-CHECK-NOT: "--dependent-lib=sycl{{[0-9]*}}d"
852-
// FSYCL-CL-LINK--MDd-CHECK: "-defaultlib:sycl{{[0-9]*}}d.lib"

0 commit comments

Comments
 (0)