mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
add code to handle programs which use heap allocations but never hit the GC
This commit is contained in:
+8
-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))
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
func main() {
|
||||
p := []byte{}
|
||||
for len(p) >= 1 {
|
||||
p = p[1:]
|
||||
}
|
||||
}
|
||||
Vendored
Reference in New Issue
Block a user