https://github.com/rthomas-activision updated 
https://github.com/llvm/llvm-project/pull/189977

>From 1e698a3919320b8e5594b02383bc6ff65e06f497 Mon Sep 17 00:00:00 2001
From: Romain Thomas <[email protected]>
Date: Wed, 1 Apr 2026 10:19:43 +0200
Subject: [PATCH 1/2] [clang][Driver] Ensure intermediate bitcode files are
 written according to `/Fo`

With the following compilation process:

```
$ mkdir -p src/ tmp/
$ cat << 'EOF' > src/main.c
int main() { return 0; }
EOF
$ clang-cl /c /Fo:tmp/ /clang:-fembed-bitcode src/main.c
```

the object file `main.obj` is generated in the `tmp/` directory
but the intermediate `main.bc` is placed in the current working directory.

Ensure that intermediate `.bc` files are written to the same
directory specified by `/Fo`.
---
 clang/lib/Driver/Driver.cpp    | 6 ++++++
 clang/test/Driver/cl-outputs.c | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0686a89d42faf..7d11d61cb84da 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6629,6 +6629,12 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
             ->getValue();
     NamedOutput =
         MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object);
+  } else if ((JA.getType() == types::TY_LLVM_BC ||
+              JA.getType() == types::TY_LLVM_IR) &&
+             IsCLMode() && C.getArgs().hasArg(options::OPT__SLASH_Fo)) {
+    StringRef Val = C.getArgs().getLastArg(options::OPT__SLASH_Fo)->getValue();
+    NamedOutput =
+        MakeCLOutputFilename(C.getArgs(), Val, BaseName, JA.getType());
   } else {
     const char *Suffix =
         types::getTypeTempSuffix(JA.getType(), IsCLMode() || IsDXCMode());
diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index a8509e795c295..fc5fb49d2a514 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -310,3 +310,6 @@
 
 // RUN: %clang_cl -target x86_64-windows -fdebug-compilation-dir=. /Z7 
/Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
 // RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
+
+// RUN: %clang_cl /c /Fodir/ /clang:-fembed-bitcode -### -- %s 2>&1 | 
FileCheck -check-prefix=FoNAMEBC %s
+// FoNAMEBC:  "-o" "dir/cl-outputs.bc"

>From 6943feeb8f7af540ab5fd2082372635e1ebf8eb9 Mon Sep 17 00:00:00 2001
From: Romain Thomas <[email protected]>
Date: Thu, 2 Apr 2026 18:38:46 +0200
Subject: [PATCH 2/2] updates tests to include `-emit-llvm`

---
 clang/test/Driver/cl-outputs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index fc5fb49d2a514..e2ce16ee840e1 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -313,3 +313,9 @@
 
 // RUN: %clang_cl /c /Fodir/ /clang:-fembed-bitcode -### -- %s 2>&1 | 
FileCheck -check-prefix=FoNAMEBC %s
 // FoNAMEBC:  "-o" "dir/cl-outputs.bc"
+
+// RUN: %clang_cl /c /clang:-emit-llvm -### -- %s 2>&1 | FileCheck 
-check-prefix=FoNAMEBC2 %s
+// FoNAMEBC2:  "-o" "cl-outputs.bc"
+
+// RUN: %clang_cl /c /Fodir/ /clang:-emit-llvm -### -- %s 2>&1 | FileCheck 
-check-prefix=FoNAMEBC3 %s
+// FoNAMEBC3:  "-o" "dir/cl-outputs.bc"

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

Reply via email to