diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2022-11-03 12:26:49 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2022-11-03 14:49:58 +0700 |
commit | fdab9f1203eea48a7b8e4c55c7ceafc54653797c (patch) | |
tree | 19c4723556d27ef899b840e22977823d0b675be6 /llvm/lib/Support/CommandLine.cpp | |
parent | a20112a74cb34fa967d10e07185167cbc2906c0d (diff) | |
download | llvm-fdab9f1203eea48a7b8e4c55c7ceafc54653797c.zip llvm-fdab9f1203eea48a7b8e4c55c7ceafc54653797c.tar.gz llvm-fdab9f1203eea48a7b8e4c55c7ceafc54653797c.tar.bz2 |
[Clang] Check for response file existence prior to check for recursion
As now errors in file operation are handled, check for file existence
must be done prior to check for recursion, otherwise reported errors are
misleading.
Differential Revision: https://reviews.llvm.org/D136090
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 136b813..fbaacbb 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1158,9 +1158,11 @@ Error ExpansionContext::expandResponseFile( assert(sys::path::is_absolute(FName)); llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr = FS->getBufferForFile(FName); - if (!MemBufOrErr) - return llvm::createStringError( - MemBufOrErr.getError(), Twine("cannot not open file '") + FName + "'"); + if (!MemBufOrErr) { + std::error_code EC = MemBufOrErr.getError(); + return llvm::createStringError(EC, Twine("cannot not open file '") + FName + + "': " + EC.message()); + } MemoryBuffer &MemBuf = *MemBufOrErr.get(); StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize()); @@ -1262,7 +1264,7 @@ Error ExpansionContext::expandResponseFiles( if (auto CWD = FS->getCurrentWorkingDirectory()) { CurrDir = *CWD; } else { - return make_error<StringError>( + return createStringError( CWD.getError(), Twine("cannot get absolute path for: ") + FName); } } else { @@ -1271,49 +1273,48 @@ Error ExpansionContext::expandResponseFiles( llvm::sys::path::append(CurrDir, FName); FName = CurrDir.c_str(); } + + ErrorOr<llvm::vfs::Status> Res = FS->status(FName); + if (!Res || !Res->exists()) { + std::error_code EC = Res.getError(); + if (!InConfigFile) { + // If the specified file does not exist, leave '@file' unexpanded, as + // libiberty does. + if (!EC || EC == llvm::errc::no_such_file_or_directory) { + ++I; + continue; + } + } + if (!EC) + EC = llvm::errc::no_such_file_or_directory; + return createStringError(EC, Twine("cannot not open file '") + FName + + "': " + EC.message()); + } + const llvm::vfs::Status &FileStatus = Res.get(); + auto IsEquivalent = - [FName, this](const ResponseFileRecord &RFile) -> ErrorOr<bool> { - ErrorOr<llvm::vfs::Status> LHS = FS->status(FName); - if (!LHS) - return LHS.getError(); + [FileStatus, this](const ResponseFileRecord &RFile) -> ErrorOr<bool> { ErrorOr<llvm::vfs::Status> RHS = FS->status(RFile.File); if (!RHS) return RHS.getError(); - return LHS->equivalent(*RHS); + return FileStatus.equivalent(*RHS); }; // Check for recursive response files. for (const auto &F : drop_begin(FileStack)) { if (ErrorOr<bool> R = IsEquivalent(F)) { if (R.get()) - return make_error<StringError>( - Twine("recursive expansion of: '") + F.File + "'", R.getError()); + return createStringError( + R.getError(), Twine("recursive expansion of: '") + F.File + "'"); } else { - return make_error<StringError>(Twine("cannot open file: ") + F.File, - R.getError()); + return createStringError(R.getError(), + Twine("cannot open file: ") + F.File); } } // Replace this response file argument with the tokenization of its // contents. Nested response files are expanded in subsequent iterations. SmallVector<const char *, 0> ExpandedArgv; - if (!InConfigFile) { - // If the specified file does not exist, leave '@file' unexpanded, as - // libiberty does. - ErrorOr<llvm::vfs::Status> Res = FS->status(FName); - if (!Res) { - std::error_code EC = Res.getError(); - if (EC == llvm::errc::no_such_file_or_directory) { - ++I; - continue; - } - } else { - if (!Res->exists()) { - ++I; - continue; - } - } - } if (Error Err = expandResponseFile(FName, ExpandedArgv)) return Err; |