Skip to content

Commit 45254b2

Browse files
committed
[clang] Load -fembed-offload-object= through the VFS (llvm#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 8dcf34d commit 45254b2

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
@@ -52,7 +52,7 @@ void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
5252
llvm::MemoryBufferRef Buf);
5353

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

5858
#endif

clang/lib/CodeGen/BackendUtil.cpp

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

15111511
void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
1512-
DiagnosticsEngine &Diags) {
1512+
llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags) {
15131513
if (CGOpts.OffloadObjects.empty())
15141514
return;
15151515

15161516
for (StringRef OffloadObject : CGOpts.OffloadObjects) {
15171517
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1518-
llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1518+
VFS.getBufferForFile(OffloadObject);
15191519
if (ObjectOrErr.getError()) {
15201520
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
15211521
"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
@@ -1160,7 +1160,8 @@ void CodeGenAction::ExecuteAction() {
11601160
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
11611161
}
11621162

1163-
EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
1163+
EmbedObject(TheModule.get(), CodeGenOpts, CI.getVirtualFileSystem(),
1164+
Diagnostics);
11641165
EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
11651166

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

clang/lib/CodeGen/CodeGenModule.cpp

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

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

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

0 commit comments

Comments
 (0)