llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Qinkun Bao (qinkunbao) <details> <summary>Changes</summary> As discussed in https://github.com/llvm/llvm-project/pull/139772, Matcher::Globs can keep the order when parsing the case list. --- Full diff: https://github.com/llvm/llvm-project/pull/140964.diff 3 Files Affected: - (modified) clang/lib/Basic/Diagnostic.cpp (+4-1) - (modified) llvm/include/llvm/Support/SpecialCaseList.h (+1-1) - (modified) llvm/lib/Support/SpecialCaseList.cpp (+10-11) ``````````diff diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index b48eed8650672..8168c36d9ccce 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -553,7 +553,10 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) { // Each section has a matcher with that section's name, attached to that // line. const auto &DiagSectionMatcher = Entry.SectionMatcher; - unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second; + unsigned DiagLine = 0; + for (const auto &[Pattern, Pair] : DiagSectionMatcher->Globs) + if (Pattern == DiagName) + DiagLine = Pair.second; LineAndSectionEntry.emplace_back(DiagLine, &Entry); } llvm::sort(LineAndSectionEntry); diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index fc6dc93651f38..14d83e64ec28c 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -125,7 +125,7 @@ class SpecialCaseList { // Returns zero if no match is found. LLVM_ABI unsigned match(StringRef Query) const; - StringMap<std::pair<GlobPattern, unsigned>> Globs; + std::vector<std::pair<std::string, std::pair<GlobPattern, unsigned>>> Globs; std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes; }; diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index dddf84cbb1ced..3e43f7bc93eff 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -53,17 +53,16 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber, return Error::success(); } - auto [It, DidEmplace] = Globs.try_emplace(Pattern); - if (DidEmplace) { - // We must be sure to use the string in the map rather than the provided - // reference which could be destroyed before match() is called - Pattern = It->getKey(); - auto &Pair = It->getValue(); - if (auto Err = GlobPattern::create(Pattern, /*MaxSubPatterns=*/1024) - .moveInto(Pair.first)) - return Err; - Pair.second = LineNumber; - } + Globs.emplace_back(); + auto &Glob = Globs.back(); + Glob.first = Pattern; + auto &Pair = Glob.second; + // We must be sure to use the string in the map rather than the provided + // reference which could be destroyed before match() is called + if (auto Err = GlobPattern::create(Glob.first, /*MaxSubPatterns=*/1024) + .moveInto(Pair.first)) + return Err; + Pair.second = LineNumber; return Error::success(); } `````````` </details> https://github.com/llvm/llvm-project/pull/140964 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits