summaryrefslogtreecommitdiff
path: root/test/escape2.go
diff options
context:
space:
mode:
authorR?my Oudompheng <oudomphe@phare.normalesup.org>2012-01-12 12:08:40 +0100
committerR?my Oudompheng <oudomphe@phare.normalesup.org>2012-01-12 12:08:40 +0100
commiteafa30ea7bc1d85d3babcfa659536788a7bbdf20 (patch)
treed99c6429af962a0074f3c2faa21419a2f34babbd /test/escape2.go
parent8b26b0d437b4cdbd0e7eff18bedd8844b769487c (diff)
downloadgo-eafa30ea7bc1d85d3babcfa659536788a7bbdf20.tar.gz
gc: avoid false positives when using scalar struct fields.
The escape analysis code does not make a distinction between scalar and pointers fields in structs. Non-pointer fields that escape should not make the whole struct escape. R=lvd, rsc CC=golang-dev, remy http://codereview.appspot.com/5489128 Committer: Luuk van Dijk <lvd@golang.org>
Diffstat (limited to 'test/escape2.go')
-rw-r--r--test/escape2.go42
1 files changed, 36 insertions, 6 deletions
diff --git a/test/escape2.go b/test/escape2.go
index c2cbefbe6..73b2a7e58 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -126,10 +126,36 @@ func (b *Bar) NoLeak() int { // ERROR "b does not escape"
return *(b.ii)
}
+func (b *Bar) Leak() *int { // ERROR "leaking param: b"
+ return &b.i // ERROR "&b.i escapes to heap"
+}
+
func (b *Bar) AlsoNoLeak() *int { // ERROR "b does not escape"
return b.ii
}
+func (b Bar) AlsoLeak() *int { // ERROR "leaking param: b"
+ return b.ii
+}
+
+func (b Bar) LeaksToo() *int { // ERROR "leaking param: b"
+ v := 0 // ERROR "moved to heap: v"
+ b.ii = &v // ERROR "&v escapes"
+ return b.ii
+}
+
+func (b *Bar) LeaksABit() *int { // ERROR "b does not escape"
+ v := 0 // ERROR "moved to heap: v"
+ b.ii = &v // ERROR "&v escapes"
+ return b.ii
+}
+
+func (b Bar) StillNoLeak() int { // ERROR "b does not escape"
+ v := 0
+ b.ii = &v // ERROR "&v does not escape"
+ return b.i
+}
+
func goLeak(b *Bar) { // ERROR "leaking param: b"
go b.NoLeak()
}
@@ -148,20 +174,24 @@ func (b *Bar2) NoLeak() int { // ERROR "b does not escape"
}
func (b *Bar2) Leak() []int { // ERROR "leaking param: b"
- return b.i[:] // ERROR "b.i escapes to heap"
+ return b.i[:] // ERROR "b.i escapes to heap"
}
func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape"
return b.ii[0:1]
}
+func (b Bar2) AgainNoLeak() [12]int { // ERROR "b does not escape"
+ return b.i
+}
+
func (b *Bar2) LeakSelf() { // ERROR "leaking param: b"
- b.ii = b.i[0:4] // ERROR "b.i escapes to heap"
+ b.ii = b.i[0:4] // ERROR "b.i escapes to heap"
}
func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b"
var buf []int
- buf = b.i[0:] // ERROR "b.i escapes to heap"
+ buf = b.i[0:] // ERROR "b.i escapes to heap"
b.ii = buf
}
@@ -1018,7 +1048,7 @@ func foo122() {
goto L1
L1:
- i = new(int) // ERROR "does not escape"
+ i = new(int) // ERROR "does not escape"
_ = i
}
@@ -1027,8 +1057,8 @@ func foo123() {
var i *int
L1:
- i = new(int) // ERROR "escapes"
+ i = new(int) // ERROR "escapes"
goto L1
_ = i
-} \ No newline at end of file
+}