mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
interp: use object layout information for LLVM types
This commit will use the memory layout information for heap allocations added in the previous commit to determine LLVM types, instead of guessing their types based on the content. This fixes a bug in which recursive data structures (such as doubly linked lists) would result in a compiler stack overflow due to infinite recursion. Not all heap allocations have a memory layout yet, but this can be incrementally fixed in the future. So far, this commit should fix (almost?) all cases of this stack overflow issue.
This commit is contained in:
committed by
Ron Evans
parent
54dd75f7b3
commit
1869efe954
Vendored
+45
@@ -44,8 +44,53 @@ var (
|
||||
uint8SliceDst []uint8
|
||||
intSliceSrc = []int16{5, 123, 1024}
|
||||
intSliceDst []int16
|
||||
|
||||
someList *linkedList
|
||||
someBigList *bigLinkedList
|
||||
)
|
||||
|
||||
type linkedList struct {
|
||||
prev *linkedList
|
||||
next *linkedList
|
||||
v int // arbitrary value (don't care)
|
||||
}
|
||||
|
||||
func init() {
|
||||
someList = &linkedList{
|
||||
v: -1,
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
prev := someList
|
||||
someList = &linkedList{
|
||||
v: i,
|
||||
prev: prev,
|
||||
}
|
||||
prev.next = someList
|
||||
}
|
||||
}
|
||||
|
||||
type bigLinkedList struct {
|
||||
prev *bigLinkedList
|
||||
next *bigLinkedList
|
||||
v int
|
||||
buf [100]*int
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Create a circular reference.
|
||||
someBigList = &bigLinkedList{
|
||||
v: -1,
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
prev := someBigList
|
||||
someBigList = &bigLinkedList{
|
||||
v: i,
|
||||
prev: prev,
|
||||
}
|
||||
prev.next = someBigList
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
uint8SliceDst = make([]uint8, len(uint8SliceSrc))
|
||||
copy(uint8SliceDst, uint8SliceSrc)
|
||||
|
||||
Reference in New Issue
Block a user