diff --git a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp --- a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp +++ b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp @@ -145,16 +145,21 @@ // Deduplicate identical replacements in diagnostics. // FIXME: Find an efficient way to deduplicate on diagnostics level. - llvm::DenseMap> + llvm::DenseMap> DiagReplacements; - auto AddToGroup = [&](const tooling::Replacement &R, bool FromDiag) { + auto AddToGroup = [&](const tooling::Replacement &R, + const tooling::TranslationUnitDiagnostics *FromTU) { // Use the file manager to deduplicate paths. FileEntries are // automatically canonicalized. if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) { - if (FromDiag) { + if (FromTU) { auto &Replaces = DiagReplacements[*Entry]; - if (!Replaces.insert(R).second) + if (Replaces.find(R) == Replaces.end()) + Replaces.emplace(R, FromTU); + else if (Replaces.at(R) != FromTU) return; } GroupedReplacements[*Entry].push_back(R); @@ -166,14 +171,14 @@ for (const auto &TU : TUs) for (const tooling::Replacement &R : TU.Replacements) - AddToGroup(R, false); + AddToGroup(R, nullptr); for (const auto &TU : TUDs) for (const auto &D : TU.Diagnostics) if (const auto *ChoosenFix = tooling::selectFirstFix(D)) { for (const auto &Fix : *ChoosenFix) for (const tooling::Replacement &R : Fix.second) - AddToGroup(R, true); + AddToGroup(R, &TU); } // Sort replacements per file to keep consistent behavior when