Skip to content

Commit ca1a1f4

Browse files
authored
[NFC][SpecialCaseList] Generalize "#!special-case-list-v" parsing (#162350)
1 parent 33e82e6 commit ca1a1f4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
#include "llvm/Support/SpecialCaseList.h"
1717
#include "llvm/ADT/STLExtras.h"
18+
#include "llvm/ADT/StringExtras.h"
19+
#include "llvm/ADT/StringRef.h"
1820
#include "llvm/Support/LineIterator.h"
1921
#include "llvm/Support/MemoryBuffer.h"
2022
#include "llvm/Support/VirtualFileSystem.h"
23+
#include <limits>
2124
#include <stdio.h>
2225
#include <string>
2326
#include <system_error>
@@ -147,19 +150,25 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
147150

148151
bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
149152
std::string &Error) {
153+
unsigned long long Version = std::numeric_limits<unsigned long long>::max();
154+
155+
StringRef Header = MB->getBuffer();
156+
if (Header.consume_front("#!special-case-list-v"))
157+
consumeUnsignedInteger(Header, 10, Version);
158+
159+
// In https://reviews.llvm.org/D154014 we added glob support and planned
160+
// to remove regex support in patterns. We temporarily support the
161+
// original behavior using regexes if "#!special-case-list-v1" is the
162+
// first line of the file. For more details, see
163+
// https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
164+
bool UseGlobs = Version > 1;
165+
150166
Section *CurrentSection;
151167
if (auto Err = addSection("*", FileIdx, 1).moveInto(CurrentSection)) {
152168
Error = toString(std::move(Err));
153169
return false;
154170
}
155171

156-
// In https://reviews.llvm.org/D154014 we added glob support and planned to
157-
// remove regex support in patterns. We temporarily support the original
158-
// behavior using regexes if "#!special-case-list-v1" is the first line of the
159-
// file. For more details, see
160-
// https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
161-
bool UseGlobs = !MB->getBuffer().starts_with("#!special-case-list-v1\n");
162-
163172
for (line_iterator LineIt(*MB, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
164173
!LineIt.is_at_eof(); LineIt++) {
165174
unsigned LineNo = LineIt.line_number();

0 commit comments

Comments
 (0)