[llvm] r318555 - [llvm-profdata] Don't treat non-fatal merge errors as fatal
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 13:18:32 PST 2017
Author: vedantk
Date: Fri Nov 17 13:18:32 2017
New Revision: 318555
URL: http://llvm.org/viewvc/llvm-project?rev=318555&view=rev
Log:
[llvm-profdata] Don't treat non-fatal merge errors as fatal
This fixes an issue seen on the coverage bot:
http://lab.llvm.org:8080/green/view/Experimental/job/clang-stage2-coverage-R/1930
Profile merging shouldn't fail if a single counter mismatch is detected.
Modified:
llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test
llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
Modified: llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext?rev=318555&r1=318554&r2=318555&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext (original)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext Fri Nov 17 13:18:32 2017
@@ -2,3 +2,12 @@ foo
1024
1
0
+
+foo
+1024
+5
+0
+0
+0
+0
+0
Modified: llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test?rev=318555&r1=318554&r2=318555&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test Fri Nov 17 13:18:32 2017
@@ -1,6 +1,6 @@
# Test multithreaded error reporting.
-RUN: not llvm-profdata merge -j 4 -o %t.profdata \
+RUN: llvm-profdata merge -j 4 -o %t.profdata \
RUN: %S/Inputs/counter-mismatch-1.proftext \
RUN: %S/Inputs/counter-mismatch-2.proftext \
RUN: %S/Inputs/counter-mismatch-3.proftext \
Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=318555&r1=318554&r2=318555&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Fri Nov 17 13:18:32 2017
@@ -37,14 +37,19 @@ using namespace llvm;
enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
-static void exitWithError(Twine Message, std::string Whence = "",
- std::string Hint = "") {
- errs() << "error: ";
+static void warn(StringRef Prefix, Twine Message, std::string Whence = "",
+ std::string Hint = "") {
+ errs() << Prefix;
if (!Whence.empty())
errs() << Whence << ": ";
errs() << Message << "\n";
if (!Hint.empty())
errs() << Hint << "\n";
+}
+
+static void exitWithError(Twine Message, std::string Whence = "",
+ std::string Hint = "") {
+ warn("error: ", Message, Whence, Hint);
::exit(1);
}
@@ -129,6 +134,22 @@ struct WriterContext {
ErrLock(ErrLock), WriterErrorCodes(WriterErrorCodes) {}
};
+/// Determine whether an error is fatal for profile merging.
+static bool isFatalError(instrprof_error IPE) {
+ switch (IPE) {
+ default:
+ return true;
+ case instrprof_error::success:
+ case instrprof_error::eof:
+ case instrprof_error::unknown_function:
+ case instrprof_error::hash_mismatch:
+ case instrprof_error::count_mismatch:
+ case instrprof_error::counter_overflow:
+ case instrprof_error::value_site_count_mismatch:
+ return false;
+ }
+}
+
/// Load an input into a writer context.
static void loadInput(const WeightedFile &Input, WriterContext *WC) {
std::unique_lock<std::mutex> CtxGuard{WC->Lock};
@@ -177,8 +198,13 @@ static void loadInput(const WeightedFile
FuncName, firstTime);
});
}
- if (Reader->hasError())
- WC->Err = Reader->getError();
+ if (Reader->hasError()) {
+ if (Error E = Reader->getError()) {
+ instrprof_error IPE = InstrProfError::take(std::move(E));
+ if (isFatalError(IPE))
+ WC->Err = make_error<InstrProfError>(IPE);
+ }
+ }
}
/// Merge the \p Src writer context into \p Dst.
@@ -262,10 +288,20 @@ static void mergeInstrProfile(const Weig
}
// Handle deferred hard errors encountered during merging.
- for (std::unique_ptr<WriterContext> &WC : Contexts)
- if (WC->Err)
+ for (std::unique_ptr<WriterContext> &WC : Contexts) {
+ if (!WC->Err)
+ continue;
+ if (!WC->Err.isA<InstrProfError>())
exitWithError(std::move(WC->Err), WC->ErrWhence);
+ instrprof_error IPE = InstrProfError::take(std::move(WC->Err));
+ if (isFatalError(IPE))
+ exitWithError(make_error<InstrProfError>(IPE), WC->ErrWhence);
+ else
+ warn("warning: ", toString(make_error<InstrProfError>(IPE)),
+ WC->ErrWhence);
+ }
+
InstrProfWriter &Writer = Contexts[0]->Writer;
if (OutputFormat == PF_Text) {
if (Error E = Writer.writeText(Output))
More information about the llvm-commits
mailing list