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

>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 1/2] [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

>From 2f9aba56e1f4f492a0ef07fe7863f0263242cefd Mon Sep 17 00:00:00 2001
From: Haohai Wen <[email protected]>
Date: Tue, 26 May 2026 15:41:25 +0800
Subject: [PATCH 2/2] Address comments

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 9 +++++----
 clang/test/Driver/split-debug.c            | 4 +++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f59b50f4f45ca..a5ee29e108c32 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1884,11 +1884,12 @@ const char *tools::SplitDebugName(const JobAction &JA, 
const ArgList &Args,
   } else {
     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();
+    if (FinalOutput && Args.hasArg(options::OPT_c) && Output.isFilename()) {
+      // The driver has resolved /Fo<dir>/ into a concrete obj path in Output.
+      StringRef Obj = Output.getFilename();
+      T = Obj;
       llvm::sys::path::remove_filename(T);
-      llvm::sys::path::append(T,
-                              llvm::sys::path::stem(FinalOutput->getValue()));
+      llvm::sys::path::append(T, llvm::sys::path::stem(Obj));
       AddPostfix(T);
       return Args.MakeArgString(T);
     }
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index eaccc2784c50f..6c0df7f3b1d9d 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -57,11 +57,13 @@
 // 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.
+/// /Fo places the .dwo 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
+// RUN: %clang_cl -### -c --target=x86_64-unknown-windows-msvc -gdwarf 
-gsplit-dwarf /Foobj/ -- %s 2>&1 | FileCheck %s 
--check-prefix=SPLIT_SLASH_FO_DIR
 
 // SPLIT_SLASH_FO:      "-split-dwarf-file" "obj{{[/\\]}}out.dwo" 
"-split-dwarf-output" "obj{{[/\\]}}out.dwo"
+// SPLIT_SLASH_FO_DIR:  "-split-dwarf-file" "obj{{[/\\]}}split-debug.dwo" 
"-split-dwarf-output" "obj{{[/\\]}}split-debug.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

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

Reply via email to