-
Notifications
You must be signed in to change notification settings - Fork 15k
[profdata] Consume reader error if returned early #163671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-pgo Author: Ellis Hoag (ellishg) Changes#69513 added logic to emit an error when something goes wrong in llvm-project/llvm/tools/llvm-profdata/llvm-profdata.cpp Lines 864 to 867 in 1c7ae89
Fix this assert by calling We might be able to simplify this by directly adding the error to Full diff: https://github.com/llvm/llvm-project/pull/163671.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 15ddb05f953ee..585a39de9985f 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -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));
+ });
auto Warn = [&](Error E) {
if (ReaderWarning) {
consumeError(std::move(E));
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to add a small test?
@david-xl we only hit an assert if we early return in one of these places llvm-project/llvm/tools/llvm-profdata/llvm-profdata.cpp Lines 857 to 868 in 68fa9c4
The problem is it is difficult to reproduce these errors in |
#69513 added logic to emit an error when something goes wrong in
readRawCounts()by passing aWarn()lambda to capture errors. If we capture an error in this way and we also early return due to some other error (say fromreadBinaryIds()) then we will hit an assert due to an unconsumed error. This is because we don't consume the error at the end of this function.llvm-project/llvm/tools/llvm-profdata/llvm-profdata.cpp
Lines 864 to 867 in 1c7ae89
Fix this assert by calling
consumeError()viallvm::make_scope_exit()when the function returns for any reason.We might be able to simplify this by directly adding the error to
WC->ErrorsinWarn(), but that might change the order of the errors reported and I am less confident in that change.