[llvm] [profdata] Consume reader error if returned early (PR #163671)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 09:58:39 PDT 2025


================
@@ -778,6 +779,12 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
   // we have more non-fatal errors from InstrProfReader in the future. How
   // should this interact with different -failure-mode?
   std::optional<std::pair<Error, std::string>> ReaderWarning;
+  auto ReaderWarningScope = llvm::make_scope_exit([&] {
+    // If we hit a different error we may still have an error in ReaderWarning.
+    // Consume it now to avoid an assert
+    if (ReaderWarning)
+      consumeError(std::move(ReaderWarning->first));
+  });
----------------
ellishg wrote:

Unfortunately this would change the behavior when we return early because we could add two errors for the same file. There is some logic to count if the number of errors equals the number of inputs. If we add two errors for one file we might break this logic.

https://github.com/llvm/llvm-project/blob/f802acf32d0755d774f9b91c346f17bdf7f9d37e/llvm/tools/llvm-profdata/llvm-profdata.cpp#L1077-L1088

Ideally we would save all errors and fix this logic, but that is beyond the scope of this PR.

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


More information about the llvm-commits mailing list