|
15 | 15 |
|
16 | 16 | #include "llvm/Support/SpecialCaseList.h"
|
17 | 17 | #include "llvm/ADT/STLExtras.h"
|
| 18 | +#include "llvm/ADT/StringExtras.h" |
| 19 | +#include "llvm/ADT/StringRef.h" |
18 | 20 | #include "llvm/Support/LineIterator.h"
|
19 | 21 | #include "llvm/Support/MemoryBuffer.h"
|
20 | 22 | #include "llvm/Support/VirtualFileSystem.h"
|
| 23 | +#include <limits> |
21 | 24 | #include <stdio.h>
|
22 | 25 | #include <string>
|
23 | 26 | #include <system_error>
|
@@ -147,19 +150,25 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
|
147 | 150 |
|
148 | 151 | bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
|
149 | 152 | 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 | + |
150 | 166 | Section *CurrentSection;
|
151 | 167 | if (auto Err = addSection("*", FileIdx, 1).moveInto(CurrentSection)) {
|
152 | 168 | Error = toString(std::move(Err));
|
153 | 169 | return false;
|
154 | 170 | }
|
155 | 171 |
|
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 |
| - |
163 | 172 | for (line_iterator LineIt(*MB, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
|
164 | 173 | !LineIt.is_at_eof(); LineIt++) {
|
165 | 174 | unsigned LineNo = LineIt.line_number();
|
|
0 commit comments