diff options
author | Steven Wu <stevenwu@apple.com> | 2022-09-09 08:56:53 -0700 |
---|---|---|
committer | Steven Wu <stevenwu@apple.com> | 2022-09-09 08:57:12 -0700 |
commit | 493766e068474a80a790ac41c667061229d2262d (patch) | |
tree | 369e38eb16aad06f1d125fcbee7b0b1beda4ba61 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | fa40fd40e055630c34890de84eb048796133fe03 (diff) | |
download | llvm-493766e068474a80a790ac41c667061229d2262d.zip llvm-493766e068474a80a790ac41c667061229d2262d.tar.gz llvm-493766e068474a80a790ac41c667061229d2262d.tar.bz2 |
Frontend: Respect -working-directory when checking if output files can be written
Call `FixupRelativePath` when opening output files to ensure that
`-working-directory` is used when checking up front for write failures,
not just when finalizing the files at the end. This also moves the
temporary file into the same directory as the output file.
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D95497
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index b187bdc..995c94b 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -781,12 +781,7 @@ void CompilerInstance::clearOutputFiles(bool EraseFiles) { continue; } - // If '-working-directory' was passed, the output filename should be - // relative to that. - SmallString<128> NewOutFile(OF.Filename); - FileMgr->FixupRelativePath(NewOutFile); - - llvm::Error E = OF.File->keep(NewOutFile); + llvm::Error E = OF.File->keep(OF.Filename); if (!E) continue; @@ -849,6 +844,15 @@ CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary, assert((!CreateMissingDirectories || UseTemporary) && "CreateMissingDirectories is only allowed when using temporary files"); + // If '-working-directory' was passed, the output filename should be + // relative to that. + Optional<SmallString<128>> AbsPath; + if (OutputPath != "-" && !llvm::sys::path::is_absolute(OutputPath)) { + AbsPath.emplace(OutputPath); + FileMgr->FixupRelativePath(*AbsPath); + OutputPath = *AbsPath; + } + std::unique_ptr<llvm::raw_fd_ostream> OS; Optional<StringRef> OSFile; |