[clang] [clang] Load `-fembed-offload-object=` through the VFS (PR #160906)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 26 08:25:07 PDT 2025
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/160906
This PR loads the path from `-fembed-offload-object=<path>` through the VFS rather than going straight to the real file system. This matches the behavior of other input files of the compiler. This technically changes behavior in that `-fembed-offload-object=-` no longer loads the file from stdin, but I don't think that was the intention of the original code anyways.
>From d1dd695916d1463a3067f07af9fb0fa39187b9d7 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 25 Sep 2025 15:32:27 -0700
Subject: [PATCH] [clang] Load `-fembed-offload-object=` through the VFS
---
clang/include/clang/CodeGen/BackendUtil.h | 2 +-
clang/lib/CodeGen/BackendUtil.cpp | 4 ++--
clang/lib/CodeGen/CodeGenAction.cpp | 3 ++-
clang/lib/CodeGen/CodeGenModule.cpp | 2 +-
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/CodeGen/BackendUtil.h b/clang/include/clang/CodeGen/BackendUtil.h
index 92e0d13bf25b6..8b0d975a876e6 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -49,7 +49,7 @@ void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
llvm::MemoryBufferRef Buf);
void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
- DiagnosticsEngine &Diags);
+ llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags);
} // namespace clang
#endif
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index d2ab7aa0b0369..e7de251086869 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1475,13 +1475,13 @@ void clang::EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
}
void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
- DiagnosticsEngine &Diags) {
+ llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags) {
if (CGOpts.OffloadObjects.empty())
return;
for (StringRef OffloadObject : CGOpts.OffloadObjects) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
- llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
+ VFS.getBufferForFile(OffloadObject);
if (ObjectOrErr.getError()) {
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
"could not open '%0' for embedding");
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 8e3234998df2a..9286f1f25c6cc 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1141,7 +1141,8 @@ void CodeGenAction::ExecuteAction() {
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
}
- EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
+ EmbedObject(TheModule.get(), CodeGenOpts, CI.getVirtualFileSystem(),
+ Diagnostics);
EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
LLVMContext &Ctx = TheModule->getContext();
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0eac7c351b164..875f06b53f53d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1556,7 +1556,7 @@ void CodeGenModule::Release() {
EmitBackendOptionsMetadata(getCodeGenOpts());
// If there is device offloading code embed it in the host now.
- EmbedObject(&getModule(), CodeGenOpts, getDiags());
+ EmbedObject(&getModule(), CodeGenOpts, *getFileSystem(), getDiags());
// Set visibility from DLL storage class
// We do this at the end of LLVM IR generation; after any operation
More information about the cfe-commits
mailing list