[llvm] Revert "[llvm-cov] Fix error propagation in CoverageMapping::load() (… (PR #193266)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 09:47:11 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: gulfemsavrun

<details>
<summary>Changes</summary>

…#<!-- -->193197)"

This reverts commit b7cfcfe03deb679befe821d0c7a9c302f8645763.

Revert "[llvm] Errorize DebuginfodFetcher for inspection at call-sites (#<!-- -->191191)"

This reverts commit 337ad44a3e585f62bcf2e30b5766146cb8aacaca.

Reason for revert: Caused debuginfod tests failed in profile runtime:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8683917826498677969/overview

---
Full diff: https://github.com/llvm/llvm-project/pull/193266.diff


9 Files Affected:

- (modified) llvm/include/llvm/Debuginfod/BuildIDFetcher.h (+2-1) 
- (modified) llvm/include/llvm/Object/BuildID.h (+1-2) 
- (modified) llvm/lib/DebugInfo/Symbolize/Symbolize.cpp (+2-5) 
- (modified) llvm/lib/Debuginfod/BuildIDFetcher.cpp (+9-11) 
- (modified) llvm/lib/Object/BuildID.cpp (+2-6) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+11-13) 
- (modified) llvm/lib/ProfileData/InstrProfCorrelator.cpp (+3-8) 
- (modified) llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp (+4-6) 
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+3-9) 


``````````diff
diff --git a/llvm/include/llvm/Debuginfod/BuildIDFetcher.h b/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
index 66b6720a01226..8f9c2aa8722ad 100644
--- a/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
+++ b/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
@@ -16,6 +16,7 @@
 #define LLVM_DEBUGINFOD_DIFETCHER_H
 
 #include "llvm/Object/BuildID.h"
+#include <optional>
 
 namespace llvm {
 
@@ -27,7 +28,7 @@ class DebuginfodFetcher : public object::BuildIDFetcher {
 
   /// Fetches the given Build ID using debuginfod and returns a local path to
   /// the resulting file.
-  Expected<std::string> fetch(object::BuildIDRef BuildID) const override;
+  std::optional<std::string> fetch(object::BuildIDRef BuildID) const override;
 };
 
 } // namespace llvm
