Skip to content

Commit 37282bc

Browse files
authored
[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.
1 parent ff98e51 commit 37282bc

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

clang/include/clang/CodeGen/BackendUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
4949
llvm::MemoryBufferRef Buf);
5050

5151
void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
52-
DiagnosticsEngine &Diags);
52+
llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags);
5353
} // namespace clang
5454

5555
#endif

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,13 +1476,13 @@ void clang::EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
14761476
}
14771477

14781478
void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
1479-
DiagnosticsEngine &Diags) {
1479+
llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags) {
14801480
if (CGOpts.OffloadObjects.empty())
14811481
return;
14821482

14831483
for (StringRef OffloadObject : CGOpts.OffloadObjects) {
14841484
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1485-
llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1485+
VFS.getBufferForFile(OffloadObject);
14861486
if (ObjectOrErr.getError()) {
14871487
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
14881488
"could not open '%0' for embedding");

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,8 @@ void CodeGenAction::ExecuteAction() {
11411141
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
11421142
}
11431143

1144-
EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
1144+
EmbedObject(TheModule.get(), CodeGenOpts, CI.getVirtualFileSystem(),
1145+
Diagnostics);
11451146
EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
11461147

11471148
LLVMContext &Ctx = TheModule->getContext();

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ void CodeGenModule::Release() {
15561556
EmitBackendOptionsMetadata(getCodeGenOpts());
15571557

15581558
// If there is device offloading code embed it in the host now.
1559-
EmbedObject(&getModule(), CodeGenOpts, getDiags());
1559+
EmbedObject(&getModule(), CodeGenOpts, *getFileSystem(), getDiags());
15601560

15611561
// Set visibility from DLL storage class
15621562
// We do this at the end of LLVM IR generation; after any operation

0 commit comments

Comments
 (0)