Index: docs/CommandGuide/FileCheck.rst =================================================================== --- docs/CommandGuide/FileCheck.rst +++ docs/CommandGuide/FileCheck.rst @@ -480,3 +480,19 @@ letting us set the :program:`FileCheck` variable ``DLOC`` to the desired value ``0x00000233``, extracted from the line immediately preceding "``intd``". + +Repeat in regular expressions +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can use quantifiers with numbers in regular expressions such as {n}, {n,m}, {n,}. +For example: + +.. code-block:: llvm + + // CHECK : {{matched{5}}} + +It’s equal to + +.. code-block:: llvm + + // CHECK : {{matchedmatchedmatchedmatchedmatched}} Index: test/FileCheck/repeat-in-regex.txt =================================================================== --- /dev/null +++ test/FileCheck/repeat-in-regex.txt @@ -0,0 +1,13 @@ +// RUN: FileCheck -input-file %s %s + +text to be matchedmatchedmatchedmatchedmatched +// CHECK: {{(matched){5}}} + +r1, is register is register is register is register is register +// CHECK: [[REG:r[0-9]{1,2}]] +// CHECK-SAME: {{(is register ){1,}}} + +r2r13r1 +dag +// CHECK-DAG: {{dag{1}}} +// CHECK-DAG: {{[[REG]]{0,2}}} Index: utils/FileCheck/FileCheck.cpp =================================================================== --- utils/FileCheck/FileCheck.cpp +++ utils/FileCheck/FileCheck.cpp @@ -237,6 +237,14 @@ return true; } + // Find end of pattern in case of quantifiers of the form {n,m} + size_t NextChar = End + 2; + while (NextChar < PatternStr.size() && PatternStr[NextChar] == '}') { + NextChar++; + } + + End = NextChar - 2; + // Enclose {{}} patterns in parens just like [[]] even though we're not // capturing the result for any purpose. This is required in case the // expression contains an alternation like: CHECK: abc{{x|z}}def. We