tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
14.72k stars 858 forks source link

compiler/empty basic block #4283

Closed leongross closed 3 weeks ago

leongross commented 4 weeks ago

To generate a function, tinygo builds a function using llvm and a list of pre-defined basic blocks. Therefore it needs the first basic block for the entry point of a function. If the list of BasicBlocks is empty, this indicates that the function is external 1. Getting the first basic block is then impossible and results in a panic (observed in 2).

This PR aims to fix this issue and end the compilation gracefully. Since my experience with compiler development is non though, it would be great if the original authors (@aykevl) could take care of the logic behind this and probably make it behave sanely.