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

Michael Halkenhäuser via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 09:09:55 PST 2024


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

>From 73bbd41253ad1f9216c9fad30cf85b4f627237ee Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <MichaelGerald.Halkenhauser at amd.com>
Date: Wed, 21 Feb 2024 11:58:17 -0600
Subject: [PATCH] [llvm-link] Improve missing file error message

Add error message showing the missing filename.

Currently, we only get 'No such file or directory' without any(!) further info.
This patch will (upon ENOENT error) create an error which exposes the filename.
---
 llvm/tools/llvm-link/llvm-link.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

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