aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2023-09-27 13:29:50 -0400
committerStefan Monnier2023-09-27 13:29:50 -0400
commitbc52fdd1d153b36a9da74d7aa7f1e6150ff6b2eb (patch)
treea302e300d15378c840b9eab4f49861c375dd52f7
parent9a67540e51edca00b17de639af18989f9ecc9be9 (diff)
downloademacs-bc52fdd1d153b36a9da74d7aa7f1e6150ff6b2eb.tar.gz
emacs-bc52fdd1d153b36a9da74d7aa7f1e6150ff6b2eb.zip
* src/regex-emacs.c (analyze_first): Fix incorrect optimization
The optimization was incorrect in a particular corner case. In this fix I just disable it conservatively for more cases because it's not obvious how to fix it while preserving the "good" cases. We may find a better fix by using an approach like the one in `mutually_exhaustive_aux`, but for now this is good enough, especially since \{..\} repetitions are not used very frequently. * test/src/regex-resources/PTESTS: New test.
-rw-r--r--src/regex-emacs.c6
-rw-r--r--test/src/regex-resources/PTESTS1
2 files changed, 5 insertions, 2 deletions
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index 338323cf79e..ae82dd63917 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -3086,8 +3086,10 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, bool multibyte)
3086 /* We only care about one iteration of the loop, so we don't 3086 /* We only care about one iteration of the loop, so we don't
3087 need to consider the case where this behaves like an 3087 need to consider the case where this behaves like an
3088 on_failure_jump. */ 3088 on_failure_jump. */
3089 continue; 3089 /* FIXME: Sadly, the above is not true when the loop's body
3090 3090 can match the empty string :-( */
3091 /* continue; */
3092 return -1;
3091 3093
3092 case set_number_at: 3094 case set_number_at:
3093 p += 4; 3095 p += 4;
diff --git a/test/src/regex-resources/PTESTS b/test/src/regex-resources/PTESTS
index 68acc314d37..59dd4b3bc21 100644
--- a/test/src/regex-resources/PTESTS
+++ b/test/src/regex-resources/PTESTS
@@ -269,6 +269,7 @@
269#W the expected result for \([a-c]*\)\{2,\} is failure which isn't correct 269#W the expected result for \([a-c]*\)\{2,\} is failure which isn't correct
2701¦3¦\([a-c]*\)\{2,\}¦abcdefg¦ 2701¦3¦\([a-c]*\)\{2,\}¦abcdefg¦
2711¦3¦\([a-c]*\)\{1,\}¦abcdefg¦ 2711¦3¦\([a-c]*\)\{1,\}¦abcdefg¦
2720¦0¦\([a-c]*\)\{2,\}¦gabcdefg¦
272-1¦-1¦a\{64,\}¦aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa¦ 273-1¦-1¦a\{64,\}¦aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa¦
273# GA142 274# GA142
2741¦3¦a\{2,3\}¦aaaa¦ 2751¦3¦a\{2,3\}¦aaaa¦