Skip to content

Commit 70b6767

Browse files
authored
[Driver][SYCL] Add additional debug settings when using -g on Windows (#6909)
A recent addition of adding sycld.lib on Windows when using the Linux based driver was performed. There is additional tie-ins needed for general usage of debug libraries, which includes adding -D_DEBUG. Add the needed macro and also pull in the debug runtime library to match. This is done only for -fsycl based compilations as that is when we are pulling in these particular libraries.
1 parent 88fd329 commit 70b6767

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5995,6 +5995,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59955995
if (D.IsCLMode())
59965996
AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
59975997

5998+
// Add debug macro for debug library usage when using non-cl driver on
5999+
// Windows as we are using the debug sycld.lib with -g
6000+
if (!D.IsCLMode() && TC.getTriple().isWindowsMSVCEnvironment() &&
6001+
Args.hasArg(options::OPT_fsycl) && Args.hasArg(options::OPT_g_Flag))
6002+
CmdArgs.push_back("-D_DEBUG");
6003+
59986004
DwarfFissionKind DwarfFission = DwarfFissionKind::None;
59996005
renderDebugOptions(TC, D, RawTriple, Args, EmitCodeView,
60006006
types::isLLVMIR(InputType), CmdArgs, DebugInfoKind,

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
125125
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
126126
!C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
127127
if (Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl))
128-
CmdArgs.push_back("-defaultlib:msvcrt");
128+
if (Args.hasArg(options::OPT_g_Flag))
129+
CmdArgs.push_back("-defaultlib:msvcrtd");
130+
else
131+
CmdArgs.push_back("-defaultlib:msvcrt");
129132
else
130133
CmdArgs.push_back("-defaultlib:libcmt");
131134
CmdArgs.push_back("-defaultlib:oldnames");

clang/test/Driver/sycl-offload.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@
666666
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG-CL %s
667667
// CHECK-LINK-SYCL-DEBUG-CL: "--dependent-lib=sycl{{[0-9]*}}d"
668668
// CHECK-LINK-SYCL-DEBUG-CL-NOT: "-defaultlib:sycl{{[0-9]*}}d.lib"
669+
// CHECK-LINK-SYCL-DEBUG: "-D_DEBUG"
670+
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:msvcrtd"
669671
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycl{{[0-9]*}}d.lib"
670672
// CHECK-LINK-SYCL-DEBUG-NOT: "--dependent-lib=sycl{{[0-9]*}}d"
671673

0 commit comments

Comments
 (0)