go/src/cmd/compile/internal/gc/fixedbugs_test.go
Keith Randall 6129f37367 cmd/compile: inline convT2{I,E} when result doesn't escape
No point in calling a function when we can build the interface
using a known type (or itab) and the address of a local.

Get rid of third arg (preallocated stack space) to convT2{I,E}.

Makes go binary smaller by 0.2%

benchmark                   old ns/op     new ns/op     delta
BenchmarkEfaceInteger-8     16.7          10.1          -39.52%

Update #17118
Update #15375

Change-Id: I9724a1f802bfa1e3957bf1856b55558278e198a2
Reviewed-on: https://go-review.googlesource.com/29373
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-19 02:37:08 +00:00

50 lines
1.2 KiB
Go

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gc
import "testing"
type T struct {
x [2]int64 // field that will be clobbered. Also makes type not SSAable.
p *byte // has a pointer
}
//go:noinline
func makeT() T {
return T{}
}
var g T
var sink interface{}
func TestIssue15854(t *testing.T) {
for i := 0; i < 10000; i++ {
if g.x[0] != 0 {
t.Fatalf("g.x[0] clobbered with %x\n", g.x[0])
}
// The bug was in the following assignment. The return
// value of makeT() is not copied out of the args area of
// stack frame in a timely fashion. So when write barriers
// are enabled, the marshaling of the args for the write
// barrier call clobbers the result of makeT() before it is
// read by the write barrier code.
g = makeT()
sink = make([]byte, 1000) // force write barriers to eventually happen
}
}
func TestIssue15854b(t *testing.T) {
const N = 10000
a := make([]T, N)
for i := 0; i < N; i++ {
a = append(a, makeT())
sink = make([]byte, 1000) // force write barriers to eventually happen
}
for i, v := range a {
if v.x[0] != 0 {
t.Fatalf("a[%d].x[0] clobbered with %x\n", i, v.x[0])
}
}
}