]> granicus.if.org Git - re2c/commitdiff
Output user-defines start label in the appropriate place.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 26 May 2015 20:34:56 +0000 (21:34 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 26 May 2015 20:34:56 +0000 (21:34 +0100)
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
re2c/src/codegen/emit_dfa.cc
re2c/test/segfault_full_range_star_startlabel.ci.c [new file with mode: 0644]
re2c/test/segfault_full_range_star_startlabel.ci.re [new file with mode: 0644]
re2c/test/segfault_full_range_star_startlabel.i.c [new file with mode: 0644]
re2c/test/segfault_full_range_star_startlabel.i.re [new file with mode: 0644]

index d6eaa17416725d8831023b12187ff12f3ab4fa06..0efca68ee2e60106f4fee2c6253084c1fd5a76de 100644 (file)
@@ -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)
index cd3acaffd5e4f5af5a93bc9a27a23cdb5d52dcf4..25b6bdb74755b0586305d6c01d303a59dd05c68c 100644 (file)
@@ -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 (file)
index 0000000..fcf4284
--- /dev/null
@@ -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 (file)
index 0000000..ace5767
--- /dev/null
@@ -0,0 +1,4 @@
+/*!re2c
+       re2c:startlabel = "start";
+       <c1> [^]*       {}
+*/
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 (file)
index 0000000..e43c519
--- /dev/null
@@ -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 (file)
index 0000000..2990c03
--- /dev/null
@@ -0,0 +1,4 @@
+/*!re2c
+       re2c:startlabel = "start";
+       [^]*    {}
+*/