Skip to content

Escape analysis caused unintuitive behavior #27644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ashi009 opened this issue Sep 12, 2018 · 2 comments
Closed

Escape analysis caused unintuitive behavior #27644

ashi009 opened this issue Sep 12, 2018 · 2 comments

Comments

@ashi009
Copy link

ashi009 commented Sep 12, 2018

What did you do?

https://play.golang.org/p/0EKO_Iju5Ol

What did you expect to see?

b ----- b
b ----- b

What did you see instead?

a ----- b
b ----- b

Does this issue reproduce with the latest release (go1.11)?

yep.

System details

go version go1.10.3 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xiaoyi/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xiaoyi/go"
GORACE=""
GOROOT="/Users/xiaoyi/homebrew/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/Users/xiaoyi/homebrew/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cb/j3f4sj8j3yq46t5kqcc5mpj80000gn/T/go-build864956246=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.10.3 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.10.3
uname -v: Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65
lldb --version: lldb-900.0.64
  Swift-4.0
@randall77
Copy link
Contributor

When you do []byte(s) where s is a string, the runtime can choose to use a capacity larger than the length of s. In this case that choice depends on escape analysis. It chooses 0 in your first case and 32 in your second case (print cap(s) in your Printfs to see this in action).
Closing, as this is not a bug.

@ianlancetaylor
Copy link
Contributor

Related to #24163.

@golang golang locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants