[llvm] ca1a1f4 - [NFC][SpecialCaseList] Generalize "#!special-case-list-v" parsing (#162350)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 15:43:35 PDT 2025


Author: Vitaly Buka
Date: 2025-10-07T15:43:32-07:00
New Revision: ca1a1f47da0a073de838748b9b7067d7f10e8c92

URL: https://github.com/llvm/llvm-project/commit/ca1a1f47da0a073de838748b9b7067d7f10e8c92
DIFF: https://github.com/llvm/llvm-project/commit/ca1a1f47da0a073de838748b9b7067d7f10e8c92.diff

LOG: [NFC][SpecialCaseList] Generalize "#!special-case-list-v" parsing (#162350)

Added: 
    

Modified: 
    llvm/lib/Support/SpecialCaseList.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 4b038850b62ca..c0bfeb4020872 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -15,9 +15,12 @@
 
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include <limits>
 #include <stdio.h>
 #include <string>
 #include <system_error>
@@ -147,19 +150,25 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
 
 bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
                             std::string &Error) {
+  unsigned long long Version = std::numeric_limits<unsigned long long>::max();
+
+  StringRef Header = MB->getBuffer();
+  if (Header.consume_front("#!special-case-list-v"))
+    consumeUnsignedInteger(Header, 10, Version);
+
+  // In https://reviews.llvm.org/D154014 we added glob support and planned
+  // to remove regex support in patterns. We temporarily support the
+  // original behavior using regexes if "#!special-case-list-v1" is the
+  // first line of the file. For more details, see
+  // https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
+  bool UseGlobs = Version > 1;
+
   Section *CurrentSection;
   if (auto Err = addSection("*", FileIdx, 1).moveInto(CurrentSection)) {
     Error = toString(std::move(Err));
     return false;
   }
 
-  // In https://reviews.llvm.org/D154014 we added glob support and planned to
-  // remove regex support in patterns. We temporarily support the original
-  // behavior using regexes if "#!special-case-list-v1" is the first line of the
-  // file. For more details, see
-  // https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
-  bool UseGlobs = !MB->getBuffer().starts_with("#!special-case-list-v1\n");
-
   for (line_iterator LineIt(*MB, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
        !LineIt.is_at_eof(); LineIt++) {
     unsigned LineNo = LineIt.line_number();


        


More information about the llvm-commits mailing list