diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2022-10-14 20:07:09 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2022-10-29 22:01:47 +0700 |
commit | 17eb198de934eced784e16ec15e020a574ba07e1 (patch) | |
tree | bf58a5eb0a64bf65e32f77ef3b7e4781edaeb9da /clang/lib/Driver/Driver.cpp | |
parent | d344146857aa105a24e06f2526d88e96c5865d00 (diff) | |
download | llvm-17eb198de934eced784e16ec15e020a574ba07e1.zip llvm-17eb198de934eced784e16ec15e020a574ba07e1.tar.gz llvm-17eb198de934eced784e16ec15e020a574ba07e1.tar.bz2 |
Handle errors in expansion of response files
Previously an error raised during an expansion of response files (including
configuration files) was ignored and only the fact of its presence was
reported to the user with generic error messages. This made it difficult to
analyze problems. For example, if a configuration file tried to read an
inexistent file, the error message said that 'configuration file cannot
be found', which is wrong and misleading.
This change enhances handling errors in the expansion so that users
could get more informative error messages.
Differential Revision: https://reviews.llvm.org/D136090
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 26729f1..80e6ec7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -940,10 +940,24 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt, bool Driver::readConfigFile(StringRef FileName, llvm::cl::ExpansionContext &ExpCtx) { + // Try opening the given file. + auto Status = getVFS().status(FileName); + if (!Status) { + Diag(diag::err_drv_cannot_open_config_file) + << FileName << Status.getError().message(); + return true; + } + if (Status->getType() != llvm::sys::fs::file_type::regular_file) { + Diag(diag::err_drv_cannot_open_config_file) + << FileName << "not a regular file"; + return true; + } + // Try reading the given file. SmallVector<const char *, 32> NewCfgArgs; - if (!ExpCtx.readConfigFile(FileName, NewCfgArgs)) { - Diag(diag::err_drv_cannot_read_config_file) << FileName; + if (llvm::Error Err = ExpCtx.readConfigFile(FileName, NewCfgArgs)) { + Diag(diag::err_drv_cannot_read_config_file) + << FileName << toString(std::move(Err)); return true; } @@ -1025,12 +1039,9 @@ bool Driver::loadConfigFiles() { if (llvm::sys::path::has_parent_path(CfgFileName)) { CfgFilePath.assign(CfgFileName); if (llvm::sys::path::is_relative(CfgFilePath)) { - if (getVFS().makeAbsolute(CfgFilePath)) - return true; - auto Status = getVFS().status(CfgFilePath); - if (!Status || - Status->getType() != llvm::sys::fs::file_type::regular_file) { - Diag(diag::err_drv_config_file_not_exist) << CfgFilePath; + if (getVFS().makeAbsolute(CfgFilePath)) { + Diag(diag::err_drv_cannot_open_config_file) + << CfgFilePath << "cannot get absolute path"; return true; } } |