diff --git a/compiler/gc.go b/compiler/gc.go index 3a87b115..fd82525e 100644 --- a/compiler/gc.go +++ b/compiler/gc.go @@ -122,6 +122,7 @@ func (c *Compiler) makeGCStackSlots() bool { stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.Type().ElementType())) stackChainStart.SetGlobalConstant(true) } + return false } trackPointer := c.mod.NamedFunction("runtime.trackPointer") @@ -180,7 +181,13 @@ func (c *Compiler) makeGCStackSlots() bool { // Collect some variables used below in the loop. stackChainStart := c.mod.NamedGlobal("runtime.stackChainStart") if stackChainStart.IsNil() { - panic("stack chain start not found!") + // This may be reached in a weird scenario where we call runtime.alloc but the garbage collector is unreachable. + // This can be accomplished by allocating 0 bytes. + // There is no point in tracking anything. + for _, use := range getUses(trackPointer) { + use.EraseFromParentAsInstruction() + } + return false } stackChainStartType := stackChainStart.Type().ElementType() stackChainStart.SetInitializer(llvm.ConstNull(stackChainStartType)) diff --git a/testdata/zeroalloc.go b/testdata/zeroalloc.go new file mode 100644 index 00000000..53c6fa0b --- /dev/null +++ b/testdata/zeroalloc.go @@ -0,0 +1,7 @@ +package main +func main() { + p := []byte{} + for len(p) >= 1 { + p = p[1:] + } +} diff --git a/testdata/zeroalloc.txt b/testdata/zeroalloc.txt new file mode 100644 index 00000000..e69de29b