@@ -477,15 +477,31 @@ void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
477477 }
478478 std::stable_sort (sorted.begin (), sorted.end (),
479479 [](const Message *x, const Message *y) { return x->SortBefore (*y); });
480- const Message *lastMsg{ nullptr } ;
480+ std::vector< const Message *> msgsWithLastLocation ;
481481 std::size_t errorsEmitted{0 };
482482 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) {
485501 continue ;
486502 }
503+ msgsWithLastLocation.push_back (msg);
487504 msg->Emit (o, allCooked, echoSourceLines, hintFlagPtr);
488- lastMsg = msg;
489505 if (warningsAreErrors || msg->IsFatal ()) {
490506 ++errorsEmitted;
491507 }
0 commit comments