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

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 11:17:36 PST 2024


Author: Michael Halkenhäuser
Date: 2024-02-23T13:17:32-06:00
New Revision: a64ff9630ccd305a63fca3ea9cc4bc4b49098495

URL: https://github.com/llvm/llvm-project/commit/a64ff9630ccd305a63fca3ea9cc4bc4b49098495
DIFF: https://github.com/llvm/llvm-project/commit/a64ff9630ccd305a63fca3ea9cc4bc4b49098495.diff

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

Add error messages showing the missing filenames.

Currently, we only get 'No such file or directory' without any(!)
further info. This patch will (only upon ENOENT error) iterate over all
requested files and print which ones are actually missing.

Added: 
    

Modified: 
    llvm/tools/llvm-link/llvm-link.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index e6c219a8cd7ece..9e7f2c3ebac437 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -393,8 +393,16 @@ 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 BufferOrErr = MemoryBuffer::getFileOrSTDIN(File);
+
+    // When we encounter a missing file, make sure we expose its name.
+    if (auto EC = BufferOrErr.getError())
+      if (EC == std::errc::no_such_file_or_directory)
+        ExitOnErr(createStringError(EC, "No such file or directory: '%s'",
+                                    File.c_str()));
+
     std::unique_ptr<MemoryBuffer> Buffer =
-        ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(File)));
+        ExitOnErr(errorOrToExpected(std::move(BufferOrErr)));
 
     std::unique_ptr<Module> M =
         identify_magic(Buffer->getBuffer()) == file_magic::archive


        


More information about the llvm-commits mailing list