Commit 0000f0be authored by Dan Scales's avatar Dan Scales

cmd/compile: add an explicit test for compile of arch.ZeroRange

Add a test that causes generation of arch.ZeroRange calls of various sizes 8-136
bytes in the compiler. This is to test that ZeroRanges of various sizes actually
compile on different architectures, but is not testing runtime correctness (which
is hard to do).

Updates #34604

Change-Id: I4131eb86669bdfe8d4e36f4ae5c2a7b069abd6c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/198045
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 0ba0ea17
// Copyright 2019 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"
)
var glob = 3
var globp *int64
// Testing compilation of arch.ZeroRange of various sizes.
// By storing a pointer to an int64 output param in a global, the compiler must
// ensure that output param is allocated on the heap. Also, since there is a
// defer, the pointer to each output param must be zeroed in the prologue (see
// plive.go:epilogue()). So, we will get a block of one or more stack slots that
// need to be zeroed. Hence, we are testing compilation completes successfully when
// zerorange calls of various sizes (8-136 bytes) are generated. We are not
// testing runtime correctness (which is hard to do for the current uses of
// ZeroRange).
func TestZeroRange(t *testing.T) {
testZeroRange8(t)
testZeroRange16(t)
testZeroRange32(t)
testZeroRange64(t)
testZeroRange136(t)
}
func testZeroRange8(t *testing.T) (r int64) {
defer func() {
glob = 4
}()
globp = &r
return
}
func testZeroRange16(t *testing.T) (r, s int64) {
defer func() {
glob = 4
}()
globp = &r
globp = &s
return
}
func testZeroRange32(t *testing.T) (r, s, t2, u int64) {
defer func() {
glob = 4
}()
globp = &r
globp = &s
globp = &t2
globp = &u
return
}
func testZeroRange64(t *testing.T) (r, s, t2, u, v, w, x, y int64) {
defer func() {
glob = 4
}()
globp = &r
globp = &s
globp = &t2
globp = &u
globp = &v
globp = &w
globp = &x
globp = &y
return
}
func testZeroRange136(t *testing.T) (r, s, t2, u, v, w, x, y, r1, s1, t1, u1, v1, w1, x1, y1, z1 int64) {
defer func() {
glob = 4
}()
globp = &r
globp = &s
globp = &t2
globp = &u
globp = &v
globp = &w
globp = &x
globp = &y
globp = &r1
globp = &s1
globp = &t1
globp = &u1
globp = &v1
globp = &w1
globp = &x1
globp = &y1
globp = &z1
return
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment