mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
compiler: improve position information
In many cases, position information is not stored in Go SSA instructions because they don't exit directly in the source code. This includes implicit type conversions, implicit returns at the end of a function, the creation of a (hidden) slice when calling a variadic function, and many other cases. I'm not sure where this information is supposed to come from, but this patch takes the value (usually) from the value the instruction refers to. This seems to work well for these implicit conversions. I've also added a few extra tests to the heap-to-stack transform pass, of which one requires this improved position information.
This commit is contained in:
committed by
Ron Evans
parent
f79e66ac2e
commit
c3992bd77b
Vendored
+20
-1
@@ -24,11 +24,24 @@ func main() {
|
||||
readByteSlice(s4)
|
||||
|
||||
s5 := make([]int, 4) // OUT: object allocated on the heap: escapes at line 27
|
||||
s5 = append(s5, 5)
|
||||
_ = append(s5, 5)
|
||||
|
||||
s6 := make([]int, 3)
|
||||
s7 := []int{1, 2, 3}
|
||||
copySlice(s6, s7)
|
||||
|
||||
c1 := getComplex128() // OUT: object allocated on the heap: escapes at line 34
|
||||
useInterface(c1)
|
||||
|
||||
n3 := 5 // OUT: object allocated on the heap: escapes at line 39
|
||||
func() int {
|
||||
return n3
|
||||
}()
|
||||
|
||||
callVariadic(3, 5, 8) // OUT: object allocated on the heap: escapes at line 41
|
||||
|
||||
s8 := []int{3, 5, 8} // OUT: object allocated on the heap: escapes at line 44
|
||||
callVariadic(s8...)
|
||||
}
|
||||
|
||||
func derefInt(x *int) int {
|
||||
@@ -56,3 +69,9 @@ func getUnknownNumber() int
|
||||
func copySlice(out, in []int) {
|
||||
copy(out, in)
|
||||
}
|
||||
|
||||
func getComplex128() complex128
|
||||
|
||||
func useInterface(interface{})
|
||||
|
||||
func callVariadic(...int)
|
||||
|
||||
Reference in New Issue
Block a user