https://github.com/HaohaiWen created 
https://github.com/llvm/llvm-project/pull/199613

SplitDebugName checked -o and /o but not /Fo, so clang-cl /Fo<path> /c
fell through to the cwd-relative fallback and every .dwo landed in cwd
under <source-stem>.dwo regardless of the .obj location.

>From d87e58e489cfec5c5dcb57eb9c1285b9ca939454 Mon Sep 17 00:00:00 2001
From: Haohai Wen <[email protected]>
Date: Tue, 26 May 2026 14:30:36 +0800
Subject: [PATCH] [Driver] Honor /Fo when deriving the split-dwarf .dwo path

SplitDebugName checked -o and /o but not /Fo, so clang-cl /Fo<path> /c
fell through to the cwd-relative fallback and every .dwo landed in cwd
under <source-stem>.dwo regardless of the .obj location.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++-
 clang/test/Driver/split-debug.c            | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6a0dcfca62c60..f59b50f4f45ca 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1882,7 +1882,8 @@ const char *tools::SplitDebugName(const JobAction &JA, 
const ArgList &Args,
   if (const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
     T = A->getValue();
   } else {
-    Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o);
+    Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o,
+                                       options::OPT__SLASH_Fo);
     if (FinalOutput && Args.hasArg(options::OPT_c)) {
       T = FinalOutput->getValue();
       llvm::sys::path::remove_filename(T);
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index 57f3989ed7b51..eaccc2784c50f 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -57,6 +57,12 @@
 // SINGLE_WITH_FILENAME: "-split-dwarf-file" "{{.*}}foo.o"
 // SINGLE_WITH_FILENAME-NOT: "-split-dwarf-output"
 
+/// /Fo drives the .dwo path so it lands next to the .obj.
+// RUN: %clang_cl -### -c --target=x86_64-unknown-windows-msvc -gdwarf 
-gsplit-dwarf /Foobj/out.obj -- %s 2>&1 | FileCheck %s 
--check-prefix=SPLIT_SLASH_FO
+// RUN: %clang_cl -### -c --target=x86_64-unknown-windows-msvc -gdwarf 
-gsplit-dwarf /Fo:obj/out.obj -- %s 2>&1 | FileCheck %s 
--check-prefix=SPLIT_SLASH_FO
+
+// SPLIT_SLASH_FO:      "-split-dwarf-file" "obj{{[/\\]}}out.dwo" 
"-split-dwarf-output" "obj{{[/\\]}}out.dwo"
+
 /// If linking is the final phase, the .dwo filename is derived from -o (if 
specified) or "a".
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu -gsplit-dwarf -g %s -o 
obj/out 2>&1 | FileCheck %s --check-prefix=SPLIT_LINK
 // RUN: %clang_cl -### --target=x86_64-unknown-windows-msvc -gsplit-dwarf -g 
-o obj/out -- %s 2>&1 | FileCheck %s --check-prefix=SPLIT_LINK

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to