summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/zerorange_test.go
blob: 89f4cb9bcf6e436ae6981cb1809927bd9c799676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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
}