sysprog21 / shecc

A self-hosting and educational C optimizing compiler
BSD 2-Clause "Simplified" License
1.11k stars 118 forks source link

The peephole optimization breaks the macro expansion #112

Closed vacantron closed 7 months ago

vacantron commented 7 months ago

Considering the following test case:

#define M(a, b) a + b

int main()
{
    return M(1, 2) * 3;
}

The stage-1 shecc (i.e. out/shecc-stage1.elf, testing with command: qemu-arm out/shecc-stage1.elf --no-libc <file>) reports:

Error Unexpected token at source location 20
#define M(a, b) a + b
                    ^ Error occurs here
Abnormal program termination

The current test driver runs on the stage-0 shecc and doesn't detect this error.

jserv commented 7 months ago

The current test driver runs on the stage-0 shecc and doesn't detect this error.

Shall we enable extra stage-1 check in CI pipeline?

vacantron commented 7 months ago

Shall we enable extra stage-1 check in CI pipeline?

I think not. The stage-1 check needs to self-host first, but the current workflow only invokes the unit test.

This problem is caused by the uncovered scenario in the test driver. We can refine the test driver to detect this problem.