Skip to content

cmd/compile: unclear escape analysis #36504

@FiloSottile

Description

@FiloSottile

What version of Go are you using (go version)?

$ go version
go version devel +198f0452b0 Thu Nov 7 02:33:31 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yep.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/filippo/Library/Caches/go-build"
GOENV="/Users/filippo/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/filippo"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org"
GOROOT="/Users/filippo/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/filippo/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/filippo/src/golang.org/x/crypto/go.mod"
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/cm/zzcl1fjx27sc8sf3s6sd_0vw0000gn/T/go-build168572639=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a function that (also thanks to inlining) I'd expect not to allocate anything to the heap.

https://go.googlesource.com/crypto/+/c8d9389ed30fa12bbe2123256b81a26dd5cbe7b8/chacha20poly1305/chacha20poly1305_generic.go (from CL 206977)

What did you see instead?

  Total:     6340801   13065057 (flat, cum) 49.99%
     26            .          .           	binary.LittleEndian.PutUint64(buf[:], uint64(n)) 
     27            .          .           	p.Write(buf[:]) 
     28            .          .           } 
     29            .          .            
     30            .          .           func (c *chacha20poly1305) sealGeneric(dst, nonce, plaintext, additionalData []byte) []byte { 
     31            .        740           	ret, out := sliceForAppend(dst, len(plaintext)+poly1305.TagSize) 
     32            .          .           	ciphertext, tag := out[:len(plaintext)], out[len(plaintext):] 
     33            .          .           	if subtle.InexactOverlap(out, plaintext) { 
     34            .          .           		panic("chacha20poly1305: invalid buffer overlap") 
     35            .          .           	} 
     36            .          .            
     37      6340801    6340801           	var polyKey [32]byte 
     38            .          .           	s, _ := chacha20.NewUnauthenticatedCipher(c.key[:], nonce) 
     39            .          .           	s.XORKeyStream(polyKey[:], polyKey[:]) 
     40            .          .           	s.Advance(1) // set the counter to 1, skipping 32 bytes 
     41            .          .           	s.XORKeyStream(ciphertext, plaintext) 
     42            .          .            
     43            .    6723516           	p := poly1305.New(&polyKey) 
     44            .          .           	writeWithPadding(p, additionalData) 
     45            .          .           	writeWithPadding(p, ciphertext) 
     46            .          .           	writeUint64(p, len(additionalData)) 
     47            .          .           	writeUint64(p, len(plaintext)) 
     48            .          .           	p.Sum(tag[:0]) 

-gcflags=-m has nothing about neither polyKey nor p.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions