Skip to content

Commit 084f34c

Browse files
authored
[SYCL][Windows] Fix debug build in non cl mode (intel#6721)
This fixes building SYCL programs in Debug mode with `Windows-Clang.cmake`. The issue is that the code was using `OPT__SLASH_MDd` to select `sycld.lib` but under the `!C.getDriver.IsCLMode()` condition this flag will never be set, `OPT_g_Flag` should be used instead (`-g` rather than `/MDd`). Note that using the regular `clang` command line to manually build with `-g` still doesn't work as it will link against `msvcrt` rather than `msvcrtd` and will miss required defines for debug builds on Windows (`_DEBUG`). This is correctly done by the CMake module or simply when using `clang-cl`.
1 parent f0c17d4 commit 084f34c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
136136
Args.hasArg(options::OPT_fsycl_host_compiler_EQ)) {
137137
CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
138138
TC.getDriver().Dir + "/../lib"));
139-
if (Args.hasArg(options::OPT__SLASH_MDd))
139+
if (Args.hasArg(options::OPT_g_Flag))
140140
CmdArgs.push_back("-defaultlib:sycld.lib");
141141
else
142142
CmdArgs.push_back("-defaultlib:sycl.lib");

clang/test/Driver/sycl-offload.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,13 @@
661661
// CHECK-LINK-NOSTDLIB: "{{.*}}link{{(.exe)?}}"
662662
// CHECK-LINK-NOSTDLIB: "-defaultlib:sycl.lib"
663663

664-
/// Check sycld.lib is chosen with /MDd
665-
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
666-
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycld"
667-
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycld.lib"
664+
/// Check sycld.lib is chosen with /MDd or -g
665+
// RUN: %clang -fsycl -g -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
666+
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG-CL %s
667+
// CHECK-LINK-SYCL-DEBUG-CL: "--dependent-lib=sycld"
668+
// CHECK-LINK-SYCL-DEBUG-CL-NOT: "-defaultlib:sycld.lib"
669+
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycld.lib"
670+
// CHECK-LINK-SYCL-DEBUG-NOT: "--dependent-lib=sycld"
668671

669672
/// Check "-spirv-allow-unknown-intrinsics=llvm.genx." option is emitted for llvm-spirv tool
670673
// RUN: %clangxx %s -fsycl -### 2>&1 | FileCheck %s --check-prefix=CHK-ALLOW-INTRIN

0 commit comments

Comments
 (0)