rui314 / 8cc

A Small C Compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Various problems.

rdebath opened this issue · comments

I've just generated this piece of C code from a torture test of BF program interpreters. Obviously, being generated code it promises to be a bit of problem. I suspect this promise will be fulfilled.

https://gist.github.com/rdebath/ecd1454a259ece0a8ecf

The CPP define "C" can be declared, on the command line or inside, to be any integer type, signed or unsigned, for 8 bits to 128bits or more. The program, when run, should display one of a few variants of 'hello world' and then finish.

The default of integers complies and runs, but incorrectly.
Any type smaller then an integer gets a 'not an lvalue' error from a "-- * X" type construct.
Longs compile, but seem not to work at all, however, this appears to be a problem with 'stdint.h'.

Test run on Debian Wheezy.

Nothing in the code looks too crazy, though large parts of the code are being rewritten atm so the issue might need to wait until after the rewrite.

I'll make a smaller test case out of your code later though, it might be useful to fill holes in the 8cc test suite. I'll add it onto a branch on my own fork so I don't forget about it.

Heh, if you want crazy I can do that too ... https://gist.github.com/rdebath/2120d506bda710a76dd6

This one seems to work correctly, however, it doesn't get any constant folding done on it so the binary is a bit large (but the memory it needs to compile isn't too bad).

TODO: Constant folding of expressions like:

    x[4] += 1+1+1+1+1+1+1+1+1;
    si.flg = 4096+256+64+2+1;

This compiler has no serious test sets except the ones in test directory and the compiler itself. When I write new code for the compiler I sometimes found a miscompilation. So I wouldn't surprise that the code couldn't be compiled correctly with 8cc. I'll take a look later.

@rdebath I don't think we want crazy :). Sane code with errors is more useful. Also, 8cc doesn't do constant folding, it may need to in the future to fix issue #5 though.