]> granicus.if.org Git - re2c/commitdiff
Update tags after reading character in TDFAs without lookahead.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 23 Jan 2017 21:02:24 +0000 (21:02 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 23 Jan 2017 21:02:24 +0000 (21:02 +0000)
Fixed forgotten special case when tags and cursor increment
are hoisted out of conditional branches.

Found by slyfox's fuzzer. :)

re2c/src/codegen/go_emit.cc
re2c/test/tags/skip_before_tags.i--tags--no-lookahead.c [new file with mode: 0644]
re2c/test/tags/skip_before_tags.i--tags--no-lookahead.re [new file with mode: 0644]

index a8f91504ff12045d1536da0db38002f7c1fd8034..f9aa0246b29d89453388385a3cfa6aedd1cba650 100644 (file)
@@ -227,12 +227,14 @@ void Go::emit (OutputFile & o, uint32_t ind, const DFA &dfa)
                return;
        }
 
+       const bool lookahead = o.block().opts->lookahead;
+       o.wdelay_skip(ind, skip && !lookahead);
        code_lines_t code;
        gen_settags(code, dfa, tags, o.block().opts);
        for (size_t i = 0; i < code.size(); ++i) {
                o.wind(ind).wstring(code[i]);
        }
-       o.wdelay_skip(ind, skip);
+       o.wdelay_skip(ind, skip && lookahead);
 
        if (type == SWITCH_IF) {
                info.switchif->emit (o, ind, dfa);
diff --git a/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.c b/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.c
new file mode 100644 (file)
index 0000000..b1909f0
--- /dev/null
@@ -0,0 +1,30 @@
+/* Generated by re2c */
+
+{
+       YYCTYPE yych;
+       yyt1 = NULL;
+       yyt2 = YYCURSOR;
+       goto yy0;
+yy1:
+yy0:
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch (yych) {
+       case 'a':
+               ++YYCURSOR;
+               goto yy3;
+       default:        goto yy2;
+       }
+yy2:
+       a = yyt1;
+       {}
+yy3:
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR++;
+       yyt1 = yyt2;
+       yyt2 = YYCURSOR;
+       goto yy1;
+}
+
+re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string]
+re2c: warning: line 3: tag 'a' is non-deterministic and induces 2 parallel instances [-Wnondeterministic-tags]
diff --git a/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.re b/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.re
new file mode 100644 (file)
index 0000000..7e17c2d
--- /dev/null
@@ -0,0 +1,5 @@
+/*!re2c
+
+(@a "a" [^])* {}
+
+*/