diff options
Diffstat (limited to 'flang/lib/Parser/message.cpp')
-rw-r--r-- | flang/lib/Parser/message.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/flang/lib/Parser/message.cpp b/flang/lib/Parser/message.cpp index 2c4f930..cfcd08b 100644 --- a/flang/lib/Parser/message.cpp +++ b/flang/lib/Parser/message.cpp @@ -477,15 +477,31 @@ void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked, } std::stable_sort(sorted.begin(), sorted.end(), [](const Message *x, const Message *y) { return x->SortBefore(*y); }); - const Message *lastMsg{nullptr}; + std::vector<const Message *> msgsWithLastLocation; std::size_t errorsEmitted{0}; for (const Message *msg : sorted) { - if (lastMsg && *msg == *lastMsg) { - // Don't emit two identical messages for the same location + bool shouldSkipMsg{false}; + // Don't emit two identical messages for the same location. + // At the same location, messages are sorted by the order they were + // added to the Messages buffer, which is a decent proxy for the + // causality of the messages. + if (!msgsWithLastLocation.empty()) { + if (msgsWithLastLocation[0]->AtSameLocation(*msg)) { + for (const Message *msgAtThisLocation : msgsWithLastLocation) { + if (*msg == *msgAtThisLocation) { + shouldSkipMsg = true; // continue loop over sorted messages + break; + } + } + } else { + msgsWithLastLocation.clear(); + } + } + if (shouldSkipMsg) { continue; } + msgsWithLastLocation.push_back(msg); msg->Emit(o, allCooked, echoSourceLines, hintFlagPtr); - lastMsg = msg; if (warningsAreErrors || msg->IsFatal()) { ++errorsEmitted; } |