@@ -477,15 +477,31 @@ void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
477
477
}
478
478
std::stable_sort (sorted.begin (), sorted.end (),
479
479
[](const Message *x, const Message *y) { return x->SortBefore (*y); });
480
- const Message *lastMsg{ nullptr } ;
480
+ std::vector< const Message *> msgsWithLastLocation ;
481
481
std::size_t errorsEmitted{0 };
482
482
for (const Message *msg : sorted) {
483
- if (lastMsg && *msg == *lastMsg) {
484
- // Don't emit two identical messages for the same location
483
+ bool shouldSkipMsg{false };
484
+ // Don't emit two identical messages for the same location.
485
+ // At the same location, messages are sorted by the order they were
486
+ // added to the Messages buffer, which is a decent proxy for the
487
+ // causality of the messages.
488
+ if (!msgsWithLastLocation.empty ()) {
489
+ if (msgsWithLastLocation[0 ]->AtSameLocation (*msg)) {
490
+ for (const Message *msgAtThisLocation : msgsWithLastLocation) {
491
+ if (*msg == *msgAtThisLocation) {
492
+ shouldSkipMsg = true ; // continue loop over sorted messages
493
+ break ;
494
+ }
495
+ }
496
+ } else {
497
+ msgsWithLastLocation.clear ();
498
+ }
499
+ }
500
+ if (shouldSkipMsg) {
485
501
continue ;
486
502
}
503
+ msgsWithLastLocation.push_back (msg);
487
504
msg->Emit (o, allCooked, echoSourceLines, hintFlagPtr);
488
- lastMsg = msg;
489
505
if (warningsAreErrors || msg->IsFatal ()) {
490
506
++errorsEmitted;
491
507
}
0 commit comments