[llvm] [llvm-link] Improve missing file error message (PR #82514)

Michael Halkenhäuser via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 12:49:38 PST 2024


================
@@ -393,8 +393,17 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
   // Similar to some flags, internalization doesn't apply to the first file.
   bool InternalizeLinkedSymbols = false;
   for (const auto &File : Files) {
+    auto ErrOrExpected = MemoryBuffer::getFileOrSTDIN(File);
+
+    // When we encounter a missing file, print all missing files to stderr.
+    if (auto EC = ErrOrExpected.getError())
+      if (EC == std::errc::no_such_file_or_directory)
+        for (auto &F : Files)
+          if (!llvm::sys::fs::exists(F))
+            errs() << "No such file or directory: '" << F << "'\n";
+
     std::unique_ptr<MemoryBuffer> Buffer =
-        ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(File)));
+        ExitOnErr(errorOrToExpected(std::move(ErrOrExpected)));
----------------
mhalk wrote:

> Unsure if it's necessary to error on all missing files at the same time.

I have no strong preference here, as long as I get the filename instead of nothing.
**Q: So you'd prefer only one error message mentioning the first missing file?**

> I would recommend just returning an error on this file if it's not found [...]

Like this? (If not: what do you mean by 'returning'?)
```
  // When we encounter a missing file, print all missing files to stderr.
  if (auto EC = ErrOrExpected.getError())
    if (EC == std::errc::no_such_file_or_directory)
      ExitOnErr(createStringError(EC, "No such file or directory: %s", File.c_str()));
```

https://github.com/llvm/llvm-project/pull/82514


More information about the llvm-commits mailing list