aboutsummaryrefslogtreecommitdiffhomepage
path: root/transform
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-04-25 01:48:54 +0200
committerRon Evans <[email protected]>2021-04-26 16:15:57 +0200
commitc3992bd77b1e0b64c56065d9d32b8b920eb0efb2 (patch)
tree5c1e5d4b93461ef52b78c8f976670a4fcf88e130 /transform
parentf79e66ac2e66a5338ec3ce3c4c992567b07c4959 (diff)
downloadtinygo-c3992bd77b1e0b64c56065d9d32b8b920eb0efb2.tar.gz
tinygo-c3992bd77b1e0b64c56065d9d32b8b920eb0efb2.zip
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.
Diffstat (limited to 'transform')
-rw-r--r--transform/testdata/allocs2.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/transform/testdata/allocs2.go b/transform/testdata/allocs2.go
index 3e1df07df..aeddcf6ba 100644
--- a/transform/testdata/allocs2.go
+++ b/transform/testdata/allocs2.go
@@ -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)