Skip to content

Commit e53aa20

Browse files
authored
[Driver][SYCL] Add defaultlib directive for sycl lib (#2464)
When compiling for Windows, add the sycl dependent library to the object. If a person were to use /MTd to compile and not use /MTd to link, the default sycl lib would be passed to the linker instead of sycld.
1 parent 244e874 commit e53aa20

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -6819,6 +6819,16 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
68196819
// users want. The /Za flag to cl.exe turns this off, but it's not
68206820
// implemented in clang.
68216821
CmdArgs.push_back("--dependent-lib=oldnames");
6822+
6823+
// Add SYCL dependent library
6824+
if (Args.hasArg(options::OPT_fsycl) &&
6825+
!Args.hasArg(options::OPT_nolibsycl)) {
6826+
if (RTOptionID == options::OPT__SLASH_MDd ||
6827+
RTOptionID == options::OPT__SLASH_MTd)
6828+
CmdArgs.push_back("--dependent-lib=sycld");
6829+
else
6830+
CmdArgs.push_back("--dependent-lib=sycl");
6831+
}
68226832
}
68236833

68246834
if (Arg *ShowIncludes =

clang/lib/Driver/ToolChains/MSVC.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
373373
!C.getDriver().IsCLMode())
374374
CmdArgs.push_back("-defaultlib:libcmt");
375375

376-
if (!Args.hasArg(options::OPT_nostdlib) && Args.hasArg(options::OPT_fsycl) &&
377-
!Args.hasArg(options::OPT_nolibsycl)) {
376+
if (!C.getDriver().IsCLMode() && !Args.hasArg(options::OPT_nostdlib) &&
377+
Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
378378
if (Args.hasArg(options::OPT__SLASH_MDd) ||
379379
Args.hasArg(options::OPT__SLASH_MTd))
380380
CmdArgs.push_back("-defaultlib:sycld.lib");

clang/test/Driver/sycl-offload.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -577,21 +577,23 @@
577577

578578
/// Check for default linking of sycl.lib with -fsycl usage
579579
// RUN: %clang -fsycl -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL %s
580-
// RUN: %clang_cl -fsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL %s
581-
// CHECK-LINK-SYCL: "{{.*}}link{{(.exe)?}}"
580+
// RUN: %clang_cl -fsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-CL %s
581+
// CHECK-LINK-SYCL-CL: "--dependent-lib=sycl"
582+
// CHECK-LINK-SYCL-CL-NOT: "-defaultlib:sycl.lib"
582583
// CHECK-LINK-SYCL: "-defaultlib:sycl.lib"
583584

584585
/// Check no SYCL runtime is linked with -nolibsycl
585586
// RUN: %clang -fsycl -nolibsycl -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOLIBSYCL %s
586587
// RUN: %clang_cl -fsycl -nolibsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOLIBSYCL %s
588+
// CHECK-LINK-NOLIBSYCL-NOT: "--dependent-lib=sycl"
587589
// CHECK-LINK-NOLIBSYCL: "{{.*}}link{{(.exe)?}}"
588590
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl.lib"
589591

590592
/// Check sycld.lib is chosen with /MDd and /MTd
591593
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
592594
// RUN: %clang_cl -fsycl /MTd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
593-
// CHECK-LINK-SYCL-DEBUG: "{{.*}}link{{(.exe)?}}"
594-
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycld.lib"
595+
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycld"
596+
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycld.lib"
595597

596598
/// Check "-spirv-allow-unknown-intrinsics" option is emitted for llvm-spirv tool for esimd mode
597599
// RUN: %clangxx %s -fsycl -fsycl-explicit-simd -### 2>&1 | FileCheck %s --check-prefix=CHK-FSYCL-ESIMD

0 commit comments

Comments
 (0)