[clang] 37282bc - [clang] Load `-fembed-offload-object=` through the VFS (#160906)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 26 10:35:27 PDT 2025
Author: Jan Svoboda
Date: 2025-09-26T10:35:22-07:00
New Revision: 37282bcee10dc20d0469d014e566f42377f0c22c
URL: https://github.com/llvm/llvm-project/commit/37282bcee10dc20d0469d014e566f42377f0c22c
DIFF: https://github.com/llvm/llvm-project/commit/37282bcee10dc20d0469d014e566f42377f0c22c.diff
LOG: [clang] Load `-fembed-offload-object=` through the VFS (#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.
Added:
Modified:
clang/include/clang/CodeGen/BackendUtil.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
Removed:
################################################################################
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 3f38741f24a60..57db20f70801b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1476,13 +1476,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