From 38936b143f6ead66d64431c96ae96dc05984d624 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 23 Jan 2017 22:28:16 +0000 Subject: [PATCH] Don't loose 'YYBACKUPTAG' command in case of equal mapped versions. Found by slyfox's fuzzer. :) --- re2c/src/ir/dfa/find_state.cc | 8 +++---- ...and.i--tags--no-lookahead--input(custom).c | 24 +++++++++++++++++++ ...nd.i--tags--no-lookahead--input(custom).re | 5 ++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).c create mode 100644 re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).re diff --git a/re2c/src/ir/dfa/find_state.cc b/re2c/src/ir/dfa/find_state.cc index 9b6e35ad..9817f092 100644 --- a/re2c/src/ir/dfa/find_state.cc +++ b/re2c/src/ir/dfa/find_state.cc @@ -367,14 +367,14 @@ static tcmd_t commands(const closure_t &closure, const Tagpool &tagpool, // mapping: see note [save(X), copy(Y,X) optimization] for (tagver_t x = -map->max; x < map->max; ++x) { const tagver_t y = map->x2y_backup[x]; - if (y == TAGVER_ZERO || y == x) continue; - const size_t t = map->x2t_backup[x]; - if (cur[t] == y) { + if (y == TAGVER_ZERO) { + continue; + } else if (cur[t] == y) { save = tcpool.make_save(save, abs(x), false); } else if (bot[t] == y) { save = tcpool.make_save(save, abs(x), true); - } else { + } else if (x != y) { copy = tcpool.make_copy(copy, abs(x), abs(y)); } } diff --git a/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).c b/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).c new file mode 100644 index 00000000..f978bdae --- /dev/null +++ b/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).c @@ -0,0 +1,24 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; + YYBACKUPTAG (yyt2); + if (YYLESSTHAN (1)) YYFILL(1); + yych = YYPEEK (); + YYSKIP (); + switch (yych) { + case 'a': + YYBACKUPTAG (yyt1); + goto yy2; + default: + YYBACKUPTAG (yyt1); + YYCOPYTAG (yyt2, NULL); + goto yy2; + } +yy2: + YYCOPYTAG (b, yyt1); + YYCOPYTAG (a, yyt2); + {} +} + +re2c: warning: line 3: tag 'a' is non-deterministic and induces 2 parallel instances [-Wnondeterministic-tags] diff --git a/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).re b/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).re new file mode 100644 index 00000000..ca0144e9 --- /dev/null +++ b/re2c/test/tags/lost_save_command.i--tags--no-lookahead--input(custom).re @@ -0,0 +1,5 @@ +/*!re2c + +(@a [a] | [^a]) @b {} + +*/ -- 2.40.0