elliotchance / c2go

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

UnaryExprOrTypeTraitExpr does not support ConditionalOperator #868

Closed kroppt closed 3 years ago

kroppt commented 3 years ago

Error:

panic: cannot do unary on: &ast.ConditionalOperator{Addr:0x55714bab87b8, Pos:ast.Position{File:"/home/user/code/c2gotest/c/code.c", Line:2, LineEnd:0, Column:18, ColumnEnd:26, StringValue:""}, Type:"int", ChildNodes:[]ast.Node{(*ast.IntegerLiteral)(0xc00022e900), (*ast.IntegerLiteral)(0xc00022e980), (*ast.IntegerLiteral)(0xc000106480)}}

goroutine 1 [running]:
github.com/elliotchance/c2go/transpiler.transpileUnaryExprOrTypeTraitExpr(0xc000236dc0, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/unary.go:724 +0x496
github.com/elliotchance/c2go/transpiler.transpileToExpr(0x711e40, 0xc000236dc0, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:203 +0x364
github.com/elliotchance/c2go/transpiler.transpileImplicitCastExpr(0xc000236be0, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/cast.go:41 +0x1a7
github.com/elliotchance/c2go/transpiler.transpileToExpr(0x711340, 0xc000236be0, 0xc00019a000, 0xc000046700, 0x0, 0x0, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:179 +0x878
github.com/elliotchance/c2go/transpiler.transpileReturnStmt(0xc00020e480, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/functions.go:337 +0xe5
github.com/elliotchance/c2go/transpiler.transpileToStmt(0x711b40, 0xc00020e480, 0xc00019a000, 0x0, 0x0, 0x8dd368, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:349 +0xf4a
github.com/elliotchance/c2go/transpiler.transpileToStmts(0x711b40, 0xc00020e480, 0xc00019a000, 0x8dd368, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:270 +0xdf
github.com/elliotchance/c2go/transpiler.transpileCompoundStmt(0xc000273500, 0xc00019a000, 0x0, 0x8, 0x400000000, 0xffffffffffffffff, 0x0, 0xc000046ca8, 0x30000000066ada0, 0xffffffffffffffff,
...)
        /home/user/code/c2go/transpiler/scope.go:21 +0xbb
github.com/elliotchance/c2go/transpiler.transpileToStmt(0x710ac0, 0xc000273500, 0xc00019a000, 0x0, 0x0, 0x8dd368, 0x0, 0x0, 0x8dd368, 0x0, ...)
        /home/user/code/c2go/transpiler/transpiler.go:352 +0xb98
github.com/elliotchance/c2go/transpiler.transpileToStmts(0x710ac0, 0xc000273500, 0xc00019a000, 0x8dd368, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:270 +0xdf
github.com/elliotchance/c2go/transpiler.transpileToBlockStmt(0x710ac0, 0xc000273500, 0xc00019a000, 0x4, 0xc000116e08, 0x8dd301, 0x0, 0x0, 0x0, 0x0, ...)
        /home/user/code/c2go/transpiler/scope.go:38 +0x43
github.com/elliotchance/c2go/transpiler.transpileFunctionDecl(0xc00027a000, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/functions.go:86 +0x287d
github.com/elliotchance/c2go/transpiler.transpileToNode(0x711140, 0xc00027a000, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:448 +0x308
github.com/elliotchance/c2go/transpiler.transpileTranslationUnitDecl(0xc00019a000, 0xc00000c500, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/translation_unit.go:116 +0x153
github.com/elliotchance/c2go/transpiler.transpileToNode(0x711d00, 0xc00000c500, 0xc00019a000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/user/code/c2go/transpiler/transpiler.go:445 +0xbce
github.com/elliotchance/c2go/transpiler.TranspileAST(0x0, 0x0, 0x6b0360, 0x4, 0xc00019a000, 0x711d00, 0xc00000c500, 0x1a, 0x1a)
        /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

Soure file: https://github.com/elliotchance/c2go/blob/72b29fc853de024e982e28dd754b0686e47ccf01/tests/assert.c

Test file:

int main()
{
    return sizeof(1 ? 1 : 2);
}

Related: #778