mirror of
https://github.com/golang/go
synced 2024-11-22 01:24:42 -07:00
test: Use global variables to defeat gccgo optimizer.
The gccgo compiler is smart enough to not make something which is not used. Use global variables to defeat this optimization. R=rsc CC=golang-dev https://golang.org/cl/2129041
This commit is contained in:
parent
728003e340
commit
426275d702
@ -15,6 +15,8 @@ var bug = false
|
||||
var minus1 = -1
|
||||
var big int64 = 10 | 1<<32
|
||||
|
||||
var g1 []int
|
||||
|
||||
func shouldfail(f func(), desc string) {
|
||||
defer func() { recover() }()
|
||||
f()
|
||||
@ -26,52 +28,56 @@ func shouldfail(f func(), desc string) {
|
||||
}
|
||||
|
||||
func badlen() {
|
||||
_ = make([]int, minus1)
|
||||
g1 = make([]int, minus1)
|
||||
}
|
||||
|
||||
func biglen() {
|
||||
_ = make([]int, big)
|
||||
g1 = make([]int, big)
|
||||
}
|
||||
|
||||
func badcap() {
|
||||
_ = make([]int, 10, minus1)
|
||||
g1 = make([]int, 10, minus1)
|
||||
}
|
||||
|
||||
func badcap1() {
|
||||
_ = make([]int, 10, 5)
|
||||
g1 = make([]int, 10, 5)
|
||||
}
|
||||
|
||||
func bigcap() {
|
||||
_ = make([]int, 10, big)
|
||||
g1 = make([]int, 10, big)
|
||||
}
|
||||
|
||||
const (
|
||||
addrBits = 8*uint(unsafe.Sizeof((*byte)(nil)))
|
||||
sh = addrBits/2 - 2
|
||||
)
|
||||
var g2 [][1<<sh][1<<sh]byte
|
||||
func overflow() {
|
||||
_ = make([][1<<sh][1<<sh]byte, 64)
|
||||
g2 = make([][1<<sh][1<<sh]byte, 64)
|
||||
}
|
||||
|
||||
var g3 map[int]int
|
||||
func badmapcap() {
|
||||
_ = make(map[int]int, minus1)
|
||||
g3 = make(map[int]int, minus1)
|
||||
}
|
||||
|
||||
func bigmapcap() {
|
||||
_ = make(map[int]int, big)
|
||||
g3 = make(map[int]int, big)
|
||||
}
|
||||
|
||||
var g4 chan int
|
||||
func badchancap() {
|
||||
_ = make(chan int, minus1)
|
||||
g4 = make(chan int, minus1)
|
||||
}
|
||||
|
||||
func bigchancap() {
|
||||
_ = make(chan int, big)
|
||||
g4 = make(chan int, big)
|
||||
}
|
||||
|
||||
var g5 chan [1<<15]byte
|
||||
func overflowchan() {
|
||||
if addrBits == 32 {
|
||||
_ = make(chan [1<<15]byte, 1<<20)
|
||||
g5 = make(chan [1<<15]byte, 1<<20)
|
||||
} else {
|
||||
// cannot overflow on 64-bit, because
|
||||
// int is 32 bits and max chan value size
|
||||
|
Loading…
Reference in New Issue
Block a user