Source file test/fixedbugs/bug366.go

     1  // run
     2  
     3  // Copyright 2011 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  // Issue 2206.  Incorrect sign extension of div arguments.
     8  
     9  package main
    10  
    11  func five(x int64) {
    12  	if x != 5 {
    13  		panic(x)
    14  	}
    15  }
    16  
    17  func main() {
    18         // 5
    19         five(int64(5 / (5 / 3)))
    20  
    21         // 5
    22         five(int64(byte(5) / (byte(5) / byte(3))))
    23  
    24         // 5
    25         var a, b byte = 5, 3
    26         five(int64(a / (a / b)))
    27  
    28         // integer divide by zero in golang.org sandbox
    29         // 0 on windows/amd64
    30         x := [3]byte{2, 3, 5}
    31         five(int64(x[2] / (x[2] / x[1])))
    32  
    33         // integer divide by zero in golang.org sandbox
    34         // crash on windows/amd64
    35         y := x[1:3]
    36         five(int64(y[1] / (y[1] / y[0])))
    37  }

View as plain text