diff --git a/llvm/include/llvm/Object/BuildID.h b/llvm/include/llvm/Object/BuildID.h
index 73b1a0784da13..65ba00f75dd6f 100644
--- a/llvm/include/llvm/Object/BuildID.h
+++ b/llvm/include/llvm/Object/BuildID.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/Error.h"
 
 namespace llvm {
 namespace object {
@@ -45,7 +44,7 @@ class LLVM_ABI BuildIDFetcher {
   virtual ~BuildIDFetcher() = default;
 
   /// Returns the path to the debug file with the given build ID.
-  virtual Expected<std::string> fetch(BuildIDRef BuildID) const;
+  virtual std::optional<std::string> fetch(BuildIDRef BuildID) const;
 
 private:
   const std::vector<std::string> DebugFileDirectories;
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 4c910c65895bf..c2e15d6b3def4 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -490,17 +490,14 @@ bool LLVMSymbolizer::getOrFindDebugBinary(const ArrayRef<uint8_t> BuildID,
   }
   if (!BIDFetcher)
     return false;
-  Expected<std::string> Path = BIDFetcher->fetch(BuildID);
-  if (Path) {
+  if (std::optional<std::string> Path = BIDFetcher->fetch(BuildID)) {
     Result = *Path;
     auto InsertResult = BuildIDPaths.insert({BuildIDStr, Result});
     assert(InsertResult.second);
     (void)InsertResult;
     return true;
   }
-  // Failure to fetch debuginfod is rarely an error and most users will not care
-  // why this failed.
-  consumeError(Path.takeError());
+
   return false;
 }
 
diff --git a/llvm/lib/Debuginfod/BuildIDFetcher.cpp b/llvm/lib/Debuginfod/BuildIDFetcher.cpp
index 550ee4995008b..a7f13104abee1 100644
--- a/llvm/lib/Debuginfod/BuildIDFetcher.cpp
+++ b/llvm/lib/Debuginfod/BuildIDFetcher.cpp
@@ -15,19 +15,17 @@
 #include "llvm/Debuginfod/BuildIDFetcher.h"
 
 #include "llvm/Debuginfod/Debuginfod.h"
-#include "llvm/Support/Error.h"
 
 using namespace llvm;
 
-Expected<std::string>
+std::optional<std::string>
 DebuginfodFetcher::fetch(ArrayRef<uint8_t> BuildID) const {
-  Expected<std::string> Path = BuildIDFetcher::fetch(BuildID);
-  if (Path)
-    return Path;
-  // Most users will not care why this failed.
-  assert(errorToErrorCode(Path.takeError()) ==
-             std::errc::no_such_file_or_directory &&
-         "BuildIDFetcher::fetch() failed in an unexpected way");
-  consumeError(Path.takeError());
-  return getCachedOrDownloadDebuginfo(BuildID);
+  if (std::optional<std::string> Path = BuildIDFetcher::fetch(BuildID))
+    return std::move(*Path);
+
+  Expected<std::string> PathOrErr = getCachedOrDownloadDebuginfo(BuildID);
+  if (PathOrErr)
+    return *PathOrErr;
+  consumeError(PathOrErr.takeError());
+  return std::nullopt;
 }
diff --git a/llvm/lib/Object/BuildID.cpp b/llvm/lib/Object/BuildID.cpp
index 591c3a41e1df7..d1ee597a11327 100644
--- a/llvm/lib/Object/BuildID.cpp
+++ b/llvm/lib/Object/BuildID.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Object/BuildID.h"
 
 #include "llvm/Object/ELFObjectFile.h"
-#include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
@@ -80,7 +79,7 @@ BuildIDRef llvm::object::getBuildID(const ObjectFile *Obj) {
   return {};
 }
 
-Expected<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
+std::optional<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
   auto GetDebugPath = [&](StringRef Directory) {
     SmallString<128> Path{Directory};
     sys::path::append(Path, ".build-id",
@@ -109,8 +108,5 @@ Expected<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
         return std::string(Path);
     }
   }
-  return createStringError(
-      make_error_code(std::errc::no_such_file_or_directory),
-      "could not find debug file for build ID '" +
-          llvm::toHex(BuildID, /*LowerCase=*/true) + "'");
+  return std::nullopt;
 }
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index dff77d2f017d9..0d9a5a6758f06 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -1106,21 +1106,19 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
     }
 
     for (object::BuildIDRef BinaryID : BinaryIDsToFetch) {
-      if (Expected<std::string> Path = BIDFetcher->fetch(BinaryID)) {
+      std::optional<std::string> PathOpt = BIDFetcher->fetch(BinaryID);
+      if (PathOpt) {
+        std::string Path = std::move(*PathOpt);
         StringRef Arch = Arches.size() == 1 ? Arches.front() : StringRef();
-        if (Error E = loadFromFile(*Path, Arch, CompilationDir,
-                                   ProfileReaderRef, *Coverage, DataFound))
+        if (Error E = loadFromFile(Path, Arch, CompilationDir, ProfileReaderRef,
+                                   *Coverage, DataFound))
           return std::move(E);
-      } else {
-        // Conditionally propagate as new error.
-        consumeError(Path.takeError());
-        if (CheckBinaryIDs) {
-          return createFileError(
-              ProfileFilename.value(),
-              createStringError(errc::no_such_file_or_directory,
-                                "Missing binary ID: " +
-                                    llvm::toHex(BinaryID, /*LowerCase=*/true)));
-        }
+      } else if (CheckBinaryIDs) {
+        return createFileError(
+            ProfileFilename.value(),
+            createStringError(errc::no_such_file_or_directory,
+                              "Missing binary ID: " +
+                                  llvm::toHex(BinaryID, /*LowerCase=*/true)));
       }
     }
   }
diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
index faf98a3a7e28e..b38189de31606 100644
--- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -114,6 +114,7 @@ llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
 InstrProfCorrelator::get(StringRef Filename, ProfCorrelatorKind FileKind,
                          const object::BuildIDFetcher *BIDFetcher,
                          const ArrayRef<object::BuildID> BIs) {
+  std::optional<std::string> Path;
   if (BIDFetcher) {
     if (BIs.empty())
       return make_error<InstrProfError>(
@@ -126,18 +127,12 @@ InstrProfCorrelator::get(StringRef Filename, ProfCorrelatorKind FileKind,
           "unsupported profile binary correlation when there are multiple "
           "build IDs in a profile");
 
-    Expected<std::string> Path = BIDFetcher->fetch(BIs.front());
-    if (!Path) {
-      // Propagate as InstrProf specific error type.
-      assert(errorToErrorCode(Path.takeError()) ==
-                 std::errc::no_such_file_or_directory &&
-             "BuildIDFetcher::fetch() failed in an unexpected way");
-      consumeError(Path.takeError());
+    Path = BIDFetcher->fetch(BIs.front());
+    if (!Path)
       return make_error<InstrProfError>(
           instrprof_error::unable_to_correlate_profile,
           "Missing build ID: " + llvm::toHex(BIs.front(),
                                              /*LowerCase=*/true));
-    }
     Filename = *Path;
   }
 
diff --git a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
index 3a4a0b8ac255e..b6a5efd3e162c 100644
--- a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
+++ b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
@@ -152,12 +152,10 @@ int llvm_debuginfod_find_main(int argc, char **argv,
 
 // Find a debug file in local build ID directories and via debuginfod.
 std::string fetchDebugInfo(object::BuildIDRef BuildID) {
-  Expected<std::string> PathOrErr =
-      DebuginfodFetcher(DebugFileDirectory).fetch(BuildID);
-  if (PathOrErr)
-    return *PathOrErr;
-  errs() << "Build ID " << llvm::toHex(BuildID, /*Lowercase=*/true) << ": "
+  if (std::optional<std::string> Path =
+          DebuginfodFetcher(DebugFileDirectory).fetch(BuildID))
+    return *Path;
+  errs() << "Build ID " << llvm::toHex(BuildID, /*Lowercase=*/true)
          << " could not be found.\n";
-  consumeError(PathOrErr.takeError());
   exit(1);
 }
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 36bea85e83b68..a8a856e79dff8 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1743,13 +1743,9 @@ fetchBinaryByBuildID(const ObjectFile &Obj) {
   object::BuildIDRef BuildID = getBuildID(&Obj);
   if (BuildID.empty())
     return std::nullopt;
-  Expected<std::string> Path = BIDFetcher->fetch(BuildID);
-  if (!Path) {
-    // Failure to fetch debuginfod is rarely an error and most users will not
-    // care why this failed.
-    consumeError(Path.takeError());
+  std::optional<std::string> Path = BIDFetcher->fetch(BuildID);
+  if (!Path)
     return std::nullopt;
-  }
   Expected<OwningBinary<Binary>> DebugBinary = createBinary(*Path);
   if (!DebugBinary) {
     reportWarning(toString(DebugBinary.takeError()), *Path);
@@ -3845,10 +3841,8 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
   // Look up any provided build IDs, then append them to the input filenames.
   for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {
     object::BuildID BuildID = parseBuildIDArg(A);
-    Expected<std::string> Path = BIDFetcher->fetch(BuildID);
+    std::optional<std::string> Path = BIDFetcher->fetch(BuildID);
     if (!Path) {
-      // Most users will not care why this failed.
-      consumeError(Path.takeError());
       reportCmdLineError(A->getSpelling() + ": could not find build ID '" +
                          A->getValue() + "'");
     }

``````````

</details>


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


More information about the llvm-commits mailing list