modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue23812.go (about)

     1  // run
     2  
     3  // Copyright 2018 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  import "fmt"
    10  
    11  func main() {
    12  	want := int32(0x3edae8)
    13  	got := foo(1)
    14  	if want != got {
    15  		panic(fmt.Sprintf("want %x, got %x", want, got))
    16  	}
    17  }
    18  
    19  func foo(a int32) int32 {
    20  	return shr1(int32(shr2(int64(0x14ff6e2207db5d1f), int(a))), 4)
    21  }
    22  
    23  func shr1(n int32, m int) int32 { return n >> uint(m) }
    24  
    25  func shr2(n int64, m int) int64 {
    26  	if m < 0 {
    27  		m = -m
    28  	}
    29  	if m >= 64 {
    30  		return n
    31  	}
    32  
    33  	return n >> uint(m)
    34  }