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

Infinite loop in frontend #1

Open
elazarg opened this issue May 16, 2016 · 3 comments
Open

Infinite loop in frontend #1

elazarg opened this issue May 16, 2016 · 3 comments

Comments

@elazarg
Copy link

elazarg commented May 16, 2016

A trace loop:

at ccomp.parser_hw.CCompiler.genericFunctionCall(CCompiler.java:1039)
at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:947)
at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:961)
at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:782)
at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:649)
at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:624)
at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:840)
at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:649)
at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:862)
at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:649)
at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:624)
at ccomp.parser_hw.CCompiler.genericFunctionCall(CCompiler.java:1039)
@kwantam
Copy link
Member

kwantam commented May 16, 2016

Thanks for reporting this 👍

Do you have a test case you could share that triggers this issue?

@elazarg
Copy link
Author

elazarg commented May 16, 2016

It is a recursive program, so I assume that's an unbounded number of inlining. It's just that there is a clear warning for unbounded loops, and there isn't one for unbounded recursion.

@elazarg
Copy link
Author

elazarg commented May 16, 2016

// adapted from code by Rob Pike
// www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html

int matchhere(char *regexp, char *text);

int matchstar(int c, char *regexp, char *text)
{
    int res = 0;
    do {    /* a * matches zero or more instances */
        if (matchhere(regexp, text)) {
            res = 1;
            break;
        }
    } while (*text != 0 && (*text++ == c || c == '.'));
    return res;
}     

int matchhere(char *regexp, char *text)
{
    int res = 0;
    char* chars = "*$.";
    if (regexp[0] == 0) {
        res = 1;
    } else 
    if (regexp[1] == chars[0]) {
        res = matchstar(regexp[0], regexp+2, text);
    } else 
    if (regexp[0] == chars[1] && regexp[1] == 0) {
        res = *text == 0;
    } else 
    if (*text!=0 && (regexp[0]==chars[2] || regexp[0]==*text)) {
        res = matchhere(regexp+1, text+1);
    }
    return res;
}

int match(char *regexp, char *text)
{
    char* anchor = "^";
    int res = 0;
    if (regexp[0] == anchor[0]) { 
        res = matchhere(regexp+1, text);
    } else
    do {    /* must look even if string is empty */
        if (matchhere(regexp, text)) {
            res = 1;
            break;
        }
    } while (*text++ != 0);
    return res;
}

char* POSITIVE = "assumes word senses. Within";

char* NEGATIVE = "in the U.S.A., people often";

struct In {
    char regex[30];
};

struct Out {
    int success;
};

int compute(struct In* input, struct Out* output) {
    char* regex = input->regex;
    int pos = match(regex, POSITIVE);
    int neg = match(regex, NEGATIVE);
    output->success = pos + 1-neg;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@kwantam @elazarg and others