[libc-commits] [libc] [libc][regex] Add ERE {m, n} interval quantifiers (PR #236569)

Alex Strelnikov via libc-commits libc-commits at lists.llvm.org
Tue Nov 17 07:46:02 PST 2026


================
@@ -386,9 +385,26 @@ ErrorOr<ExprId> coalesce_repeat_pair(ExprId a, ExprId b, ExprPool &pool) {
       return left;
     return pool.make_concat(*left, a);
   }
+  if (ae.kind == ExprKind::Concat && ae.bin.left == b) {
+    ErrorOr<ExprId> right =
+        coalesce_repeat_pair(ae.bin.right, EMPTY_STR_ID, pool);
+    if (!right.has_value() || *right == INVALID_EXPR_ID)
+      return right;
+    return pool.make_concat(b, *right);
+  }
+  if (be.kind == ExprKind::Concat && be.bin.left == a) {
+    ErrorOr<ExprId> right =
+        coalesce_repeat_pair(EMPTY_STR_ID, be.bin.right, pool);
+    if (!right.has_value() || *right == INVALID_EXPR_ID)
+      return right;
+    return pool.make_concat(a, *right);
+  }
   if (ae.kind != ExprKind::Repeat && be.kind != ExprKind::Repeat)
     return INVALID_EXPR_ID;
-  ExprId body = (ae.kind == ExprKind::Repeat) ? ae.rep.body : be.rep.body;
+  ExprId body = (ae.kind == ExprKind::Repeat &&
+                 !(be.kind == ExprKind::Repeat && be.rep.body == a))
----------------
strel-12 wrote:

The added `&& !(be.kind == ExprKind::Repeat && be.rep.body == a)` seems unnecessary / spurious to the other changes in the latest commit?

This would make `get_interval(a, ae)` return `nullopt` when (`a` is a repeat AND `b` is a repeat of `a`). But without the added condition, `get_interval(b, be)` would already return `nullopt` and trigger the early `return` on line 429.



https://github.com/llvm/llvm-project/pull/236569


More information about the libc-commits mailing list