elliotchance / c2go

⚖️ A tool for transpiling C to Go.
MIT License
2.06k stars 151 forks source link

UnaryExprOrTypeTraitExpr does not support IntegerLiteral #870

Closed kroppt closed 3 years ago

kroppt commented 3 years ago

Error:

panic: cannot do unary on: &ast.IntegerLiteral{Addr:0x559734fcd8c8, Pos:ast.Position{File:"/home/user/code/c2gotest/c/code.c", Line:2, LineEnd:0, Column:18, ColumnEnd:0, StringValue:""}, Type:"int", Value:"1", ChildNodes:[]ast.Node{}}

goroutine 1 [running]:
github.com/elliotchance/c2go/transpiler.transpileUnaryExprOrTypeTraitExpr(0xc0001a9cc0, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/unary.go:730 +0x521
github.com/elliotchance/c2go/transpiler.transpileToExpr(0x711e40, 0xc0001a9cc0, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:203 +0x364
github.com/elliotchance/c2go/transpiler.transpileImplicitCastExpr(0xc0001a9ae0, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/cast.go:41 +0x1a7
github.com/elliotchance/c2go/transpiler.transpileToExpr(0x711340, 0xc0001a9ae0, 0xc000244000, 0xc000046700, 0x0, 0x0, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:179 +0x878
github.com/elliotchance/c2go/transpiler.transpileReturnStmt(0xc000198b40, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/functions.go:337 +0xe5
github.com/elliotchance/c2go/transpiler.transpileToStmt(0x711b40, 0xc000198b40, 0xc000244000, 0x0, 0x0, 0x8dd368, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:349 +0xf4a
github.com/elliotchance/c2go/transpiler.transpileToStmts(0x711b40, 0xc000198b40, 0xc000244000, 0x8dd368, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:270 +0xdf
github.com/elliotchance/c2go/transpiler.transpileCompoundStmt(0xc0002c7880, 0xc000244000, 0x0, 0x8, 0x600000400000000, 0xffffffffffffffff, 0x0, 0xc000046ca8, 0x60000000066ada0, 0xffffffffffffffff, ...)
        /home/user/code/c2go/transpiler/scope.go:21 +0xbb
github.com/elliotchance/c2go/transpiler.transpileToStmt(0x710ac0, 0xc0002c7880, 0xc000244000, 0x0, 0x0, 0x8dd368, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:352 +0xb98
github.com/elliotchance/c2go/transpiler.transpileToStmts(0x710ac0, 0xc0002c7880, 0xc000244000, 0x8dd368, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:270 +0xdf
github.com/elliotchance/c2go/transpiler.transpileToBlockStmt(0x710ac0, 0xc0002c7880, 0xc000244000, 0x4, 0xc00028d708, 0x8dd301, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/scope.go:38 +0x43
github.com/elliotchance/c2go/transpiler.transpileFunctionDecl(0xc0001ae8f0, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/functions.go:86 +0x287d
github.com/elliotchance/c2go/transpiler.transpileToNode(0x711140, 0xc0001ae8f0, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:448 +0x308
github.com/elliotchance/c2go/transpiler.transpileTranslationUnitDecl(0xc000244000, 0xc00000c240, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/translation_unit.go:116 +0x153
github.com/elliotchance/c2go/transpiler.transpileToNode(0x711d00, 0xc00000c240, 0xc000244000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:445 +0xbce
github.com/elliotchance/c2go/transpiler.TranspileAST(0x0, 0x0, 0x6b0360, 0x4, 0xc000244000, 0x711d00, 0xc00000c240, 0x17, 0x17)
        /home/user/code/c2go/transpiler/transpiler.go:32 +0x1a1
main.Start(0x0, 0xc0000101a0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6b0360, ...)
        /home/user/code/c2go/main.go:297 +0xf0c
main.runCommand(0xc000064058)
        /home/user/code/c2go/main.go:429 +0x42c
main.main()
        /home/user/code/c2go/main.go:352 +0x22

clang:

~ $ clang --version
clang version 10.0.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/10/bin

Source: https://c-testsuite.github.io/c2go_report.html

Test file:

int main() {
    return sizeof(1);
}