cc icon indicating copy to clipboard operation
cc copied to clipboard

Unhandled case: TODO case 1: // '(' Declarator ')'

Open xlab opened this issue 8 years ago • 12 comments

Hi, I'm back!

Getting this panic:

panic: 1

goroutine 1 [running]:
panic(0x2d58e0, 0xc42071e258)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/cznic/cc.(*ctype).Kind(0xc420719080, 0xc4203663c0)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/etc.go:858 +0xf2
github.com/cznic/cc.(*Expression).eval(0xc42052f980, 0xc4203663c0, 0x0, 0x0, 0x4f15e0, 0xc420719020)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/ast2.go:638 +0xc85
github.com/cznic/cc.(*Expression).eval(0xc42052fec0, 0xc4203663c0, 0x0, 0xc420816640, 0x149f8, 0x8)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/ast2.go:1588 +0x61f5
github.com/cznic/cc.(*ExpressionList).eval(0xc4207013b0, 0xc4203663c0, 0x4a, 0xc4201c2398, 0x4f1500, 0xc420719020)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/ast2.go:1709 +0x5b
github.com/cznic/cc.yyParse(0x4e6300, 0xc4203663c0, 0xc420011920)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/parser.go:3186 +0x5764
github.com/cznic/cc.Parse(0xc420364a00, 0x251, 0xc42000faf0, 0x1, 0x1, 0x5252c0, 0xc420817ad0, 0x2, 0x2, 0x8, ...)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/cc.go:497 +0x743

On this line: linmath.h:92:43. Seems to be an unimplemented case for a weird style of programming.

xlab avatar Aug 13 '16 11:08 xlab

Thanks for the report. Got a repro? (ie. C source triggering the panic)

EDIT:

Opps, now I see the repro is included in the OP. Sorry!

cznic avatar Aug 13 '16 11:08 cznic

Please try branch issue51 and let me know.

cznic avatar Aug 13 '16 11:08 cznic

FYI: https://github.com/cznic/cc/commit/53001f082af055dbe567ecc23f02570089898b7f did not fix the issue.

cznic avatar Aug 13 '16 11:08 cznic

Hey, it worked for my case well! Although I discovered another one:

Repro code:

#include <math.h>

#define LINMATH_H_DEFINE_VEC(n) \
typedef float vec##n[n];

LINMATH_H_DEFINE_VEC(4)

typedef vec4 mat4x4[4];

Panic in case 1:

linmath.h:11:14
panic: 1

goroutine 1 [running]:
panic(0x2d5a60, 0xc4202ac1b0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/cznic/cc.(*ctype).Elements(0xc420789e00, 0x1b)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/etc.go:1102 +0x195

P.S. this code has many of missing cases, but the first one seems to be fixed in the branch.

xlab avatar Aug 13 '16 11:08 xlab

PTAL.

cznic avatar Aug 13 '16 12:08 cznic

P.S. this code has many of missing cases, but the first one seems to be fixed in the branch.

Yeah, originally the intent was not to publish cc. It was an internal package and it was made to handle exactly one particular C file so I handled only cases happening in that source code. And then you wanted it published ... and that's where we are now ;-)

cznic avatar Aug 13 '16 12:08 cznic

The latest fix is for setElements, but this happens in the source code which I had removed because I'm interested in the headers only. In my minimal example above it triggers a bug here:

    /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/cznic/cc.(*ctype).Elements(0xc420815da0, 0x1b)
    /Users/xlab/Documents/dev/go/src/github.com/cznic/cc/etc.go:1102 +0xb8

That's *ctype.Elements in typedef and it's still there.

xlab avatar Aug 13 '16 12:08 xlab

Yeah, originally the intent was not to publish cc. It was an internal package and it was made to handle exactly one particular C file so I handled only cases happening in that source code.

No worries at all! It perfectly handles a lot of generic-like header files and fits perfectly for all my binding stuff needs. By saying this code has many of missing cases I was referring to the libmath.h code that uses uncommon code style for its headers, so CC's cases not so surprisingly are missing there.

xlab avatar Aug 13 '16 12:08 xlab

I hope to fix the issue later today. Thanks for patience ;-)

cznic avatar Aug 13 '16 12:08 cznic

What's patience? 😄 I rewrote entire lib in Go https://github.com/xlab/linmath

xlab avatar Aug 13 '16 15:08 xlab

Great job Max!

Now with the presure removed, I'll probably keep this open until it bites again, okay? :8ball:

cznic avatar Aug 14 '16 10:08 cznic

Given that this seems to be not a trivial fix, let's keep this open :)

xlab avatar Aug 14 '16 11:08 xlab