]> granicus.if.org Git - re2c/commitdiff
- Fixed #1472770 re2c creates an infinite loop.
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 1 May 2006 22:45:59 +0000 (22:45 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 1 May 2006 22:45:59 +0000 (22:45 +0000)
CHANGELOG
code.cc
htdocs/index.html
test/bug1472770.b.c [new file with mode: 0755]
test/bug1472770.b.re [new file with mode: 0755]
test/bug1472770.c [new file with mode: 0755]
test/bug1472770.f.c [new file with mode: 0755]
test/bug1472770.f.re [new file with mode: 0755]
test/bug1472770.re [new file with mode: 0755]
test/bug1472770.s.c [new file with mode: 0755]
test/bug1472770.s.re [new file with mode: 0755]

index b7ac8feed0eada761a0c7588de981d46952a067c..a3ee292414b0837ce5665c688e3e48050af9cc25 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@ Version 0.10.2 (2006-??-??)
 - Changed to use if- instead of switch-expression when yyaccpt has only one case.
 - Added docu, examples and tests to .src.zip package (0.10.1 zip was repackaged).
 - Fixed #1479044 incorrect code generated when using -b.
+- Fixed #1472770 re2c creates an infinite loop.
 - Fixed #1454253 Piece of code saving a backtracking point not generated.
 - Fixed #1463639 Missing forward declaration.
 - Implemented #1187127 savable state support for multiple re2c blocks.
diff --git a/code.cc b/code.cc
index 931a44900aa109f61be1004d6e819ea965cb168e..371acbbe22d76722123956fe0e418a58d8926a4a 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -399,6 +399,19 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const
        {
                o << startLabelName << ":\n";
        }
+
+       if (vUsedLabels.count(1))
+       {
+               if (state->link)
+               {
+                       o << indent(ind) << "++YYCURSOR;\n";
+               }
+               else
+               {
+                       o << indent(ind) << "yych = *++YYCURSOR;\n";
+               }
+       }
+
        if (vUsedLabels.count(label))
        {
                o << "yy" << label << ":\n";
@@ -407,10 +420,12 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const
        {
                o << "\n";
        }
+
        if (dFlag)
        {
                o << indent(ind) << "YYDEBUG(" << label << ", *YYCURSOR);\n";
        }
+
        if (state->link)
        {
                need(o, ind, state->depth, readCh, setMarker && bUsedYYMarker);
@@ -1430,6 +1445,12 @@ void DFA::emit(std::ostream &o, uint ind)
 
        genGetState(o, ind, start_label);
 
+       if (vUsedLabels.count(1))
+       {
+               vUsedLabels.insert(0);
+               o << indent(ind) << "goto yy0;\n";
+       }
+
        // Generate code
        for (s = head; s; s = s->next)
        {
index c1c38f957814d63b1cb617bbb538c142cf42905a..011381b8b1dbd7ed864738f7a1939f39fdae99e7 100755 (executable)
@@ -93,6 +93,7 @@ provide re2c packages.</li>
 <li>Changed to use if- instead of switch-expression when yyaccpt has only one case.</li>
 <li>Added docu, examples and tests to .src.zip package (0.10.1 zip was repackaged).</li>
 <li>Fixed #1479044 incorrect code generated when using -b.</li>
+<li>Fixed #1472770 re2c creates an infinite loop.</li>
 <li>Fixed #1454253 Piece of code saving a backtracking point not generated.</li>
 <li>Fixed #1463639 Missing forward declaration.</li>
 <li>Implemented #1187127 savable state support for multiple re2c blocks.</li>
diff --git a/test/bug1472770.b.c b/test/bug1472770.b.c
new file mode 100755 (executable)
index 0000000..8dd8f3d
--- /dev/null
@@ -0,0 +1,108 @@
+/* Generated by re2c */
+#line 1 "bug1472770.b.re"
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+{
+       static unsigned char yybm[] = {
+                 0, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128,   0, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+               128, 128, 128, 128, 128, 128, 128, 128, 
+       };
+
+#line 58 "<stdout>"
+       {
+               YYCTYPE yych;
+               goto yy0;
+yy1:
+               ++YYCURSOR;
+yy0:
+               if(YYLIMIT == YYCURSOR) YYFILL(1);
+               yych = *YYCURSOR;
+               if(yybm[0+yych] & 128) {
+                       goto yy1;
+               }
+               if(yych <= 0x00) goto yy5;
+               ++YYCURSOR;
+#line 21 "bug1472770.b.re"
+               {
+               ++n;
+               goto start;
+       }
+#line 77 "<stdout>"
+yy5:
+               ++YYCURSOR;
+#line 26 "bug1472770.b.re"
+               {
+               return n;
+       }
+#line 84 "<stdout>"
+       }
+}
+#line 29 "bug1472770.b.re"
+
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.b.re b/test/bug1472770.b.re
new file mode 100755 (executable)
index 0000000..84cd455
--- /dev/null
@@ -0,0 +1,50 @@
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+/*!re2c
+[^\n\000]* '\n'
+       {
+               ++n;
+               goto start;
+       }
+[^\n\000]* '\000'
+       {
+               return n;
+       }
+*/
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.c b/test/bug1472770.c
new file mode 100755 (executable)
index 0000000..fb2ea04
--- /dev/null
@@ -0,0 +1,74 @@
+/* Generated by re2c */
+#line 1 "bug1472770.re"
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+
+#line 23 "<stdout>"
+{
+       YYCTYPE yych;
+       goto yy0;
+yy1:
+       ++YYCURSOR;
+yy0:
+       if(YYLIMIT == YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch(yych){
+       case 0x00:      goto yy5;
+       case 0x0A:      goto yy3;
+       default:        goto yy1;
+       }
+yy3:
+       ++YYCURSOR;
+#line 21 "bug1472770.re"
+       {
+               ++n;
+               goto start;
+       }
+#line 44 "<stdout>"
+yy5:
+       ++YYCURSOR;
+#line 26 "bug1472770.re"
+       {
+               return n;
+       }
+#line 51 "<stdout>"
+}
+#line 29 "bug1472770.re"
+
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.f.c b/test/bug1472770.f.c
new file mode 100755 (executable)
index 0000000..428f382
--- /dev/null
@@ -0,0 +1,87 @@
+/* Generated by re2c */
+#line 1 "bug1472770.f.re"
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+YYCTYPE yych;
+int yySavedState;
+
+#define YYGETSTATE()   yySavedState
+#define YYSETSTATE(n)  yySavedState = n;
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+
+#line 29 "<stdout>"
+{
+
+       switch(YYGETSTATE())
+       {
+       default: goto yy0;
+       case 0: goto yyFillLabel0;
+       }
+       goto yy0;
+yy1:
+       ++YYCURSOR;
+yy0:
+       YYSETSTATE(0);
+       if(YYLIMIT == YYCURSOR) YYFILL(1);
+yyFillLabel0:
+       yych = *YYCURSOR;
+       switch(yych){
+       case 0x00:      goto yy5;
+       case 0x0A:      goto yy3;
+       default:        goto yy1;
+       }
+yy3:
+       ++YYCURSOR;
+#line 27 "bug1472770.f.re"
+       {
+               ++n;
+               goto start;
+       }
+#line 57 "<stdout>"
+yy5:
+       ++YYCURSOR;
+#line 32 "bug1472770.f.re"
+       {
+               return n;
+       }
+#line 64 "<stdout>"
+}
+#line 35 "bug1472770.f.re"
+
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.f.re b/test/bug1472770.f.re
new file mode 100755 (executable)
index 0000000..7d788a5
--- /dev/null
@@ -0,0 +1,56 @@
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+YYCTYPE yych;
+int yySavedState;
+
+#define YYGETSTATE()   yySavedState
+#define YYSETSTATE(n)  yySavedState = n;
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+/*!re2c
+[^\n\000]* '\n'
+       {
+               ++n;
+               goto start;
+       }
+[^\n\000]* '\000'
+       {
+               return n;
+       }
+*/
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.re b/test/bug1472770.re
new file mode 100755 (executable)
index 0000000..84cd455
--- /dev/null
@@ -0,0 +1,50 @@
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+/*!re2c
+[^\n\000]* '\n'
+       {
+               ++n;
+               goto start;
+       }
+[^\n\000]* '\000'
+       {
+               return n;
+       }
+*/
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.s.c b/test/bug1472770.s.c
new file mode 100755 (executable)
index 0000000..16ff3ed
--- /dev/null
@@ -0,0 +1,70 @@
+/* Generated by re2c */
+#line 1 "bug1472770.s.re"
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+
+#line 23 "<stdout>"
+{
+       YYCTYPE yych;
+       goto yy0;
+yy1:
+       ++YYCURSOR;
+yy0:
+       if(YYLIMIT == YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       if(yych <= 0x00) goto yy5;
+       if(yych != 0x0A) goto yy1;
+       ++YYCURSOR;
+#line 21 "bug1472770.s.re"
+       {
+               ++n;
+               goto start;
+       }
+#line 40 "<stdout>"
+yy5:
+       ++YYCURSOR;
+#line 26 "bug1472770.s.re"
+       {
+               return n;
+       }
+#line 47 "<stdout>"
+}
+#line 29 "bug1472770.s.re"
+
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}
diff --git a/test/bug1472770.s.re b/test/bug1472770.s.re
new file mode 100755 (executable)
index 0000000..84cd455
--- /dev/null
@@ -0,0 +1,50 @@
+#define NULL ((char*) 0)
+#define YYCTYPE char
+#define YYCURSOR p
+#define YYLIMIT p
+#define YYMARKER q
+#define YYFILL(n)
+
+#include <stdio.h>
+
+int scan(char *p)
+{
+       int n = 0;
+       char *q;
+       
+       printf("[--------------\n");
+       printf("%s\n", p);
+       printf("]--------------\n");
+start:
+/*!re2c
+[^\n\000]* '\n'
+       {
+               ++n;
+               goto start;
+       }
+[^\n\000]* '\000'
+       {
+               return n;
+       }
+*/
+}
+
+int main(int argc, char **argv)
+{
+       int n = 0;
+       char *largv[4];
+
+       if (argc < 2)
+       {
+               argc = 4;
+               argv = largv;
+               argv[1] = "";
+               argv[2] = "1\n\n";
+               argv[3] = "1\n2\n";
+       }
+       while(++n < argc)
+       {
+               printf("%d\n", scan(argv[n]));
+       }
+       return 0;
+}