aboutsummaryrefslogtreecommitdiff
path: root/test/escape2n.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-01-28 08:42:20 +0300
committerDmitry Vyukov <dvyukov@google.com>2015-01-28 20:37:20 +0000
commit4ce4d8b2c4ffb0378a246b26815e9e27d077670a (patch)
tree47a9ab04b5123b069d3f868be8590b14314cb18c /test/escape2n.go
parente6fac08146df323eb95f46508bef937cdfb802fd (diff)
downloadgo-4ce4d8b2c4ffb0378a246b26815e9e27d077670a.tar.gz
go-4ce4d8b2c4ffb0378a246b26815e9e27d077670a.zip
cmd/gc: allocate stack buffer for ORUNESTR
If result of string(i) does not escape, allocate a [4]byte temp on stack for it. Change-Id: If31ce9447982929d5b3b963fd0830efae4247c37 Reviewed-on: https://go-review.googlesource.com/3411 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'test/escape2n.go')
-rw-r--r--test/escape2n.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/escape2n.go b/test/escape2n.go
index 6769906e30..03c0f4b75d 100644
--- a/test/escape2n.go
+++ b/test/escape2n.go
@@ -1630,3 +1630,24 @@ func addstr3() {
s2 := s[0:1]
sink = s2
}
+
+func intstring0() bool {
+ // string does not escape
+ x := '0'
+ s := string(x) // ERROR "string\(x\) does not escape"
+ return s == "0"
+}
+
+func intstring1() string {
+ // string does not escape, but the buffer does
+ x := '0'
+ s := string(x) // ERROR "string\(x\) escapes to heap"
+ return s
+}
+
+func intstring2() {
+ // string escapes to heap
+ x := '0'
+ s := string(x) // ERROR "string\(x\) escapes to heap" "moved to heap: s"
+ sink = &s // ERROR "&s escapes to heap"
+}