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

printf with "%s" assertion error &604 #58

Open
noresistence opened this issue Mar 20, 2019 · 1 comment
Open

printf with "%s" assertion error &604 #58

noresistence opened this issue Mar 20, 2019 · 1 comment

Comments

@noresistence
Copy link

When calling printf("[...] %s", s) with some string literal s, an Assertion Error pops up:

example.c

#define FOO 10

#define str_expand(x) #x
#define str(x) str_expand(x)

struct In {
    int in;
};
struct Out {
    int out;
};

void compute(struct In *input, struct Out *output) {
    /* Print constants */
    printf("FOO: %s", str(FOO));
}

Error message during compilation

Exception in thread "main" java.lang.RuntimeException: Assertion error &604
        at SFE.Compiler.PrintfStatement.toAssignmentStatements_NoChangeRef(PrintfStatement.java:93)
        at SFE.Compiler.PrintfStatement.toAssignmentStatements(PrintfStatement.java:86)
        at SFE.Compiler.BlockStatement.toAssignmentStatements(BlockStatement.java:111)
        at ccomp.parser_hw.CCompiler.addStatement(CCompiler.java:521)
        at ccomp.parser_hw.CCompiler.builtinFunctionCall(CCompiler.java:1651)
        at ccomp.parser_hw.CCompiler.genericFunctionCall(CCompiler.java:1009)
        at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:958)
        at ccomp.parser_hw.CCompiler.getExpr(CCompiler.java:793)
        at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:660)
        at ccomp.parser_hw.CCompiler.expandStatement(CCompiler.java:635)
        at ccomp.parser_hw.CCompiler.access$1100(CCompiler.java:114)
        at ccomp.parser_hw.CCompiler$CMainStatement.toAssignmentStatements(CCompiler.java:491)
        at SFE.Compiler.BlockStatement.toAssignmentStatements(BlockStatement.java:111)
        at SFE.Compiler.FunctionBody.toAssignmentStatements(FunctionBody.java:31)
        at zcc.ZCC.compile(ZCC.java:260)
        at zcc.ZCC.main(ZCC.java:127)
@maxhowald
Copy link
Contributor

Thanks for reporting this! (and #56).

Since you're not the first person to report issues with printf, we'll look into improving it, although I can't promise any kind of timeline.

For now, I've added to the documentation in printf.txt to clarify these limitations.

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

2 participants