From: Ulya Trofimovich Date: Mon, 23 Jan 2017 21:02:24 +0000 (+0000) Subject: Update tags after reading character in TDFAs without lookahead. X-Git-Tag: 1.0~39^2~144 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65780565a0cc80dc7d103f0e7f5dcf084d2bfdbb;p=re2c Update tags after reading character in TDFAs without lookahead. Fixed forgotten special case when tags and cursor increment are hoisted out of conditional branches. Found by slyfox's fuzzer. :) --- diff --git a/re2c/src/codegen/go_emit.cc b/re2c/src/codegen/go_emit.cc index a8f91504..f9aa0246 100644 --- a/re2c/src/codegen/go_emit.cc +++ b/re2c/src/codegen/go_emit.cc @@ -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 index 00000000..b1909f08 --- /dev/null +++ b/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.c @@ -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 index 00000000..7e17c2d6 --- /dev/null +++ b/re2c/test/tags/skip_before_tags.i--tags--no-lookahead.re @@ -0,0 +1,5 @@ +/*!re2c + +(@a "a" [^])* {} + +*/