From 2ede5a7546215ba6dd328c707629f789b90edf31 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 26 May 2015 21:34:56 +0100 Subject: [PATCH] Output user-defines start label in the appropriate place. Before this commit, given the following example: /*!re2c re2c:startlabel = "start"; [^]* {} */ re2c would generate the following code: { YYCTYPE yych; goto yy0; yy1: start: ++YYCURSOR; yy0: if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy1; {} } where "start:" falsely corresponds to "yy1:" rather to "yy0:". (The important property of this example is that DFA has arrows to initial state.) This commit fixes this behavior: { YYCTYPE yych; start: goto yy0; yy1: ++YYCURSOR; yy0: if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy1; {} } --- re2c/src/codegen/emit_action.cc | 5 ----- re2c/src/codegen/emit_dfa.cc | 8 ++++---- .../segfault_full_range_star_startlabel.ci.c | 20 +++++++++++++++++++ .../segfault_full_range_star_startlabel.ci.re | 4 ++++ .../segfault_full_range_star_startlabel.i.c | 15 ++++++++++++++ .../segfault_full_range_star_startlabel.i.re | 4 ++++ 6 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 re2c/test/segfault_full_range_star_startlabel.ci.c create mode 100644 re2c/test/segfault_full_range_star_startlabel.ci.re create mode 100644 re2c/test/segfault_full_range_star_startlabel.i.c create mode 100644 re2c/test/segfault_full_range_star_startlabel.i.re diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index d6eaa174..0efca68e 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -80,11 +80,6 @@ void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * co return; } - if (!cFlag && !startLabelName.empty()) - { - o << startLabelName << ":\n"; - } - if (vUsedLabels.count(s->label)) { if (s->link) diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index cd3acaff..25b6bdb7 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -168,10 +168,10 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s { o << labelPrefix << prolog_label << ":\n"; } - if (!startLabelName.empty()) - { - o << startLabelName << ":\n"; - } + } + if (!startLabelName.empty()) + { + o << startLabelName << ":\n"; } genCondGoto(o, ind, *specMap); } diff --git a/re2c/test/segfault_full_range_star_startlabel.ci.c b/re2c/test/segfault_full_range_star_startlabel.ci.c new file mode 100644 index 00000000..fcf4284a --- /dev/null +++ b/re2c/test/segfault_full_range_star_startlabel.ci.c @@ -0,0 +1,20 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; +start: + switch (YYGETCONDITION()) { + case yycc1: goto yyc_c1; + } +/* *********************************** */ +yyc_c1: + goto yy1; +yy2: + ++YYCURSOR; +yy1: + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + goto yy2; + {} +} + diff --git a/re2c/test/segfault_full_range_star_startlabel.ci.re b/re2c/test/segfault_full_range_star_startlabel.ci.re new file mode 100644 index 00000000..ace5767f --- /dev/null +++ b/re2c/test/segfault_full_range_star_startlabel.ci.re @@ -0,0 +1,4 @@ +/*!re2c + re2c:startlabel = "start"; + [^]* {} +*/ diff --git a/re2c/test/segfault_full_range_star_startlabel.i.c b/re2c/test/segfault_full_range_star_startlabel.i.c new file mode 100644 index 00000000..e43c5199 --- /dev/null +++ b/re2c/test/segfault_full_range_star_startlabel.i.c @@ -0,0 +1,15 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; +start: + goto yy0; +yy1: + ++YYCURSOR; +yy0: + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + goto yy1; + {} +} + diff --git a/re2c/test/segfault_full_range_star_startlabel.i.re b/re2c/test/segfault_full_range_star_startlabel.i.re new file mode 100644 index 00000000..2990c03b --- /dev/null +++ b/re2c/test/segfault_full_range_star_startlabel.i.re @@ -0,0 +1,4 @@ +/*!re2c + re2c:startlabel = "start"; + [^]* {} +*/ -- 2.40.0