diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2015-01-28 08:42:20 +0300 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2015-01-28 20:37:20 +0000 |
commit | 4ce4d8b2c4ffb0378a246b26815e9e27d077670a (patch) | |
tree | 47a9ab04b5123b069d3f868be8590b14314cb18c /test/escape2n.go | |
parent | e6fac08146df323eb95f46508bef937cdfb802fd (diff) | |
download | go-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.go | 21 |
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" +} |