@@ -63,6 +63,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
6363 .moveInto (Pair.first ))
6464 return Err;
6565 Pair.second = LineNumber;
66+ } else {
67+ // We should update the new line number if an entry with the same pattern
68+ // repeats.
69+ auto &Pair = It->getValue ();
70+ Pair.second = LineNumber;
6671 }
6772 return Error::success ();
6873}
@@ -132,18 +137,25 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB,
132137Expected<SpecialCaseList::Section *>
133138SpecialCaseList::addSection (StringRef SectionStr, unsigned LineNo,
134139 bool UseGlobs) {
135- Sections.emplace_back ();
136- auto &Section = Sections.back ();
137- Section.SectionStr = SectionStr;
138-
139- if (auto Err = Section.SectionMatcher ->insert (SectionStr, LineNo, UseGlobs)) {
140+ auto it =
141+ std::find_if (Sections.begin (), Sections.end (), [&](const Section &s) {
142+ return s.SectionStr == SectionStr && s.LineNo == LineNo;
143+ });
144+ if (it == Sections.end ()) {
145+ Sections.emplace_back ();
146+ auto &sec = Sections.back ();
147+ sec.SectionStr = SectionStr;
148+ sec.LineNo = LineNo;
149+ it = std::prev (Sections.end ());
150+ }
151+ if (auto Err = it->SectionMatcher ->insert (SectionStr, LineNo, UseGlobs)) {
140152 return createStringError (errc::invalid_argument,
141153 " malformed section at line " + Twine (LineNo) +
142154 " : '" + SectionStr +
143155 " ': " + toString (std::move (Err)));
144156 }
145157
146- return &Section ;
158+ return &(*it) ;
147159}
148160
149161bool SpecialCaseList::parse (const MemoryBuffer *MB, std::string &Error) {
0 commit comments