From: Ulya Trofimovich Date: Tue, 26 May 2015 20:34:56 +0000 (+0100) Subject: Output user-defines start label in the appropriate place. X-Git-Tag: 0.15~245 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ede5a7546215ba6dd328c707629f789b90edf31;p=re2c 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; {} } --- 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"; + [^]* {} +*/