llvm.org GIT mirror llvm / ddb44a6
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318555 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 1 year, 10 months ago
3 changed file(s) with 53 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 # Test multithreaded error reporting.
11
2 RUN: not llvm-profdata merge -j 4 -o %t.profdata \
2 RUN: llvm-profdata merge -j 4 -o %t.profdata \
33 RUN: %S/Inputs/counter-mismatch-1.proftext \
44 RUN: %S/Inputs/counter-mismatch-2.proftext \
55 RUN: %S/Inputs/counter-mismatch-3.proftext \
3636
3737 enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
3838
39 static void exitWithError(Twine Message, std::string Whence = "",
40 std::string Hint = "") {
41 errs() << "error: ";
39 static void warn(StringRef Prefix, Twine Message, std::string Whence = "",
40 std::string Hint = "") {
41 errs() << Prefix;
4242 if (!Whence.empty())
4343 errs() << Whence << ": ";
4444 errs() << Message << "\n";
4545 if (!Hint.empty())
4646 errs() << Hint << "\n";
47 }
48
49 static void exitWithError(Twine Message, std::string Whence = "",
50 std::string Hint = "") {
51 warn("error: ", Message, Whence, Hint);
4752 ::exit(1);
4853 }
4954
127132 : Lock(), Writer(IsSparse), Err(Error::success()), ErrWhence(""),
128133 ErrLock(ErrLock), WriterErrorCodes(WriterErrorCodes) {}
129134 };
135
136 /// Determine whether an error is fatal for profile merging.
137 static bool isFatalError(instrprof_error IPE) {
138 switch (IPE) {
139 default:
140 return true;
141 case instrprof_error::success:
142 case instrprof_error::eof:
143 case instrprof_error::unknown_function:
144 case instrprof_error::hash_mismatch:
145 case instrprof_error::count_mismatch:
146 case instrprof_error::counter_overflow:
147 case instrprof_error::value_site_count_mismatch:
148 return false;
149 }
150 }
130151
131152 /// Load an input into a writer context.
132153 static void loadInput(const WeightedFile &Input, WriterContext *WC) {
176197 FuncName, firstTime);
177198 });
178199 }
179 if (Reader->hasError())
180 WC->Err = Reader->getError();
200 if (Reader->hasError()) {
201 if (Error E = Reader->getError()) {
202 instrprof_error IPE = InstrProfError::take(std::move(E));
203 if (isFatalError(IPE))
204 WC->Err = make_error(IPE);
205 }
206 }
181207 }
182208
183209 /// Merge the \p Src writer context into \p Dst.
261287 }
262288
263289 // Handle deferred hard errors encountered during merging.
264 for (std::unique_ptr &WC : Contexts)
265 if (WC->Err)
290 for (std::unique_ptr &WC : Contexts) {
291 if (!WC->Err)
292 continue;
293 if (!WC->Err.isA())
266294 exitWithError(std::move(WC->Err), WC->ErrWhence);
295
296 instrprof_error IPE = InstrProfError::take(std::move(WC->Err));
297 if (isFatalError(IPE))
298 exitWithError(make_error(IPE), WC->ErrWhence);
299 else
300 warn("warning: ", toString(make_error(IPE)),
301 WC->ErrWhence);
302 }
267303
268304 InstrProfWriter &Writer = Contexts[0]->Writer;
269305 if (OutputFormat == PF_Text) {