Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code generation error with wide chars and bitmaps (omitted 'goto' statement) #127

Closed
skvadrik opened this issue Dec 9, 2015 · 1 comment
Closed
Assignees
Milestone

Comments

@skvadrik
Copy link
Owner

@skvadrik skvadrik commented Dec 9, 2015

Source code (err.re):

/*!re2c
    [^a]+ {}
    [a]   {}
*/

Skeleton helped me catch an error in code generation:

$ re2c -W -ubi err.re -S -o err.c && gcc err.c -o err && ./err
error: lex_line4: at position 294 (iteration 98):
        expected: match length 2, rule 0
        actual:   match length 1, rule 1

The generated code:

$ re2c -ubi err.re
/* Generated by re2c 0.15.3 on Wed Dec  9 11:07:24 2015 */

{
        YYCTYPE yych;
        static const unsigned char yybm[] = {
                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,   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,.
        };
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        if (yych & ~0xFF) {
        } else if (yybm[0+yych] & 128) {
                goto yy2;
        }
        goto yy5;
yy2:
        ++YYCURSOR;
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        if (yych & ~0xFF) {
                goto yy2;
        } else if (yybm[0+yych] & 128) {
                goto yy2;
        }
        {}
yy5:
        ++YYCURSOR;
        {}
}

The false part is:

        if (yych & ~0xFF) {
        } else if (yybm[0+yych] & 128) {
                goto yy2;
        }
        goto yy5;
yy2:

It should be:

        if (yych & ~0xFF) {
                goto yy2;
        } else if (yybm[0+yych] & 128) {
                goto yy2;
        }
        goto yy5;
yy2:

This is a false optimization: re2c thinks that since the next state is yy2, it can omit goto yy2;. But in this particular case there is a fallthrough to goto yy5;.

Previous versions also have this bug (re2c-0.13.6 generates even worse code: it has this error and another similar error).

@skvadrik skvadrik self-assigned this Dec 9, 2015
@skvadrik skvadrik added this to the 0.16 milestone Dec 9, 2015
skvadrik added a commit that referenced this issue Dec 9, 2015
…mitted 'goto' statement)".

Minimal test case:
    /*!re2c
        [^a]+ {}
        [a]   {}
    */

Catched with skeleton:
    $ re2c -W -ubi err.re -S -o err.c && gcc err.c -o err && ./err
    error: lex_line4: at position 294 (iteration 98):
            expected: match length 2, rule 0
            actual:   match length 1, rule 1
@skvadrik
Copy link
Owner Author

@skvadrik skvadrik commented Dec 9, 2015

Fixed in this coommit: 4fa27cf

Loading

@skvadrik skvadrik closed this Dec 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant