add code to handle programs which use heap allocations but never hit the GC

Этот коммит содержится в:
Jaden Weiss 2019-11-16 19:37:35 -05:00 коммит произвёл Ayke
родитель 3cedebd299
коммит 81199da3f1
3 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -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))

7
testdata/zeroalloc.go предоставленный Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
package main
func main() {
p := []byte{}
for len(p) >= 1 {
p = p[1:]
}
}

0
testdata/zeroalloc.txt предоставленный Обычный файл
Просмотреть файл