[flang-commits] [flang] e495eab - [clang] Include the error message in file reading error diagnostic
Hans Wennborg via flang-commits
flang-commits at lists.llvm.org
Fri Mar 17 05:48:14 PDT 2023
Author: Hans Wennborg
Date: 2023-03-17T13:47:02+01:00
New Revision: e495eabd326801c1e00508898dbcb04073a31014
URL: https://github.com/llvm/llvm-project/commit/e495eabd326801c1e00508898dbcb04073a31014
DIFF: https://github.com/llvm/llvm-project/commit/e495eabd326801c1e00508898dbcb04073a31014.diff
LOG: [clang] Include the error message in file reading error diagnostic
in order to provide as much information as possible to the user. The
diagnostic will now look like for example:
error: error reading '/tmp/foo.c': Permission denied
(This addresses a FIXME from 2019, 9ef6c49baf45)
Differential revision: https://reviews.llvm.org/D146280
Added:
Modified:
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/Frontend/CompilerInstance.cpp
clang/tools/driver/cc1as_main.cpp
flang/lib/Frontend/FrontendAction.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index c1a71d51d91b..9f788380f433 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -11,7 +11,7 @@ class BackendInfo : CatBackend, ShowInSystemHeader;
let Component = "Frontend" in {
def err_fe_error_opening : Error<"error opening '%0': %1">;
-def err_fe_error_reading : Error<"error reading '%0'">;
+def err_fe_error_reading : Error<"error reading '%0': %1">;
def err_fe_error_reading_stdin : Error<"error reading stdin: %0">;
def err_fe_error_backend : Error<"error in backend: %0">, DefaultFatal;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index ecf939424e56..691f779b5966 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -981,10 +981,9 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
? FileMgr.getSTDIN()
: FileMgr.getFileRef(InputFile, /*OpenFile=*/true);
if (!FileOrErr) {
- // FIXME: include the error in the diagnostic even when it's not stdin.
auto EC = llvm::errorToErrorCode(FileOrErr.takeError());
if (InputFile != "-")
- Diags.Report(diag::err_fe_error_reading) << InputFile;
+ Diags.Report(diag::err_fe_error_reading) << InputFile << EC.message();
else
Diags.Report(diag::err_fe_error_reading_stdin) << EC.message();
return false;
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 43d427b1af9b..ee54a0f7b0ea 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -384,8 +384,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true);
if (std::error_code EC = Buffer.getError()) {
- Error = EC.message();
- return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
+ return Diags.Report(diag::err_fe_error_reading)
+ << Opts.InputFile << EC.message();
}
SourceMgr SrcMgr;
diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index e6ede550092c..d9fe1232e29b 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -48,7 +48,7 @@ bool FrontendAction::beginSourceFile(CompilerInstance &ci,
unsigned diagID;
if (llvm::vfs::getRealFileSystem()->exists(input.getFile())) {
ci.getDiagnostics().Report(clang::diag::err_fe_error_reading)
- << input.getFile();
+ << input.getFile() << "not a regular file";
diagID = ci.getDiagnostics().getCustomDiagID(
clang::DiagnosticsEngine::Error, "%0 is not a regular file");
} else {
More information about the flang-commits
mailing list