Source file test/fixedbugs/issue18906.go

     1  // run
     2  
     3  // Copyright 2017 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  //go:noinline
    10  func f(x int) {
    11  }
    12  
    13  //go:noinline
    14  func val() int8 {
    15  	return -1
    16  }
    17  
    18  var (
    19  	array = [257]int{}
    20  	slice = array[1:]
    21  )
    22  
    23  func init() {
    24  	for i := range array {
    25  		array[i] = i - 1
    26  	}
    27  }
    28  
    29  func main() {
    30  	x := val()
    31  	y := int(uint8(x))
    32  	f(y) // try and force y to be calculated and spilled
    33  	if slice[y] != 255 {
    34  		panic("incorrect value")
    35  	}
    36  }
    37  

View as plain text