]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: zero return parameters earlier
authorkhr <khr@khr-glaptop.roam.corp.google.com>
Thu, 9 Mar 2017 18:38:45 +0000 (10:38 -0800)
committerKeith Randall <khr@golang.org>
Mon, 13 Mar 2017 19:39:15 +0000 (19:39 +0000)
commita51e4cc9cea152a203ab508197dc0965c00e3a76
treef7fa6e80cd35b0e0ab2f1d749af39fe60756dc74
parent27492a2a549e4e03a6aed93811cdd458ce529e32
cmd/compile: zero return parameters earlier

Move the zeroing of results earlier.  In particular, they need to
come before any move-to-heap operations, as those require allocation.
Those allocations are points at which the GC can see the uninitialized
result slots.

For the function:

func f() (x, y, z *int) {
  defer(){}()
  escape(&y)
  return
}

We used to generate code like this:

x = nil
y = nil
&y = new(int)
z = nil

Now we will generate:

x = nil
y = nil
z = nil
&y = new(int)

Since the fix for #18860, the return slots are always live if there
is a defer, so the former ordering allowed the GC to see junk
in the z slot.

Fixes #19078

Change-Id: I71554ae437549725bb79e13b2c100b2911d47ed4
Reviewed-on: https://go-review.googlesource.com/38133
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/plive.go
src/cmd/compile/internal/gc/walk.go
test/fixedbugs/issue19078.go [new file with mode: 0644]