summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue26407.go
blob: aa8e79c1e6ada0184b3839974614d2187d4e9b74 (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
// run

// Copyright 2018 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.

// Issue 26407: ensure that stack variables which have
// had their address taken and then used in a comparison,
// but are otherwise unused, are cleared.

package main

func main() {
	poison()
	test()
}

//go:noinline
func poison() {
	// initialise the stack with invalid pointers
	var large [256]uintptr
	for i := range large {
		large[i] = 1
	}
	use(large[:])
}

//go:noinline
func test() {
	a := 2
	x := &a
	if x != compare(&x) {
		panic("not possible")
	}
}

//go:noinline
func compare(x **int) *int {
	var y *int
	if x == &y {
		panic("not possible")
	}
	// grow the stack to trigger a check for invalid pointers
	grow()
	if x == &y {
		panic("not possible")
	}
	return *x
}

//go:noinline
func grow() {
	var large [1 << 16]uintptr
	use(large[:])
}

//go:noinline
func use(_ []uintptr) { }