From: Stefan Monnier Date: Mon, 22 Jan 2024 20:06:24 +0000 (-0500) Subject: * src/regex-emacs.c (forall_firstchar_1): Improve corner case X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=912f8ce2c5372a10bbfefb7967f640cd7a736f4d;p=emacs.git * src/regex-emacs.c (forall_firstchar_1): Improve corner case Fixes a "FORALL_FIRSTCHAR: Broken assumption2!!" warning with: "^\\(# *\\)\\([^ ]+?\\) *: *\\(.*?\\(?:\n\\1[ \t]+.*?\\)*\\)[[:space:]]*$" (cherry picked from commit f821ac29e0cf69316d6c721bafe9b749b47a6db3) --- diff --git a/src/regex-emacs.c b/src/regex-emacs.c index dfc6c1fd691..0ec0c6eb63f 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -2923,8 +2923,18 @@ forall_firstchar_1 (re_char *p, re_char *pend, forward over a subsequent `jump`. Recognize this pattern since that subsequent `jump` is the one that jumps to the loop-entry. */ - newp2 = ((re_opcode_t) *newp2 == jump) - ? extract_address (newp2 + 1) : newp2; + if ((re_opcode_t) *newp2 == jump) + { + re_char *p3 = extract_address (newp2 + 1); + /* Only recognize this pattern if one of the two destinations + is going forward, otherwise we'll fall into the pessimistic + "Both destinations go backward" below. + This is important if the `jump` at newp2 is the end of an + outer loop while the `on_failure_jump` is the end of an + inner loop. */ + if (p3 > p_orig || newp1 > p_orig) + newp2 = p3; + } do_twoway_jump: /* We have to check that both destinations are safe.