pepper-project / pequin

A system for verifying outsourced computations, and applying SNARKs. Simplified release of the main Pepper codebase.
Other
122 stars 46 forks source link

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

Open noresistence opened 5 years ago

noresistence commented 5 years ago

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 commented 5 years ago

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.