Commit 426275d7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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
parent 728003e3
...@@ -15,6 +15,8 @@ var bug = false ...@@ -15,6 +15,8 @@ var bug = false
var minus1 = -1 var minus1 = -1
var big int64 = 10 | 1<<32 var big int64 = 10 | 1<<32
var g1 []int
func shouldfail(f func(), desc string) { func shouldfail(f func(), desc string) {
defer func() { recover() }() defer func() { recover() }()
f() f()
...@@ -26,52 +28,56 @@ func shouldfail(f func(), desc string) { ...@@ -26,52 +28,56 @@ func shouldfail(f func(), desc string) {
} }
func badlen() { func badlen() {
_ = make([]int, minus1) g1 = make([]int, minus1)
} }
func biglen() { func biglen() {
_ = make([]int, big) g1 = make([]int, big)
} }
func badcap() { func badcap() {
_ = make([]int, 10, minus1) g1 = make([]int, 10, minus1)
} }
func badcap1() { func badcap1() {
_ = make([]int, 10, 5) g1 = make([]int, 10, 5)
} }
func bigcap() { func bigcap() {
_ = make([]int, 10, big) g1 = make([]int, 10, big)
} }
const ( const (
addrBits = 8*uint(unsafe.Sizeof((*byte)(nil))) addrBits = 8*uint(unsafe.Sizeof((*byte)(nil)))
sh = addrBits/2 - 2 sh = addrBits/2 - 2
) )
var g2 [][1<<sh][1<<sh]byte
func overflow() { func overflow() {
_ = make([][1<<sh][1<<sh]byte, 64) g2 = make([][1<<sh][1<<sh]byte, 64)
} }
var g3 map[int]int
func badmapcap() { func badmapcap() {
_ = make(map[int]int, minus1) g3 = make(map[int]int, minus1)
} }
func bigmapcap() { func bigmapcap() {
_ = make(map[int]int, big) g3 = make(map[int]int, big)
} }
var g4 chan int
func badchancap() { func badchancap() {
_ = make(chan int, minus1) g4 = make(chan int, minus1)
} }
func bigchancap() { func bigchancap() {
_ = make(chan int, big) g4 = make(chan int, big)
} }
var g5 chan [1<<15]byte
func overflowchan() { func overflowchan() {
if addrBits == 32 { if addrBits == 32 {
_ = make(chan [1<<15]byte, 1<<20) g5 = make(chan [1<<15]byte, 1<<20)
} else { } else {
// cannot overflow on 64-bit, because // cannot overflow on 64-bit, because
// int is 32 bits and max chan value size // int is 32 bits and max chan value size
......
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