windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
337 stars 36 forks source link

ppci-cc: crash when using the "value" returned by a "void" function #86

Closed tstreiff closed 4 years ago

tstreiff commented 4 years ago

int val = exit(-1);

makes the compiler crash during IR generation.

File "/home/tsf/sandbox/ppci/ppci/ir.py", line 687, in setter "Expecting a Value instance, but got {}".format(value) TypeError: Expecting a Value instance, but got None

exit() returns "void", so using the value it returns is illegal. However this is not detected, and the parsing/semantic phase calls coerce() to add a cast from "void" to "int". During IR generation, gen_cast crashes because it expects a IR value and gets None.

In semantics, coerce() should no accept to coerce "void" to anything. This way, an error would be reported during parsing/semantic phase.

windelbouwman commented 4 years ago

Thanks! Well catched bug!