tinygo/transform/testdata
Ayke van Laethem 734613c20e transform: introduce check for method calls on nil interfaces
I ran into an issue where I did a method call on a nil interface and it
resulted in a HardFault. Luckily I quickly realized what was going on so
I could fix it, but I think undefined behavior is definitely the wrong
behavior in this case. This commit therefore changes such calls to cause
a nil panic instead of introducing undefined behavior.

This does have a code size impact. It's relatively minor, much lower
than I expected. When comparing the before and after of the drivers
smoke tests (probably the most representative sample available), I found
that most did not change at all and those that did change, normally not
more than 100 bytes (16 or 32 byte changes are typical).

Right now the pattern is the following:

    switch typecode {
    case 1:
        call method 1
    case 2:
        call method 2
    default:
        nil panic
    }

I also tried the following (in the hope that it would be easier to
optimize), but it didn't really result in a code size reduction:

    switch typecode {
    case 1:
        call method 1
    case 2:
        call method 2
    case 0:
        nil panic
    default:
        unreachable
    }

Some code got smaller, while other code (the majority) got bigger. Maybe
this can be improved once range[1] is finally allowed[2] on function
parameters, but it'll probably take a while before that is implemented.

[1]: https://llvm.org/docs/LangRef.html#range-metadata
[2]: https://github.com/rust-lang/rust/issues/50156
2020-05-28 13:42:36 +02:00
..
allocs.ll fix incorrect starting value for optimized allocations in a loop 2019-11-13 16:45:09 +01:00
allocs.out.ll transform: allow updating tests with -update flag 2020-04-09 20:23:51 +02:00
coroutines.ll refactor coroutine lowering and tasks 2020-03-17 12:16:10 +01:00
coroutines.out.ll main: switch to LLVM 10 2020-04-09 20:23:51 +02:00
func-lowering.ll transform (func-lowering): remove specializations from function value lowering and fix lowering of a function value of an unimplemented type 2020-04-12 22:43:43 +02:00
func-lowering.out.ll transform (func-lowering): remove specializations from function value lowering and fix lowering of a function value of an unimplemented type 2020-04-12 22:43:43 +02:00
gc-globals.ll transform: do not track const globals 2020-02-24 21:04:50 +01:00
gc-globals.out.ll transform: do not track const globals 2020-02-24 21:04:50 +01:00
gc-stackslots.ll transform (gc): track phi nodes in stack slots 2020-04-02 15:06:58 +02:00
gc-stackslots.out.ll main: switch to LLVM 10 2020-04-09 20:23:51 +02:00
globals-function-sections.ll compiler: move ApplyFunctionSections to transform package 2020-03-19 19:56:08 +01:00
globals-function-sections.out.ll compiler: move ApplyFunctionSections to transform package 2020-03-19 19:56:08 +01:00
globals-non-const.ll compiler: move NonConstGlobals pass to transform package 2020-03-19 19:56:08 +01:00
globals-non-const.out.ll compiler: move NonConstGlobals pass to transform package 2020-03-19 19:56:08 +01:00
interface.ll transform: introduce check for method calls on nil interfaces 2020-05-28 13:42:36 +02:00
interface.out.ll transform: introduce check for method calls on nil interfaces 2020-05-28 13:42:36 +02:00
interrupt-avr.ll all: add compiler support for interrupts 2020-01-20 21:19:12 +01:00
interrupt-avr.out.ll main: switch to LLVM 10 2020-04-09 20:23:51 +02:00
interrupt-cortexm.ll all: add compiler support for interrupts 2020-01-20 21:19:12 +01:00
interrupt-cortexm.out.ll main: switch to LLVM 10 2020-04-09 20:23:51 +02:00
maps.ll all: move OptimizeMaps to transforms and add tests 2019-09-15 21:26:27 +02:00
maps.out.ll all: move OptimizeMaps to transforms and add tests 2019-09-15 21:26:27 +02:00
panic.ll compiler: move ReplacePanicsWithTrap pass to transforms 2019-11-16 18:41:28 +01:00
panic.out.ll compiler: move ReplacePanicsWithTrap pass to transforms 2019-11-16 18:41:28 +01:00
stringtobytes.ll compiler: move OptimizeStringToBytes to transform package 2019-09-22 08:25:50 +02:00
stringtobytes.out.ll compiler: move OptimizeStringToBytes to transform package 2019-09-22 08:25:50 +02:00
wasm-abi.ll compiler: move wasm ABI workaround to transform package 2020-01-28 19:29:09 +01:00
wasm-abi.out.ll main: switch to LLVM 10 2020-04-09 20:23:51 +02:00