Clang error: error reading 'A': B (err_fe_error_reading)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: error reading 'A': B
Type Error
Category None
Internal Id err_fe_error_reading
Internal Message error reading '%0': %1
Regular Expression (?:error|fatal error)\: error reading '(.*?)'\: (.*?)
First Commit 2009-03-12 4f495980c41b Add Diagnostic files for Frontend and move a couple errors over.

Description

The error is issued by the Clang compiler when it encounters difficulties accessing a file specified in the command line arguments or within the source code itself. This could be due to the file being non-existent, the path to the file being incorrect, or the compiler lacking the necessary permissions to read the file. The message is formulated by specifying the file that could not be read, followed by a description of the issue. This diagnostic is part of Clang's error reporting mechanism, aimed at notifying the user about problems related to file access during the compilation process. It is important to ensure that all files referenced are accessible and correctly specified to prevent this error.  
AI Generated

Example

In the following example, the source code attempts to use the Clang Static Analyzer with a custom checker plugin specified by the '-load' option and '-Xclang'. The plugin file is named 'mychecker.so'. However, the compilation process is unable to proceed successfully because the specified plugin file cannot be found, leading to the error message "error: error reading 'mychecker.so': No such file or directory". Additionally, the source code includes headers from the Clang Static Analyzer framework but fails to locate the 'clang/StaticAnalyzer/Core/BugReporter/BugType.h' file, resulting in a fatal error message. This example illustrates how missing files, whether they are plugins or include files, can halt the compilation process by triggering specific error diagnostics from the Clang compiler.  
AI Generated


Flags --analyze -xc++ -load -Xclang mychecker.so

[Try out in Compiler Explorer]

Source
// missing plugin file
#include <clang/StaticAnalyzer/Core/BugReporter/BugType.h>
#include <clang/StaticAnalyzer/Core/CheckerRegistry.h>

namespace {
class C : public clang::ento::Checker<true> {
public:
  void f(const clang::ento::CallEvent &E, 
                     clang::ento::CheckerContext &C) const override {
  }
};
}

static clang::ento::CheckerRegistry *S = 0;

void f() {
  if (!S) {
    S = new clang::ento::CheckerRegistry();
  }
  S->addChecker<C>();
}

// Plugin registration
extern "C" void clang_plugin_registerCheckers(clang::ento::CheckerRegistry &R) {
  f();
  R.addChecker<C>();
}
Compiler Output
clang++: warning: -load: 'linker' input unused [-Wunused-command-line-argument]
error: error reading 'mychecker.so': No such file or directory
<source>:2:10: fatal error: 'clang/StaticAnalyzer/Core/BugReporter/BugType.h' file not found


Clang Internals (17.0.6)

Git Commit Message

Add Diagnostic files for Frontend and move a couple errors over.
 - Notably, clang now exits with an error if it can't find a
   file. This flushed out a bug in the CGColorSpace.c test case. :)

llvm-svn: 66789

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Frontend/CompilerInstance.cpp (line 991)

// static
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr) {
  // ...
  if (!FileOrErr) {
    // ...
    if (InputFile != "-")
      Diags.Report(diag::err_fe_error_reading) << InputFile << EC.message();

clang/tools/driver/cc1as_main.cpp (line 395)

static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) {
  // ...
  if (std::error_code EC = Buffer.getError()) {
    return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile << EC.message();

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/Modules/working-dir-flag.m

  • error: error reading 'clang/test/Modules/working-dir-flag.m': No such file or directory