modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue15175.go (about) 1 // run 2 3 // Copyright 2016 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 // Make sure unsigned shift results get sign-extended correctly. 8 package main 9 10 import "fmt" 11 12 func main() { 13 failed := false 14 a6 := uint8(253) 15 if got := a6 >> 0; got != 253 { 16 fmt.Printf("uint8(253)>>0 = %v, wanted 253\n", got) 17 failed = true 18 } 19 if got := f1(0, 2, 1, 0, 0, 1, true); got != 255 { 20 fmt.Printf("f1(...) = %v, wanted 255\n", got) 21 failed = true 22 } 23 if got := f2(1); got != 242 { 24 fmt.Printf("f2(...) = %v, wanted 242\n", got) 25 failed = true 26 } 27 if got := f3(false, 0, 0); got != 254 { 28 fmt.Printf("f3(...) = %v, wanted 254\n", got) 29 failed = true 30 } 31 if failed { 32 panic("bad") 33 } 34 } 35 36 func f1(a1 uint, a2 int8, a3 int8, a4 int8, a5 uint8, a6 int, a7 bool) uint8 { 37 a5-- 38 a4 += (a2 << a1 << 2) | (a4 ^ a4<<(a1&a1)) - a3 // int8 39 a6 -= a6 >> (2 + uint32(a2)>>3) // int 40 a1 += a1 // uint 41 a3 *= a4 << (a1 | a1) << (uint16(3) >> 2 & (1 - 0) & (uint16(1) << a5 << 3)) // int8 42 a7 = a7 || ((a2 == a4) || (a7 && a7) || ((a5 == a5) || (a7 || a7))) // bool 43 return a5 >> a1 44 } 45 46 func f2(a1 uint8) uint8 { 47 a1-- 48 a1-- 49 a1 -= a1 + (a1 << 1) - (a1*a1*a1)<<(2-0+(3|3)-1) // uint8 50 v1 := 0 * ((2 * 1) ^ 1) & ((uint(0) >> a1) + (2+0)*(uint(2)+0)) // uint 51 _ = v1 52 return a1 >> (((2 ^ 2) >> (v1 | 2)) + 0) 53 } 54 55 func f3(a1 bool, a2 uint, a3 int64) uint8 { 56 a3-- 57 v1 := 1 & (2 & 1 * (1 ^ 2) & (uint8(3*1) >> 0)) // uint8 58 _ = v1 59 v1 += v1 - (v1 >> a2) + (v1 << (a2 ^ a2) & v1) // uint8 60 v1 *= v1 // uint8 61 a3-- 62 v1 += v1 & v1 // uint8 63 v1-- 64 v1 = ((v1 << 0) | v1>>0) + v1 // uint8 65 return v1 >> 0 66 }