tinygo/compiler
Ayke van Laethem c41a212712 wasm: avoid miscompile with ThinLTO
I found that when I enable ThinLTO, a miscompilation triggers that had
been hidden all the time previously. The bug appears to happen as
follows:

 1. TinyGo generates a function with a runtime.trackPointer call, but
    without an alloca (or the alloca gets optimized away).
 2. LLVM sees that no alloca needs to be kept alive across the
    runtime.trackPointer call, and therefore it adds the 'tail' flag.
    One of the effects of this flag is that it makes it undefined
    behavior to keep allocas alive across the call (which is still safe
    at that point).
 3. The GC lowering pass adds a stack slot alloca and converts
    runtime.trackPointer calls into alloca stores.

The last step triggers the bug: the compiler inserts an alloca where
there was none before but that's not valid as long as the 'tail' flag is
present.

This patch fixes the bug in a somewhat dirty way, by always creating a
dummy alloca so that LLVM won't do the optimization in step 2 (and
possibly other optimizations that rely on there being no alloca
instruction).
2023-01-18 08:24:42 +01:00
..
ircheck all: remove pointer ElementType calls 2022-10-19 22:23:19 +02:00
llvmutil compiler: move some llvmutil code into the compiler 2023-01-18 08:24:42 +01:00
testdata wasm: avoid miscompile with ThinLTO 2023-01-18 08:24:42 +01:00
alias.go all: add type parameter to CreateCall 2022-10-19 22:23:19 +02:00
asserts.go compiler: add support for new unsafe slice/string functions 2023-01-17 08:38:54 +01:00
atomic.go all: add type parameter to CreateLoad 2022-10-19 22:23:19 +02:00
calls.go all: remove pointer ElementType calls 2022-10-19 22:23:19 +02:00
channel.go compiler: fix stack overflow when creating recursive pointer types 2022-12-22 17:45:05 +01:00
compiler.go wasm: avoid miscompile with ThinLTO 2023-01-18 08:24:42 +01:00
compiler_test.go compiler: add support for new unsafe slice/string functions 2023-01-17 08:38:54 +01:00
defer.go all: add type parameter to *GEP calls 2022-10-19 22:23:19 +02:00
errors.go all: fix staticcheck warnings 2021-09-27 15:47:12 +02:00
func.go ci: add support for LLVM 15 2022-10-19 22:23:19 +02:00
gc.go wasm: avoid miscompile with ThinLTO 2023-01-18 08:24:42 +01:00
goroutine.go compiler: move some llvmutil code into the compiler 2023-01-18 08:24:42 +01:00
inlineasm.go all: add type parameter to CreateCall 2022-10-19 22:23:19 +02:00
interface.go all: remove pointer ElementType calls 2022-10-19 22:23:19 +02:00
interrupt.go all: replace llvm.Const* calls with builder.Create* calls 2022-10-19 22:23:19 +02:00
intrinsics.go ci: add support for LLVM 15 2022-10-19 22:23:19 +02:00
llvm.go wasm: avoid miscompile with ThinLTO 2023-01-18 08:24:42 +01:00
map.go all: add type parameter to CreateLoad 2022-10-19 22:23:19 +02:00
sizes.go compiler: fix unsafe.Sizeof for chan and map values 2022-09-01 03:53:27 +02:00
symbol.go avr: support ThinLTO 2022-11-18 18:40:38 +01:00
syscall.go all: add type parameter to CreateCall 2022-10-19 22:23:19 +02:00
volatile.go all: add type parameter to CreateLoad 2022-10-19 22:23:19 +02:00