[llvm] [profdata] Consume reader error if returned early (PR #163671)
Zequan Wu via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 09:49:16 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));
+ });
----------------
ZequanWu wrote:
Instead of consuming the error, I think the better way is to move the logic at the end of the function into llvm::make_scope_exit.
```suggestion
auto ReaderWarningScope = llvm::make_scope_exit([&] {
if (ReaderWarning) {
WC->Errors.emplace_back(std::move(ReaderWarning->first),
ReaderWarning->second);
}
});
```
https://github.com/llvm/llvm-project/pull/163671
More information about the llvm-commits
mailing list